From 9e7c894947a39ae62e0885bf085d30775e59bb93 Mon Sep 17 00:00:00 2001 From: Per Cederqvist <ceder@lysator.liu.se> Date: Thu, 21 Dec 2006 10:32:17 +0000 Subject: [PATCH] Fixed expiry of no-longer-monitored IP addresses. --- check_enodia_monitored | 2 +- check_syslog | 31 ++++++++++++++++++++++++------- 2 files changed, 25 insertions(+), 8 deletions(-) diff --git a/check_enodia_monitored b/check_enodia_monitored index 7b2b339..998fcab 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 af08485..b2064b0 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__': -- GitLab