Attached is "monfailures", a simple command line Mon client that does a "list failures" and outputs a short summary. It's meant for the staff at my shop who are too lazy to fire up their Web browsers to check Mon. I can add this command to their .profile so at least they will see any failures when they log in each morning.
A typical invocation of "monfailures" would look like this (we hope): $ monfailures No failures found. And if something Mon was watching had failed, you might see a list like this: Hostgroup:Service Down Since Error Summary ----------------- ---------- ------------- frog-servers:ping Fri Jan 11 04:58:40 [acked] frog1 msmail:smtp999 Fri Jan 11 04:58:54 msmail33 Note the "[acked]" flag for an acknowledged failure. Since in my shop, the Mon username and password are hardcoded in the script (got to make it easy for those lazy operators :-), I put the script into inetd on a high-numbered port so the staff can do something like "netcat monhost 12345" to see the current status (actually, I wrote a short script to do that to further ease the burden on the command-line challenged folks). -- Ed
#!/usr/bin/perl -w # Quickly show Mon failure status from command line. # to configure, hard-code the user and password for either # your public Mon username or a username that is only allowed # to use the "list" command and nothing else. I run this # script out of inetd on the mon server so the people who can # see its results can't read the script (and see the hard-coded # password). # Written by Ed Ravin <[EMAIL PROTECTED]> Wed Jan 2 12:23:44 EST 2002 # Release Version: 1.2 # $Header$ use strict; my %opt; use Getopt::Long; GetOptions (\%opt, "debug", "server=s", "port=s", "user=s", "password=s"); ############################ configurable stuff my $default_user="readonly"; my $default_password= "public"; ############################ my $debug= $opt{'debug'} || 0; my (%failures); my ($now); use Mon::Client; my $mon; # find the client if (!defined ($mon = Mon::Client->new)) { die "$0: could not create client object: $@"; } if (defined $opt{'server'}) { $mon->host ($opt{'server'}); } else { $mon->host ("localhost"); } $mon->port ($opt{'port'}) if (defined $opt{'port'}); $mon->username($opt{'user'} || $default_user); $mon->password($opt{'password'} || $default_password); $mon->connect; die "$0: Could not connect to server: " . $mon->error . "\n" unless $mon->connected; $mon->login; die "$0: login failure: " . $mon->error . "\n" if $mon->error; # Load data from Mon %failures = $mon->list_failures; die "$0: Error doing list_failures : " . $mon->error if ($mon->error); $now= time; # time mon data was fetched # group=thathost service=port8888 opstatus=0 last_opstatus=0 exitval=1 timer=11 # last_success=0 last_trap=0 last_check=955058065 ack=0 ackcomment='' # alerts_sent=0 depstatus=0 depend='' monitor='tcp.monitor -p 8888' # last_summary='thathost' # last_detail='\0athathost could not connect: Connection refused\0a' # last_failure=955058067 interval=60 first_failure=955055062 # failure_duration=3052 my ($watch, $service, $downtime, $summary, $acked); format STDOUT_TOP = Hostgroup:Service Down Since Error Summary ----------------- ---------- ------------- . format STDOUT = @<<<<<<<<<<<<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<< @<<<<<<<<<<<<<<<<<<<<<<<<< $watch . ":" . $service, $downtime, $summary . # list out any failures if (%failures) { foreach $watch (keys %failures) { foreach $service (keys %{$failures{$watch}}) { my $sref= \%{$failures{$watch}->{$service}}; $downtime= localtime $sref->{'first_failure'}; $acked= $sref->{'ack'} !=0; $summary= $sref->{'last_summary'}; $summary= "[acked] $summary" if $acked; write; } } print "\n"; exit(1); } else { print "No failures found.\n"; exit(0); }