Skip to content
Snippets Groups Projects
Commit e9e1b3e9 authored by Per Cederqvist's avatar Per Cederqvist
Browse files

Added check_syslog, which checks that all hosts logs to syslog.

parent b0064fce
Branches
No related tags found
No related merge requests found
DESTDIR = /usr/local/nagios/libexec/ DESTDIR = /usr/local/nagios/libexec/
SCRIPTS = check_cups check_glsa check_saned check_lpd check_hddtemp \ SCRIPTS = check_cups check_glsa check_saned check_lpd check_hddtemp \
check_link_status check_true check_lysrdiff check_link_status check_true check_lysrdiff check_syslog
all:; all:;
......
#!/usr/bin/env python
# Check that the syslog file for a certain host has changed recently.
# This script assumes that syslog log files are created using the
# following hierarchy:
#
# /misc/syslogs/2006-12/2006-12-18/sellafield
#
# where 2006 is a year, 12 a month, 18 a day, and sellafield a hostname.
import time
import os
import errno
def filename(y, m, d, host):
return "/misc/syslogs/%04d-%02d/%04d-%02d-%02d/%s" % (
y, m, y, m, d, host)
def find_newest_file(hostname):
t = time.time()
for attempts in range(14):
tm = time.localtime(t)
fn = filename(tm.tm_year, tm.tm_mon, tm.tm_mday, hostname)
try:
statval = os.stat(fn)
except OSError, e:
if e.errno != errno.ENOENT:
raise
else:
return fn, statval
t -= 24 * 3600
return None, None
def check_host(hostname):
fn, statval = find_newest_file(hostname)
if fn is None:
print "CRITICAL - no activity within the last 14 days"
sys.exit(2)
age = time.time() - statval.st_mtime
if age > 10 * 3600:
print "WARNING - no activity for %.1g hours" % (age / 3600.0)
sys.exit(1)
else:
print "OK - activity %.2g hours ago" % (age / 3600.0)
if __name__ == '__main__':
import sys
check_host(sys.argv[1])
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment