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