/usr/bin/monfailures is in mon 1.2.0-8.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 | #!/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 <eravin@panix.com> Wed Jan 2 12:23:44 EST 2002
# Release Version: 1.2
# $Header: /cvsroot/mon/mon/clients/monfailures,v 1.1.1.1 2004/06/09 05:18:07 trockij Exp $
use strict;
my %opt;
use Getopt::Long;
GetOptions (\%opt, "debug", "server=s", "port=s", "user=s", "password=s");
############################ configurable stuff
my $default_user="";
my $default_password= "";
############################
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;
if ($mon->username ne "")
{
$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);
}
|