-
Notifications
You must be signed in to change notification settings - Fork 9
/
check_supervisor.py
57 lines (45 loc) · 1.36 KB
/
check_supervisor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#!/usr/bin/env python
"""
nagios plugin to monitor indivdual supervisor processes
-------------------------------------------------------
usage
::
check_supervisor -p PROCESS_NAME
"""
from optparse import OptionParser
import os
#nagios return codes
UNKNOWN = -1
OK = 0
WARNING = 1
CRITICAL = 2
SUPERV_STAT_CHECK='supervisorctl status'
#supervisor states, map state to desired warning level
supervisor_states = {
'STOPPED': OK,
'RUNNING': OK,
'STOPPING': WARNING,
'STARTING': WARNING,
'EXITED': CRITICAL,
'BACKOFF': CRITICAL,
'FATAL': CRITICAL,
'UNKNOWN': CRITICAL
}
def get_status(proc_name):
try:
status_output = os.popen('%s %s' % (SUPERV_STAT_CHECK, proc_name)).read()
proc_status = status_output.split()[1]
return (status_output, supervisor_states[proc_status])
except:
print "CRITICAL: Could not get status of %s" % proc_name
raise SystemExit, CRITICAL
parser = OptionParser()
parser.add_option('-p', '--processes-name', dest='proc_name',
help="Name of process as it appears in supervisorctl status")
parser.add_option('-v', '--verbose', dest='verbose', action='store_true',
default=False)
parser.add_option('-q', '--quiet', dest='verbose', action='store_false')
options, args = parser.parse_args()
output = get_status(options.proc_name)
print output[0]
raise SystemExit, output[1]