diff --git a/Makefile b/Makefile index fb9946512b1608870324cad00f78a1f8a0fce7dc..4bc99e6c46593601a2dc94f18ae99b13748b5205 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ LIBEXECDIR = /usr/local/nagios/libexec/ SCRIPTS = check_cups check_glsa check_saned check_lpd check_hddtemp \ check_link_status check_true check_lysrdiff check_syslog \ check_ping check_enodia_monitored check_hostextinfo \ - check_hydra + check_hydra check_datorhandbok all:; diff --git a/check_datorhandbok b/check_datorhandbok new file mode 100755 index 0000000000000000000000000000000000000000..b3df9190740e7b5be24832af1742bea0fed763b6 --- /dev/null +++ b/check_datorhandbok @@ -0,0 +1,48 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +import urllib2 + +import BeautifulSoup + +def critical(hostname, msg): + print "CRITICAL - %s: %s" % (hostname, msg) + sys.exit(2) + +def warning(hostname, msg): + print "WARNING - %s: %s" % (hostname, msg) + sys.exit(1) + +def ok(hostname, msg): + print "OK - %s: %s" % (hostname, msg) + sys.exit(0) + +def url(hostname): + return "http://datorhandbok.lysator.liu.se/index.php/" + hostname + +def nagios_url(hostname): + return ("https://nagios.lysator.liu.se/nagios/cgi-bin/" + "extinfo.cgi?type=1&host=" + hostname) + +def check_host(hostname): + page = urllib2.urlopen(url(hostname)) + contents = page.read() + tree = BeautifulSoup.BeautifulSoup(contents) + + csub = tree.find(id="contentSub") + if csub.findNext(attrs={"alt": "#REDIRECT"}): + warning(hostname, "broken redirect") + + firstpara = csub.findNext("p").string + if firstpara == u"(Det finns för tillfället ingen text på den här sidan.)\n": + warning(hostname, "not documented") + + if csub.findNext(attrs={"href": nagios_url(hostname)}): + ok(hostname, "all ok") + else: + warning(hostname, "Nagios link missing") + +if __name__ == '__main__': + import sys + + check_host(sys.argv[1])