python3-ize the fedmsg check scripts, and on py3 boxes make it check a valid socket path
Signed-off-by: Rick Elrod <relrod@redhat.com>
This commit is contained in:
parent
8cd7809278
commit
40e13bcbf0
8 changed files with 83 additions and 71 deletions
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python2
|
||||
#!/usr/bin/python
|
||||
|
||||
import json
|
||||
import os
|
||||
|
@ -14,18 +14,18 @@ try:
|
|||
fname = '/var/run/fedmsg/monitoring-%s.socket' % service
|
||||
|
||||
if not os.path.exists(fname):
|
||||
print "UNKNOWN - %s does not exist" % fname
|
||||
print("UNKNOWN - %s does not exist" % fname)
|
||||
sys.exit(3)
|
||||
|
||||
if not os.access(fname, os.W_OK):
|
||||
print "UNKNOWN - cannot write to %s" % fname
|
||||
print("UNKNOWN - cannot write to %s" % fname)
|
||||
sys.exit(3)
|
||||
|
||||
connect_to = "ipc:///%s" % fname
|
||||
ctx = zmq.Context()
|
||||
s = ctx.socket(zmq.SUB)
|
||||
s.connect(connect_to)
|
||||
s.setsockopt(zmq.SUBSCRIBE, '')
|
||||
s.setsockopt_string(zmq.SUBSCRIBE, '')
|
||||
|
||||
poller = zmq.Poller()
|
||||
poller.register(s, zmq.POLLIN)
|
||||
|
@ -37,26 +37,26 @@ try:
|
|||
msg = s.recv()
|
||||
msg = json.loads(msg)
|
||||
else:
|
||||
print 'UNKNOWN - ZMQ timeout. No message received in %i ms' % timeout
|
||||
print('UNKNOWN - ZMQ timeout. No message received in %i ms' % timeout)
|
||||
sys.exit(3)
|
||||
|
||||
for consumer in msg['consumers']:
|
||||
if consumer['name'] == check_consumer:
|
||||
if consumer['backlog'] is None:
|
||||
print 'ERROR: fedmsg consumer %s is not initialized' % consumer['name']
|
||||
print('ERROR: fedmsg consumer %s is not initialized' % consumer['name'])
|
||||
sys.exit(3)
|
||||
elif consumer['backlog'] > backlog_critical:
|
||||
print 'CRITICAL: fedmsg consumer %s backlog value is %i' % (consumer['name'],consumer['backlog'])
|
||||
print('CRITICAL: fedmsg consumer %s backlog value is %i' % (consumer['name'],consumer['backlog']))
|
||||
sys.exit(2)
|
||||
elif consumer['backlog'] > backlog_warning:
|
||||
print 'WARNING: fedmsg consumer %s backlog value is %i' % (consumer['name'],consumer['backlog'])
|
||||
print('WARNING: fedmsg consumer %s backlog value is %i' % (consumer['name'],consumer['backlog']))
|
||||
sys.exit(1)
|
||||
else:
|
||||
print 'OK: fedmsg consumer %s backlog value is %i' % (consumer['name'],consumer['backlog'])
|
||||
print('OK: fedmsg consumer %s backlog value is %i' % (consumer['name'],consumer['backlog']))
|
||||
sys.exit(0)
|
||||
|
||||
print "UNKNOWN: fedmsg consumer %s not found" % check_consumer
|
||||
print("UNKNOWN: fedmsg consumer %s not found" % check_consumer)
|
||||
sys.exit(3)
|
||||
except Exception as err:
|
||||
print "UNKNOWN:", str(err)
|
||||
print("UNKNOWN:", str(err))
|
||||
sys.exit(3)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python2
|
||||
#!/usr/bin/python
|
||||
|
||||
import json
|
||||
import os
|
||||
|
@ -14,18 +14,18 @@ try:
|
|||
fname = '/var/run/fedmsg/monitoring-%s.socket' % service
|
||||
|
||||
if not os.path.exists(fname):
|
||||
print "UNKNOWN - %s does not exist" % fname
|
||||
print("UNKNOWN - %s does not exist" % fname)
|
||||
sys.exit(3)
|
||||
|
||||
if not os.access(fname, os.W_OK):
|
||||
print "UNKNOWN - cannot write to %s" % fname
|
||||
print("UNKNOWN - cannot write to %s" % fname)
|
||||
sys.exit(3)
|
||||
|
||||
connect_to = "ipc:///%s" % fname
|
||||
ctx = zmq.Context()
|
||||
s = ctx.socket(zmq.SUB)
|
||||
s.connect(connect_to)
|
||||
s.setsockopt(zmq.SUBSCRIBE, '')
|
||||
s.setsockopt_string(zmq.SUBSCRIBE, '')
|
||||
poller = zmq.Poller()
|
||||
poller.register(s, zmq.POLLIN)
|
||||
|
||||
|
@ -36,23 +36,23 @@ try:
|
|||
msg = s.recv()
|
||||
msg = json.loads(msg)
|
||||
else:
|
||||
print 'UNKNOWN - ZMQ timeout. No message received in %i ms' % timeout
|
||||
print('UNKNOWN - ZMQ timeout. No message received in %i ms' % timeout)
|
||||
sys.exit(3)
|
||||
|
||||
for consumer in msg['consumers']:
|
||||
if consumer['name'] == check_consumer:
|
||||
if consumer['exceptions'] > exceptions_critical:
|
||||
print 'CRITICAL: fedmsg consumer %s exceptions value is %i' % (consumer['name'],consumer['exceptions'])
|
||||
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'])
|
||||
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'])
|
||||
print('OK: fedmsg consumer %s exceptions value is %i' % (consumer['name'],consumer['exceptions']))
|
||||
sys.exit(0)
|
||||
|
||||
print "UNKNOWN: fedmsg consumers %s not found" % check_consumer
|
||||
print("UNKNOWN: fedmsg consumers %s not found" % check_consumer)
|
||||
sys.exit(3)
|
||||
except Exception as err:
|
||||
print "UNKNOWN:", str(err)
|
||||
print("UNKNOWN:", str(err))
|
||||
sys.exit(3)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python2
|
||||
#!/usr/bin/python
|
||||
|
||||
import arrow
|
||||
import json
|
||||
|
@ -16,18 +16,18 @@ try:
|
|||
fname = '/var/run/fedmsg/monitoring-%s.socket' % service
|
||||
|
||||
if not os.path.exists(fname):
|
||||
print "UNKNOWN - %s does not exist" % fname
|
||||
print("UNKNOWN - %s does not exist" % fname)
|
||||
sys.exit(3)
|
||||
|
||||
if not os.access(fname, os.W_OK):
|
||||
print "UNKNOWN - cannot write to %s" % fname
|
||||
print("UNKNOWN - cannot write to %s" % fname)
|
||||
sys.exit(3)
|
||||
|
||||
connect_to = "ipc:///%s" % fname
|
||||
ctx = zmq.Context()
|
||||
s = ctx.socket(zmq.SUB)
|
||||
s.connect(connect_to)
|
||||
s.setsockopt(zmq.SUBSCRIBE, '')
|
||||
s.setsockopt_string(zmq.SUBSCRIBE, '')
|
||||
|
||||
poller = zmq.Poller()
|
||||
poller.register(s, zmq.POLLIN)
|
||||
|
@ -39,7 +39,7 @@ try:
|
|||
msg = s.recv()
|
||||
msg = json.loads(msg)
|
||||
else:
|
||||
print 'UNKNOWN - ZMQ timeout. No message received in %i ms' % timeout
|
||||
print('UNKNOWN - ZMQ timeout. No message received in %i ms' % timeout)
|
||||
sys.exit(3)
|
||||
|
||||
now = time.time()
|
||||
|
@ -50,20 +50,20 @@ try:
|
|||
diff = now - prod['last_ran']
|
||||
then = arrow.get(prod['last_ran']).humanize()
|
||||
if diff > elapsed_critical:
|
||||
print "CRITICAL: %s last ran %s (%i seconds ago)" % (
|
||||
print("CRITICAL: %s last ran %s (%i seconds ago)" % ()
|
||||
check_producer, then, diff)
|
||||
sys.exit(2)
|
||||
elif diff > elapsed_warning:
|
||||
print "WARNING: %s last ran %s (%i seconds ago)" % (
|
||||
print("WARNING: %s last ran %s (%i seconds ago)" % ()
|
||||
check_producer, then, diff)
|
||||
sys.exit(1)
|
||||
else:
|
||||
print "OK: %s last ran %s (%i seconds ago)" % (
|
||||
print("OK: %s last ran %s (%i seconds ago)" % ()
|
||||
check_producer, then, diff)
|
||||
sys.exit(0)
|
||||
|
||||
print "UNKNOWN: fedmsg producer %s not found" % check_producer
|
||||
print("UNKNOWN: fedmsg producer %s not found" % check_producer)
|
||||
sys.exit(3)
|
||||
except Exception as err:
|
||||
print "UNKNOWN:", str(err)
|
||||
print("UNKNOWN:", str(err))
|
||||
sys.exit(3)
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/python2
|
||||
#!/usr/bin/python
|
||||
|
||||
import json
|
||||
import os
|
||||
|
@ -12,22 +12,22 @@ try:
|
|||
fname = '/var/run/fedmsg/monitoring-%s.socket' % service
|
||||
|
||||
if not check_list:
|
||||
print "UNKNOWN - empty list of fedmsg consumers and producers to check"
|
||||
print("UNKNOWN - empty list of fedmsg consumers and producers to check")
|
||||
sys.exit(3)
|
||||
|
||||
if not os.path.exists(fname):
|
||||
print "UNKNOWN - %s does not exist" % fname
|
||||
print("UNKNOWN - %s does not exist" % fname)
|
||||
sys.exit(3)
|
||||
|
||||
if not os.access(fname, os.W_OK):
|
||||
print "UNKNOWN - cannot write to %s" % fname
|
||||
print("UNKNOWN - cannot write to %s" % fname)
|
||||
sys.exit(3)
|
||||
|
||||
connect_to = "ipc:///%s" % fname
|
||||
ctx = zmq.Context()
|
||||
s = ctx.socket(zmq.SUB)
|
||||
s.connect(connect_to)
|
||||
s.setsockopt(zmq.SUBSCRIBE, '')
|
||||
s.setsockopt_string(zmq.SUBSCRIBE, '')
|
||||
poller = zmq.Poller()
|
||||
poller.register(s, zmq.POLLIN)
|
||||
|
||||
|
@ -38,27 +38,27 @@ try:
|
|||
msg = s.recv()
|
||||
msg = json.loads(msg)
|
||||
else:
|
||||
print 'UNKNOWN - ZMQ timeout. No message received in %i ms' % timeout
|
||||
print('UNKNOWN - ZMQ timeout. No message received in %i ms' % timeout)
|
||||
sys.exit(3)
|
||||
|
||||
for consumer in msg['consumers']:
|
||||
if consumer['name'] in check_list and not consumer['initialized']:
|
||||
print 'ERROR: fedmsg consumer %s is not initialized' % consumer['name']
|
||||
print('ERROR: fedmsg consumer %s is not initialized' % consumer['name'])
|
||||
sys.exit(2)
|
||||
|
||||
for producer in msg['producers']:
|
||||
if producer['name'] in check_list and not producer['initialized']:
|
||||
print 'ERROR: fedmsg producer %s is not initialized' % producer['name']
|
||||
print('ERROR: fedmsg producer %s is not initialized' % producer['name'])
|
||||
sys.exit(2)
|
||||
|
||||
for item in check_list:
|
||||
if item not in [p['name'] for p in msg['producers'] + msg['consumers']]:
|
||||
print 'ERROR: %s not found among installed plugins' % item
|
||||
print('ERROR: %s not found among installed plugins' % item)
|
||||
sys.exit(2)
|
||||
|
||||
print "OK: fedmsg consumer(s) and producer(s) initialized"
|
||||
print("OK: fedmsg consumer(s) and producer(s) initialized")
|
||||
sys.exit(0)
|
||||
|
||||
except Exception as err:
|
||||
print "UNKNOWN:", str(err)
|
||||
print("UNKNOWN:", str(err))
|
||||
sys.exit(3)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue