+nagios-plugins-local (0.17~test.0) UNRELEASED; urgency=medium
+
+ * check_monit:
+ - improve various aspects:
+ + list all unmonitored services, not just the first
+ + exit with unknown state if can't connect to monit's web interface
+
+ -- Michael Howe <michael@michaelhowe.org> Sat, 09 Dec 2017 20:29:00 +0000
+
nagios-plugins-local (0.16) unstable; urgency=medium
* check_configtool:
options, arguments = p.parse_args()
-
-request = urllib2.Request("http://%s:%s/_status?format=xml" % (options.host, options.port))
+check_url = "http://%s:%s/_status?format=xml" % (options.host, options.port)
+request = urllib2.Request(check_url)
base64string = base64.encodestring('%s:%s' % (options.user, options.passwd)).replace('\n', '')
request.add_header("Authorization", "Basic %s" % base64string)
-result = urllib2.urlopen(request)
+try:
+ result = urllib2.urlopen(request)
+except urllib2.HTTPError:
+ print "Cannot connect to %s as user '%s'" % (check_url, options.user)
+ sys.exit(3)
dom = parseString("".join(result.readlines()))
+monitored = []
+unmonitored = []
+exitcode = 0
+
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)
+ unmonitored.append(name)
+ else:
+ monitored.append(name)
+
+if len(unmonitored):
+ print "monit: unmonitored services: %s" % (', '.join(unmonitored))
+ exitcode = 2
+else:
+ print "monit: no unmonitored services"
+ exitcode = 1
+
+sys.exit(exitcode)