Network Overview Alert

Frank Sweetser fes at users.sourceforge.net
Thu Mar 20 23:46:21 CET 2003


On Thu, Mar 20, 2003 at 02:39:44PM -0800, wasson at brawleyonline.com wrote:
> I'd like to set up nagios to send a morning 'overall network status' in a
> single email/SMS message. I'd like the alert to briefly list broken hosts
> and services or send an "Everything is up" message. I can set up a time
> period and run a custom command during that time, but I am getting stuck
> when I think about what command I actually want this to run.
> I didn't find anything in the FAQ or mailing list archives about this, but
> if it's been covered, please direct me to it.
> Tony Wasson

Here's a couple of scripts that I just started using here for just such
a purpose.  Call nagcechk from cron, editing it to fit your paths.

-- 
Frank Sweetser fs at wpi.edu
WPI Network Engineer
-------------- next part --------------
#!/bin/bash

MSG=`mktemp /tmp/nagcheck-$$-XXXXXX`
if [ ! -f $MSG -o ! -w $MSG ] ; then
	exit;
fi

/usr/lib/nagios/plugins/check_nagios /var/log/nagios/status.log 5 '/usr/sbin/nagios' | sed -e 's/:.*//' > $MSG 2>&1
/usr/local/bin/nagios-summary >> $MSG 2>&1

cat $MSG | mail -s 'Nagios Heartbeat' fs at wpi.edu
cat $MSG | /usr/local/bin/qpage -f nagios -p fs

rm -f $MSG
-------------- next part --------------
#!/usr/bin/perl -w

use strict;

my $logfile = $ARGV[0] || "/var/log/nagios/status.log";

open(STAT, "<$logfile") or die "Can't open logfile $logfile: $!\n";

my $line;
my %hst;
my %svc;

while(<STAT>){
	next if /^#/;
	$_ =~ s/^\S*\s*//;
	my @inf = split(/;/);
	if ($inf[0] eq 'HOST'){
		$hst{$inf[2]}++;
	}elsif ($inf[0] eq 'SERVICE'){
		$svc{$inf[3]}++;
	}
}

print "Hosts: ";
foreach my $key (keys %hst){
	print $key, ": ", $hst{$key}, " ";
}
print "\n";

print "Svcs: ";
foreach my $key (keys %svc){
	print $key, ": ", $svc{$key}, " ";
}
print "\n";



More information about the Users mailing list