2020-02-04 22:11:06 +00:00
|
|
|
#!/usr/bin/python
|
2017-01-05 00:55:16 +00:00
|
|
|
|
|
|
|
import json
|
|
|
|
import os
|
|
|
|
import socket
|
|
|
|
import sys
|
|
|
|
import zmq
|
|
|
|
|
|
|
|
try:
|
|
|
|
service = sys.argv[1]
|
|
|
|
check_consumer = sys.argv[2]
|
|
|
|
exceptions_warning = int(sys.argv[3])
|
|
|
|
exceptions_critical = int(sys.argv[4])
|
|
|
|
fname = '/var/run/fedmsg/monitoring-%s.socket' % service
|
|
|
|
|
|
|
|
if not os.path.exists(fname):
|
2020-02-04 22:11:06 +00:00
|
|
|
print("UNKNOWN - %s does not exist" % fname)
|
2017-01-05 00:55:16 +00:00
|
|
|
sys.exit(3)
|
|
|
|
|
|
|
|
if not os.access(fname, os.W_OK):
|
2020-02-04 22:11:06 +00:00
|
|
|
print("UNKNOWN - cannot write to %s" % fname)
|
2017-01-05 00:55:16 +00:00
|
|
|
sys.exit(3)
|
|
|
|
|
|
|
|
connect_to = "ipc:///%s" % fname
|
|
|
|
ctx = zmq.Context()
|
|
|
|
s = ctx.socket(zmq.SUB)
|
|
|
|
s.connect(connect_to)
|
2020-02-04 22:11:06 +00:00
|
|
|
s.setsockopt_string(zmq.SUBSCRIBE, '')
|
2017-01-05 00:55:16 +00:00
|
|
|
poller = zmq.Poller()
|
|
|
|
poller.register(s, zmq.POLLIN)
|
|
|
|
|
|
|
|
timeout = 20000
|
|
|
|
|
|
|
|
events = dict(poller.poll(timeout))
|
|
|
|
if s in events and events[s] == zmq.POLLIN:
|
|
|
|
msg = s.recv()
|
|
|
|
msg = json.loads(msg)
|
|
|
|
else:
|
2020-02-04 22:11:06 +00:00
|
|
|
print('UNKNOWN - ZMQ timeout. No message received in %i ms' % timeout)
|
2017-01-05 00:55:16 +00:00
|
|
|
sys.exit(3)
|
|
|
|
|
|
|
|
for consumer in msg['consumers']:
|
|
|
|
if consumer['name'] == check_consumer:
|
|
|
|
if consumer['exceptions'] > exceptions_critical:
|
2020-02-04 22:11:06 +00:00
|
|
|
print('CRITICAL: fedmsg consumer %s exceptions value is %i' % (consumer['name'],consumer['exceptions']))
|
2017-01-05 00:55:16 +00:00
|
|
|
sys.exit(2)
|
|
|
|
elif consumer['exceptions'] > exceptions_warning:
|
2020-02-04 22:11:06 +00:00
|
|
|
print('WARNING: fedmsg consumer %s exceptions value is %i' % (consumer['name'],consumer['exceptions']))
|
2017-01-05 00:55:16 +00:00
|
|
|
sys.exit(1)
|
|
|
|
else:
|
2020-02-04 22:11:06 +00:00
|
|
|
print('OK: fedmsg consumer %s exceptions value is %i' % (consumer['name'],consumer['exceptions']))
|
2017-01-05 00:55:16 +00:00
|
|
|
sys.exit(0)
|
|
|
|
|
2020-02-04 22:11:06 +00:00
|
|
|
print("UNKNOWN: fedmsg consumers %s not found" % check_consumer)
|
2017-01-05 00:55:16 +00:00
|
|
|
sys.exit(3)
|
|
|
|
except Exception as err:
|
2020-02-04 22:11:06 +00:00
|
|
|
print("UNKNOWN:", str(err))
|
2017-01-05 00:55:16 +00:00
|
|
|
sys.exit(3)
|