nagios server plugins: port to py3
This commit is contained in:
parent
28b3b7f575
commit
5fe015a90a
4 changed files with 86 additions and 77 deletions
|
@ -1,4 +1,4 @@
|
||||||
#!/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.
|
||||||
|
@ -14,7 +14,9 @@ Usage:
|
||||||
: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
|
||||||
|
@ -53,14 +55,14 @@ def main():
|
||||||
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)
|
||||||
|
|
||||||
|
|
||||||
|
@ -68,5 +70,5 @@ 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,5 +1,6 @@
|
||||||
#!/usr/bin/python2
|
#!/usr/bin/python
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
import fcntl
|
import fcntl
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -7,11 +8,12 @@ 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,4 +1,4 @@
|
||||||
#!/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:
|
||||||
|
@ -7,7 +7,10 @@ Run like:
|
||||||
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
|
||||||
|
@ -49,60 +52,60 @@ 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[0] == ':zodbot!supybot@fedora/bot/zodbot':
|
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