diff --git a/check_datorhandbok b/check_datorhandbok index 6ecfb10fb5adc6556bb45946fdeed29c1a25403d..2fbfccc18ae771c7bbb0538c85ba96ce753b3762 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)