I suspect I'm not the first to write something like this, but I don't
recall anyone posting it to the mon list. This is a simple command
line client for sending mon traps.
montrap [-p port] [-r retval] -o opstatus -s summary [-d detail]
host group:service
host - Mon host to send trap to
opstatus - one of "fail", "ok", "coldstart", "warmstart", etc.
The original plan was to have a Mon watch for every critical
cron job, have those critical cron jobs run montrap at the end
of every successful run to indicate that they were OK, and have
Mon page if the trap isn't received in the specified interval.
I haven't put this together yet, but I'm sure someone can think
of other interesting uses for it.
Note that it doesn't support passwords - I'd rather run with
no password than specify it on the command line, but it's easy
enough to hard-code it or read from a file if someone wants.
-- Ed
#!/usr/bin/perl
use strict;
use Getopt::Std;
use Mon::Client;
my @opstrings= (
"fail", "ok", "coldstart", "warmstart", "linkdown",
"unknown", "timeout", "untested",
);
my $usage= "montrap [-p port] [-r retval] -o opstatus -s summary [-d detail] host
group:service\n";
use vars qw($opt_p $opt_r $opt_o $opt_s $opt_d);
getopts("p:r:o:s:d:");
die $usage unless @ARGV == 2 and $ARGV[1] =~ /[^:]+:[^:]+/;
my $host= $ARGV[0];
my ($group, $service)= $ARGV[1] =~ /^([^:]+):([^:]+)/;
my $port= $opt_p || 2583;
my $retval= $opt_r || 255;
my $opstatus= $opt_o || die "montrap: '-o opstatus' required\n";
die "montrap: unrecognized opstatus: $opstatus\n" unless
grep $opstatus, @opstrings;
my $summary= $opt_s || die "montrap: '-s summary' required\n";
my $detail= $opt_d || "";
my $mon;
if (!defined ($mon = Mon::Client->new)) {
die "$0: could not create client object: $@";
}
$mon->host($host);
$mon->send_trap(
group=> $group,
service=> $service,
retval=> $retval,
opstatus=> $opstatus,
summary=> $summary,
detail => $detail,
);