diff --git a/check_enodia_monitored b/check_enodia_monitored index 7b2b339e62577ffd8522f0638434a2c580bff1d3..998fcab2300ebcea94f2f339105205e8ed33c82a 100755 --- a/check_enodia_monitored +++ b/check_enodia_monitored @@ -10,7 +10,7 @@ CHECKED=/usr/local/nagios/var/checked_ips UNCHECKED=`tempfile` unmonitored="" -find "$CHECKED" -mtime +1 -exec rm {} \; +find "$CHECKED" -mtime +0 -type f -exec rm {} \; while read ip host do if [ ! -f $CHECKED/$ip ] diff --git a/check_syslog b/check_syslog index af084854097be04d2b8c9ec5526ec7b55fba7796..b2064b017f5ea0840ed9435f6a1c753483aeb181 100755 --- a/check_syslog +++ b/check_syslog @@ -4,21 +4,35 @@ # This script assumes that syslog log files are created using the # following hierarchy: # -# /misc/syslogs/2006-12/2006-12-18/sellafield +# /misc/syslogs/2006-12/2006-12-18/sellafield-130.236.254.103 # -# where 2006 is a year, 12 a month, 18 a day, and sellafield a hostname. +# where 2006 is a year, 12 a month, 18 a day, and sellafield a +# hostname with its IP address appended. import time import os import errno +import socket +import sys CANON = { 'inservitus': 'studsvik', } +DNS_OVERRIDE = { + 'hoover': '127.0.0.1', + } + def filename(y, m, d, host): - return "/misc/syslogs/%04d-%02d/%04d-%02d-%02d/%s" % ( - y, m, y, m, d, host) + ip = DNS_OVERRIDE.get(host) + if ip is None: + try: + ip = socket.gethostbyname(host) + except socket.gaierror, e: + print "CRITICAL - %s: %s" % (host, e[1]) + sys.exit(2) + return "/misc/syslogs/%04d-%02d/%04d-%02d-%02d/%s-%s" % ( + y, m, y, m, d, host, ip) def find_newest_file(hostname): t = time.time() @@ -39,14 +53,17 @@ def check_host(hostname): hostname = CANON.get(hostname, hostname) fn, statval = find_newest_file(hostname) if fn is None: - print "CRITICAL - no activity within the last 14 days" + print "CRITICAL - no activity for %s within the last 14 days" % ( + hostname, ) sys.exit(2) age = time.time() - statval.st_mtime if age > 1.5 * 3600: - print "WARNING - no activity for %.1f hours" % (age / 3600.0) + print "WARNING - no activity for %s for %.1f hours" % ( + hostname, age / 3600.0) sys.exit(1) else: - print "OK - activity %.2f minutes ago" % (age / 60.0) + print "OK - activity from %s %.2f minutes ago" % ( + hostname, age / 60.0) if __name__ == '__main__':