[Supervisor-users] Email notifications when programs can't be started?
khalid y
kernity at gmail.com
Wed Oct 28 10:22:47 EDT 2009
Hi,
You can code a python script and add an event listener to your sueprvisord
config.
Here is a little and basic mail notification. You can implement another type
of notification. Recently I coded an sms notification script to get my
crashes on my cell phone :-)
The code below is just a draft but it works.
Good Job
#!/usr/bin/env python -u
import smtplib, sys, os
from datetime import datetime
from supervisor import childutils
# Change your smpt_server and email
SMTP_SERVER = 'relay.skynet.be'
ADMIN_MAIL = "kernity at gmail.com"
FROM_MAIL = "kernity at gmail.com"
PROCESS_STATE_LIST = [
'PROCESS_STATE_STOPPING',
'PROCESS_STATE_EXITED',
'PROCESS_STATE_UNKNOWN',
]
def write_stdout(s):
sys.stdout.write(s)
sys.stdout.flush()
def write_stderr(s):
sys.stderr.write(s)
sys.stderr.flush()
def send_mail(subject, message):
datas = {
'mail_from' : FROM_MAIL,
'mail_to': ADMIN_MAIL,
'subject': subject,
'message': message,
}
message = """From: %(mail_from)s
To: %(mail_to)s
Subject: %(subject)s
%(message)s
""" % datas
try:
session = smtplib.SMTP(SMTP_SERVER)
result = session.sendmail(FROM_MAIL, ADMIN_MAIL, message)
except:
print "An error occured when sending mail"
def main(argv=sys.argv):
while True:
h, p = childutils.listener.wait(sys.
stdin, sys.stdout)
if not h['eventname'] in PROCESS_STATE_LIST:
childutils.listener.ok(sys.stdout)
continue
ph, pd = childutils.eventdata(p+'\n')
message = "Process %s (pid %s) fired event %s from state %s at %s" %
(
ph.get('processname'),
ph.get('pid'),
h.get('eventname'),
ph.get('from_state'),
datetime.now()
)
subject = "Process %s failed at %s" % (ph.get('processname'),
datetime.now())
send_mail(subject, message)
childutils.listener.ok(sys.stdout)
if __name__ == '__main__':
main()
Supervisor configuration :
[eventlistener:mail_notification]
command=/usr/bin/python /home/ubuntu/utils/mail_notification.py
events=PROCESS_STATE, TICK_60
user = ubuntu
autostart = true
redirect_stderr=true
priority = 20
2009/10/28 Phillip Oldham <phill at activityhq.com>
> Grzegorz Nosek wrote:
> > You'll need an event listener:
> > http://supervisord.org/manual/current/events.html
> >
> > Maybe superlance will help you here, though I haven't used it. Adapting
> > "crashmail" from this package should do the trick.
> > http://pypi.python.org/pypi/superlance/
> >
> Thanks Grzegorz, that looks like what I'm looking for.
>
> Does anyone have a config example to use this? The docs are a little light.
> _______________________________________________
> Supervisor-users mailing list
> Supervisor-users at lists.supervisord.org
> http://lists.supervisord.org/mailman/listinfo/supervisor-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.supervisord.org/pipermail/supervisor-users/attachments/20091028/902572a0/attachment.htm
More information about the Supervisor-users
mailing list