Created
June 11, 2012 17:46
-
-
Save mzupan/2911557 to your computer and use it in GitHub Desktop.
Nagios check for monit services going unmonitored
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import urllib2 | |
import base64 | |
import sys | |
import optparse | |
from xml.dom.minidom import parseString | |
p = optparse.OptionParser(conflict_handler="resolve", description= "This Nagios plugin checks monit services if they are actively monitoring.") | |
p.add_option('-H', '--host', action='store', type='string', dest='host', default='127.0.0.1', help='The hostname you want to connect to') | |
p.add_option('-P', '--port', action='store', type='string', dest='port', default='2812', help='The port you want to connect to') | |
p.add_option('-u', '--user', action='store', type='string', dest='user', default='', help='The username to auth as') | |
p.add_option('-p', '--passwd', action='store', type='string', dest='passwd', default='', help='The password to use for the user') | |
options, arguments = p.parse_args() | |
request = urllib2.Request("http://%s:%s/_status?format=xml" % (options.host, options.port)) | |
base64string = base64.encodestring('%s:%s' % (options.user, options.passwd)).replace('\n', '') | |
request.add_header("Authorization", "Basic %s" % base64string) | |
result = urllib2.urlopen(request) | |
dom = parseString("".join(result.readlines())) | |
for service in dom.getElementsByTagName('service'): | |
name = service.getElementsByTagName('name')[0].firstChild.data | |
monitor = int(service.getElementsByTagName('monitor')[0].firstChild.data) | |
if monitor == 0: | |
print "%s not monitored" % name | |
sys.exit(2) | |
print "Everything being monitored" | |
sys.exit(0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# the command | |
# | |
define command{ | |
command_name check_monit | |
command_line /usr/lib/nagios/plugins/check_monit.py -H $HOSTADDRESS$ -P 2812 -u user -p passwd | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment