-
Notifications
You must be signed in to change notification settings - Fork 1
/
check_beanstalkd.py
executable file
·88 lines (76 loc) · 2.6 KB
/
check_beanstalkd.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import beanstalkc
import sys
import getopt
def usage():
print("check-beanstalkd.py")
print("\t[-h hostname/address] // default localhost")
print("\t[-p port] // default 11300")
print("\t[-w warning-threshold] // default 8")
print("\t[-c critical-threshold] // default 10")
print("\t[-t tubename] // default None")
print("\t[-s stats entry] // default current-jobs-ready")
sys.exit(3)
def main(argv):
global returnValue
host = 'localhost'
port = 11300
tube = None
warning = 8
critical = 10
stat = 'current-jobs-ready'
try:
opts, args = getopt.getopt(argv, "h:p:t:w:c:s:")
except getopt.GetoptError as e:
usage();
print("UNKNOWN")
sys.exit(3)
for opt, arg in opts:
if opt in ('-h'):
host = arg
if opt in ('-p'):
port = int(arg)
if opt in ('-s'):
stat = arg
if opt in ('-t'):
tube = arg
if opt in ('-w'):
warning = int(arg)
if opt in ('-c'):
critical = int(arg)
try:
beanstalk = beanstalkc.Connection(host=host, port=port, parse_yaml=True)
if tube == None:
#pprint(beanstalk.stats())
s = beanstalk.stats()
v = s[stat]
if v < warning:
print('OK beanstalkd %s=%d | %s=%d;%d;%d;' % (stat, v, stat, v, warning, critical))
returnValue = 0
elif v < critical:
print('WARNING beanstalkd %s=%d | %s=%d;%d;%d;' % (stat, v, stat, v, warning, critical))
returnValue = 1
else:
print('CRITICAL beanstalkd %s=%d | %s=%d;%d;%d;' % (stat, v, stat, v, warning, critical))
returnValue = 2
else:
#pprint(beanstalk.stats_tube(tube))
s = beanstalk.stats_tube(tube)
v = s[stat]
if v < warning:
print('OK tube %s %s=%d | %s-%s=%d;%d;%d;' % (tube, stat, v, tube, stat, v, warning, critical))
returnValue = 0
elif v < critical:
print('WARNING tube %s %s=%d | %s-%s=%d;%d;%d;' % (tube, stat, v, tube, stat, v, warning, critical))
returnValue = 1
else:
print('CRITICAL tube %s %s=%d | %s-%s=%d;%d;%d' % (tube, stat, v, tube, stat, v, warning, critical))
returnValue = 2
except:
print('UNKNOWN')
sys.exit(3)
exit(returnValue)
returnValue = 3
if __name__ == '__main__':
main(sys.argv[1:])