update nagios client checks to py3
This commit is contained in:
parent
8a8b1731b3
commit
32330de141
4 changed files with 87 additions and 78 deletions
|
@ -1,26 +1,28 @@
|
||||||
#!/usr/bin/python2
|
#!/usr/bin/python
|
||||||
""" NRPE check for datanommer/fedmsg health.
|
""" NRPE check for datanommer/fedmsg health.
|
||||||
Given a category like 'bodhi', 'buildsys', or 'git', return an error if
|
Given a category like 'bodhi', 'buildsys', or 'git', return an error if
|
||||||
datanommer hasn't seen a message of that type in such and such time.
|
datanommer hasn't seen a message of that type in such and such time.
|
||||||
You can alternatively provide a 'topic' which might look like
|
You can alternatively provide a 'topic' which might look like
|
||||||
org.fedoraproject.prod.bodhi.update.comment.
|
org.fedoraproject.prod.bodhi.update.comment.
|
||||||
|
|
||||||
Requires: python-dateutil
|
Requires: python-dateutil
|
||||||
|
|
||||||
Usage:
|
Usage:
|
||||||
|
|
||||||
$ check_datanommer_timesince CATEGORY WARNING_THRESH CRITICAL_THRESH
|
$ check_datanommer_timesince CATEGORY WARNING_THRESH CRITICAL_THRESH
|
||||||
|
|
||||||
:Author: Ralph Bean <rbean@redhat.com>
|
:Author: Ralph Bean <rbean@redhat.com>
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from builtins import str
|
||||||
import dateutil.relativedelta
|
import dateutil.relativedelta
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
def query_timesince(identifier):
|
def query_timesince(identifier):
|
||||||
# If it has a '.', then assume it is a topic.
|
# If it has a '.', then assume it is a topic.
|
||||||
if '.' in identifier:
|
if '.' in identifier:
|
||||||
|
@ -34,39 +36,39 @@ def query_timesince(identifier):
|
||||||
prefix, stdout = stdout.split("INFO] ", 1)
|
prefix, stdout = stdout.split("INFO] ", 1)
|
||||||
data = json.loads(stdout)
|
data = json.loads(stdout)
|
||||||
return float(data[0])
|
return float(data[0])
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
identifier, warning_threshold, critical_threshold = sys.argv[-3:]
|
identifier, warning_threshold, critical_threshold = sys.argv[-3:]
|
||||||
timesince = query_timesince(identifier)
|
timesince = query_timesince(identifier)
|
||||||
warning_threshold = int(warning_threshold)
|
warning_threshold = int(warning_threshold)
|
||||||
critical_threshold = int(critical_threshold)
|
critical_threshold = int(critical_threshold)
|
||||||
|
|
||||||
time_strings = []
|
time_strings = []
|
||||||
rd = dateutil.relativedelta.relativedelta(seconds=timesince)
|
rd = dateutil.relativedelta.relativedelta(seconds=timesince)
|
||||||
for denomination in ['years', 'months', 'days', 'hours', 'minutes', 'seconds']:
|
for denomination in ['years', 'months', 'days', 'hours', 'minutes', 'seconds']:
|
||||||
value = getattr(rd, denomination, 0)
|
value = getattr(rd, denomination, 0)
|
||||||
if value:
|
if value:
|
||||||
time_strings.append("%d %s" % (value, denomination))
|
time_strings.append("%d %s" % (value, denomination))
|
||||||
|
|
||||||
string = ", ".join(time_strings)
|
string = ", ".join(time_strings)
|
||||||
reason = "datanommer has not seen a %r message in %s" % (identifier, string)
|
reason = "datanommer has not seen a %r message in %s" % (identifier, string)
|
||||||
|
|
||||||
if timesince > critical_threshold:
|
if timesince > critical_threshold:
|
||||||
print "CRIT: ", reason
|
print("CRIT: ", reason)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
if timesince > warning_threshold:
|
if timesince > warning_threshold:
|
||||||
print "WARN: ", reason
|
print("WARN: ", reason)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
print "OK: ", reason
|
print("OK: ", reason)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
try:
|
try:
|
||||||
main()
|
main()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "UNKNOWN: ", str(e)
|
print("UNKNOWN: ", str(e))
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
#!/usr/bin/python2
|
#!/usr/bin/python
|
||||||
|
from __future__ import print_function
|
||||||
|
from builtins import str
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
|
@ -9,15 +11,15 @@ try:
|
||||||
|
|
||||||
items = queue.length
|
items = queue.length
|
||||||
if items > 500:
|
if items > 500:
|
||||||
print "CRITICAL: %i tasks in fcomm queue" % items
|
print("CRITICAL: %i tasks in fcomm queue" % items)
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
elif items > 250:
|
elif items > 250:
|
||||||
print "WARNING: %i tasks in fcomm queue" % items
|
print("WARNING: %i tasks in fcomm queue" % items)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
else:
|
else:
|
||||||
print "OK: %i tasks in fcomm queue" % items
|
print("OK: %i tasks in fcomm queue" % items)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "UNKNOWN:", str(e)
|
print("UNKNOWN:", str(e))
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
|
@ -1,17 +1,19 @@
|
||||||
#!/usr/bin/python2
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import fcntl
|
import fcntl
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
try:
|
try:
|
||||||
f = open('/mnt/koji/.nagios_test', 'r')
|
f = open('/mnt/koji/.nagios_test', 'r')
|
||||||
f.close()
|
f.close()
|
||||||
f = open('/mnt/koji/.nagios_test', 'w')
|
f = open('/mnt/koji/.nagios_test', 'w')
|
||||||
except IOError:
|
except IOError as e:
|
||||||
print "Could not create file"
|
print(e)
|
||||||
|
print("Could not create file")
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
|
|
||||||
fcntl.flock(f, fcntl.LOCK_EX)
|
fcntl.flock(f, fcntl.LOCK_EX)
|
||||||
f.close()
|
f.close()
|
||||||
print "File Locked Successfully"
|
print("File Locked Successfully")
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
|
@ -1,20 +1,23 @@
|
||||||
#!/usr/bin/python2
|
#!/usr/bin/python
|
||||||
""" check_supybot_plugin -- ensure that a plugin is loaded by supybot.
|
""" check_supybot_plugin -- ensure that a plugin is loaded by supybot.
|
||||||
|
|
||||||
Run like:
|
Run like:
|
||||||
|
|
||||||
check_supybot_plugin --target fedmsg
|
check_supybot_plugin --target fedmsg
|
||||||
check_supybot_plugin --target koji --debug
|
check_supybot_plugin --target koji --debug
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
|
from builtins import str
|
||||||
|
from builtins import map
|
||||||
import argparse
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
import socket
|
import socket
|
||||||
import string
|
import string
|
||||||
import uuid
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
def process_args():
|
def process_args():
|
||||||
parser = argparse.ArgumentParser()
|
parser = argparse.ArgumentParser()
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -38,71 +41,71 @@ def process_args():
|
||||||
help='Host to connect to.', dest='port',
|
help='Host to connect to.', dest='port',
|
||||||
)
|
)
|
||||||
return parser.parse_args()
|
return parser.parse_args()
|
||||||
|
|
||||||
args = process_args()
|
args = process_args()
|
||||||
|
|
||||||
# Use a random nick so people can't mess with us
|
# Use a random nick so people can't mess with us
|
||||||
if not args.nick:
|
if not args.nick:
|
||||||
args.nick = 'nrpe-' + str(uuid.uuid4()).split('-')[0]
|
args.nick = 'nrpe-' + str(uuid.uuid4()).split('-')[0]
|
||||||
|
|
||||||
name = "NRPE Bot"
|
name = "NRPE Bot"
|
||||||
readbuffer = ""
|
readbuffer = ""
|
||||||
|
|
||||||
if not args.target:
|
if not args.target:
|
||||||
print "UNKNOWN: No 'target' specified."
|
print("UNKNOWN: No 'target' specified.")
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
||||||
args.target = args.target.lower()
|
args.target = args.target.lower()
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
print "connecting to %s/%i" % (args.host, args.port)
|
print("connecting to %s/%i" % (args.host, args.port))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
s = socket.socket()
|
s = socket.socket()
|
||||||
s.connect((args.host, args.port))
|
s.connect((args.host, args.port))
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
print "as %s/%s (%s)" % (args.nick, args.nick, name)
|
print("as %s/%s (%s)" % (args.nick, args.nick, name))
|
||||||
|
|
||||||
s.send("nick %s\r\n" % args.nick)
|
s.send(("nick %s\r\n" % args.nick).encode())
|
||||||
s.send("USER %s %s bla :%s\r\n" % (args.nick, args.host, name))
|
s.send(("USER %s %s bla :%s\r\n" % (args.nick, args.host, name)).encode())
|
||||||
|
|
||||||
while 1:
|
while 1:
|
||||||
readbuffer = readbuffer+s.recv(1024)
|
readbuffer = readbuffer+s.recv(1024).decode()
|
||||||
temp = string.split(readbuffer, "\n")
|
temp = str.split(readbuffer, "\n")
|
||||||
readbuffer = temp.pop()
|
readbuffer = temp.pop()
|
||||||
|
|
||||||
for line in temp:
|
for line in temp:
|
||||||
line = string.rstrip(line)
|
line = str.rstrip(line)
|
||||||
|
|
||||||
if args.debug:
|
if args.debug:
|
||||||
print " * ", line
|
print(" * ", line)
|
||||||
|
|
||||||
line = string.split(line)
|
line = str.split(line)
|
||||||
|
|
||||||
if line[1] == 'MODE':
|
if line[1] == 'MODE':
|
||||||
msg = "privmsg zodbot :list\r\n"
|
msg = "privmsg zodbot :list\r\n".encode()
|
||||||
if args.debug:
|
if args.debug:
|
||||||
print "sending:"
|
print("sending:")
|
||||||
print " ->", msg
|
print(" ->", msg)
|
||||||
s.send(msg)
|
s.send(msg)
|
||||||
|
|
||||||
if line[1] == 'PRIVMSG' and line[0] != ':freenode-connect!frigg@freenode/utility-bot/frigg':
|
if line[0] == ':zodbot!supybot@fedora/bot/zodbot':
|
||||||
if args.debug:
|
if args.debug:
|
||||||
print "Got our response.."
|
print("Got our response..")
|
||||||
|
|
||||||
plugins = map(str.lower, ' '.join(line[3:][1:]).split(', '))
|
plugins = list(map(str.lower, ' '.join(line[3:][1:]).split(', ')))
|
||||||
|
|
||||||
if args.target in plugins:
|
if args.target in plugins:
|
||||||
print "OK"
|
print("OK")
|
||||||
s.send("QUIT")
|
s.send("QUIT".encode())
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
else:
|
else:
|
||||||
print "CRITICAL: %r not loaded by supybot" % args.target
|
print("CRITICAL: %r not loaded by supybot" % args.target)
|
||||||
s.send("QUIT")
|
s.send("QUIT".encode())
|
||||||
sys.exit(2)
|
sys.exit(2)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print "UNKNOWN: ", str(e)
|
print("UNKNOWN: ", str(e))
|
||||||
if args.debug:
|
if args.debug:
|
||||||
raise
|
raise
|
||||||
sys.exit(3)
|
sys.exit(3)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue