From e2f6da7d8b394ba25b8002a1de7e647d42ceb88c Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Thu, 28 Dec 2006 15:17:15 +0000 Subject: [PATCH] Return UNKNOWN if the page cannot be retrieved from the datorhandbok. --- check_datorhandbok | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/check_datorhandbok b/check_datorhandbok index 6ecfb10..2fbfccc 100755 --- a/check_datorhandbok +++ b/check_datorhandbok @@ -6,6 +6,10 @@ import urllib2 import BeautifulSoup +def unknown(hostname, msg): + print "UNKNOWN - %s: %s" % (hostname, msg) + sys.exit(3) + def critical(hostname, msg): print "CRITICAL - %s: %s" % (hostname, msg) sys.exit(2) @@ -26,7 +30,10 @@ def nagios_url(hostname): "extinfo.cgi?type=1&host=" + hostname) def check_host(hostname): - page = urllib2.urlopen(url(hostname)) + try: + page = urllib2.urlopen(url(hostname)) + except urllib2.URLError, err: + unknown(hostname, err.args[0][1] + " while connecting to datorhandbok") contents = page.read() tree = BeautifulSoup.BeautifulSoup(contents) -- GitLab