From 8ef63b4ad1269285c671ad9fb43282d31c39773f Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Thu, 28 Dec 2006 14:54:34 +0000 Subject: [PATCH] Added check_datorhandbok. --- Makefile | 2 +- check_datorhandbok | 48 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 49 insertions(+), 1 deletion(-) create mode 100755 check_datorhandbok diff --git a/Makefile b/Makefile index fb99465..4bc99e6 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 0000000..b3df919 --- /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]) -- GitLab