Skip to content

Instantly share code, notes, and snippets.

@scr34m
Created April 16, 2014 08:27
Show Gist options
  • Save scr34m/10832214 to your computer and use it in GitHub Desktop.
Save scr34m/10832214 to your computer and use it in GitHub Desktop.
Supervisord nagios monitor script, modified to check every process state
#!/usr/bin/env python
import xmlrpclib
import sys
# Simple Nagios/Icinga check for a process under Supervisord.
# Requires XML-RPC interface (inet) enabled
__author__ = 'Jan-Piet Mens <jpmens()gmail.com>'
supervisorduri = 'http://localhost:9001/RPC2'
OK = 0
WARNING = 1
CRITICAL = 2
stati = {
0 : 'OK',
1 : 'WARNING',
2 : 'CRITICAL',
3 : 'UNKNOWN' }
processes = 0
status = OK
statustext = None
server = xmlrpclib.Server(supervisorduri)
try:
info = server.supervisor.getAllProcessInfo()
except xmlrpclib.Fault:
status = CRITICAL
statustext = "supervisor: not running"
except Exception, e:
status = CRITICAL
statustext = "supervisor: not running %s" % str(e)
if info:
for item in info:
processes += 1
if item['statename'] != 'RUNNING':
status = CRITICAL
statustext = "%s supervisor for %s: %s" % (item['statename'], item['name'], item['description'])
if statustext is None:
statustext = 'supervisor: OK (%d process running)' % processes
print statustext
sys.exit(status)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment