Add the supybot plugin check script in from puppet.
This commit is contained in:
parent
daceb9dd99
commit
afe872aa83
3 changed files with 110 additions and 0 deletions
108
roles/nagios_client/files/scripts/check_supybot_plugin
Executable file
108
roles/nagios_client/files/scripts/check_supybot_plugin
Executable file
|
@ -0,0 +1,108 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
""" check_supybot_plugin -- ensure that a plugin is loaded by supybot.
|
||||||
|
|
||||||
|
Run like:
|
||||||
|
|
||||||
|
check_supybot_plugin --target fedmsg
|
||||||
|
check_supybot_plugin --target koji --debug
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sys
|
||||||
|
import socket
|
||||||
|
import string
|
||||||
|
import uuid
|
||||||
|
|
||||||
|
|
||||||
|
def process_args():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
'-t', '--target', default=None, dest='target',
|
||||||
|
help="Required. The plugin we're looking for."
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-n', '--nick', default=None, dest='nick',
|
||||||
|
help="NICK to use when connecting to freenode.",
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-d', '--debug', default=False, action='store_true',
|
||||||
|
help='Print out debug information.', dest='debug',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-H', '--host', default='irc.freenode.net',
|
||||||
|
help='Host to connect to.', dest='host',
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
'-p', '--port', default=6667, type=int,
|
||||||
|
help='Host to connect to.', dest='port',
|
||||||
|
)
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
args = process_args()
|
||||||
|
|
||||||
|
# Use a random nick so people can't mess with us
|
||||||
|
if not args.nick:
|
||||||
|
args.nick = 'nrpe-' + str(uuid.uuid4()).split('-')[0]
|
||||||
|
|
||||||
|
name = "NRPE Bot"
|
||||||
|
readbuffer = ""
|
||||||
|
|
||||||
|
if not args.target:
|
||||||
|
print "UNKNOWN: No 'target' specified."
|
||||||
|
sys.exit(3)
|
||||||
|
|
||||||
|
args.target = args.target.lower()
|
||||||
|
|
||||||
|
if args.debug:
|
||||||
|
print "connecting to %s/%i" % (args.host, args.port)
|
||||||
|
|
||||||
|
try:
|
||||||
|
s = socket.socket()
|
||||||
|
s.connect((args.host, args.port))
|
||||||
|
|
||||||
|
if args.debug:
|
||||||
|
print "as %s/%s (%s)" % (args.nick, args.nick, name)
|
||||||
|
|
||||||
|
s.send("nick %s\r\n" % args.nick)
|
||||||
|
s.send("USER %s %s bla :%s\r\n" % (args.nick, args.host, name))
|
||||||
|
|
||||||
|
while 1:
|
||||||
|
readbuffer = readbuffer+s.recv(1024)
|
||||||
|
temp = string.split(readbuffer, "\n")
|
||||||
|
readbuffer = temp.pop()
|
||||||
|
|
||||||
|
for line in temp:
|
||||||
|
line = string.rstrip(line)
|
||||||
|
|
||||||
|
if args.debug:
|
||||||
|
print " * ", line
|
||||||
|
|
||||||
|
line = string.split(line)
|
||||||
|
|
||||||
|
if line[1] == 'MODE':
|
||||||
|
msg = "privmsg zodbot :list\r\n"
|
||||||
|
if args.debug:
|
||||||
|
print "sending:"
|
||||||
|
print " ->", msg
|
||||||
|
s.send(msg)
|
||||||
|
|
||||||
|
if line[1] == 'PRIVMSG':
|
||||||
|
if args.debug:
|
||||||
|
print "Got our response.."
|
||||||
|
|
||||||
|
plugins = map(str.lower, ' '.join(line[3:][1:]).split(', '))
|
||||||
|
|
||||||
|
if args.target in plugins:
|
||||||
|
print "OK"
|
||||||
|
s.send("QUIT")
|
||||||
|
sys.exit(0)
|
||||||
|
else:
|
||||||
|
print "CRITICAL: %r not loaded by supybot" % args.target
|
||||||
|
s.send("QUIT")
|
||||||
|
sys.exit(2)
|
||||||
|
except Exception as e:
|
||||||
|
print "UNKNOWN: ", str(e)
|
||||||
|
if args.debug:
|
||||||
|
raise
|
||||||
|
sys.exit(3)
|
|
@ -28,6 +28,7 @@
|
||||||
- check_fedmsg_consumer_backlog.py
|
- check_fedmsg_consumer_backlog.py
|
||||||
- check_fedmsg_consumer_exceptions.py
|
- check_fedmsg_consumer_exceptions.py
|
||||||
- check_fedmsg_producers_consumers.py
|
- check_fedmsg_producers_consumers.py
|
||||||
|
- check_supybot_plugin
|
||||||
|
|
||||||
# create dirs
|
# create dirs
|
||||||
# puppet used to make /var/spool/nagios (owned by nagios.nagios) mode 750
|
# puppet used to make /var/spool/nagios (owned by nagios.nagios) mode 750
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
command[check_supybot_fedmsg_plugin]={{libdir}}/nagios/plugins/check_supybot_plugin -t fedmsg
|
Loading…
Add table
Add a link
Reference in a new issue