Here's a little program to integrate snmp traps into your mon setup.
It's meant to be used as an 'EXEC'ed program from snmptt
(http://snmptt.sf.net), which does most of the heavy lifting.
I had written something like this in the past that got lost, I'm
sending out this version to the list for storage in contrib/ or,
minimally, in google's archive :-)
As the comment block says:
# to be used in conjunction with snmptt : it hands us
# the results of an snmp trap and we forward it on in
# a format mon will understand.
# usage:
# snmptrap2mon [(--watch|-w) watchname] [(--service|-s) servicename]
# [(--host|-h) hostname] [(--name|-n) trapname] [(--time|-t) timestamp]
# "Quoted longform text of alert to send"
# - 'watchname' and 'servicename' should map to your mon config;
# leave them off and they will be set to 'default'
# - 'host' is the host sending the trap, as best snmptt can tell
# - 'trapname' is the unique string configured for this trap in snmptt.conf
# - 'timestamp' will be the time alert was received/queued ($x or $X)
#
# Example, from /etc/snmp/snmptt.conf:
# EVENT communicationLost .1.3.6.1.4.1.318.0.1 "Status Events" CRITICAL
# FORMAT APC UPS: Communication lost between the agent and the UPS.
# EXEC snmptrap2mon -w symmetra-ups -s trap -h $A -n $N \
# -t "$x" "APC UPS: Communication lost between the agent and the UPS."
#
# See README.traps in the mon distribution to setup your mon.cf.
--
Eric Sorenson - Unix / Networks / MIS Manager - Transmeta Corporation
#!/usr/bin/perl
#
# to be used in conjunction with snmptt : it hands us
# the results of an snmp trap and we forward it on in
# a format mon will understand.
# usage:
# snmptrap2mon [(--watch|-w) watchname] [(--service|-s) servicename]
# [(--host|-h) hostname] [(--name|-n) trapname] [(--time|-t) timestamp]
# "Quoted longform text of alert to send"
# - 'watchname' and 'servicename' should map to your mon config;
# leave them off and they will be set to 'default'
# - 'host' is the host sending the trap, as best snmptt can tell
# - 'trapname' is the unique string configured for this trap in snmptt.conf
# - 'timestamp' will be the time alert was received/queued ($x or $X)
#
# Example, from /etc/snmp/snmptt.conf:
# EVENT communicationLost .1.3.6.1.4.1.318.0.1 "Status Events" CRITICAL
# FORMAT APC UPS: Communication lost between the agent and the UPS.
# EXEC snmptrap2mon -w symmetra-ups -s trap -h $A -n $N \
# -t "$x" "APC UPS: Communication lost between the agent and the UPS."
#
# See README.traps in the mon distribution to setup your mon.cf.
use Carp;
use Mon::Client;
use Getopt::Std;
getopts("w:s:h:n:t:u");
my $detail = join(" ",@ARGV);
my $monhost = 'monhost.domain.com';
my $monport = 2583;
my $watch = $opt_w or 'default';
my $service = $opt_s or 'default';
my $status = $opt_u ? 'ok' : 'fail' ;
croak "Need all of -h, -n and -t" unless (defined $opt_h and
defined $opt_n and defined $opt_t);
my $alerthost = $opt_h;
my $alertname = $opt_n;
my $alerttime = $opt_t;
my $summary = "$alertname trap from $alerthost at $alerttime";
$mon = new Mon::Client( host => $monhost, port => $monport );
croak "Couldn't make a new Mon::Client to $monhost on $monport"
unless $mon;
$t = $mon->send_trap(group => $watch,
service => $service,
retval => 1,
opstatus => $status,
summary => $summary,
detail => $detail,
);
exit ( $t );
_______________________________________________
mon mailing list
mon@linux.kernel.org
http://linux.kernel.org/mailman/listinfo/mon