[Mon-commit] mon/alert.d trap.alert,1.1.1.1,1.2
Brought to you by:
trockij
From: David N. <vi...@us...> - 2004-06-14 10:54:03
|
Update of /cvsroot/mon/mon/alert.d In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19671 Modified Files: trap.alert Log Message: Rewrote trap.alert to use Mon::Client instead of trying to encode the trap directly. Index: trap.alert =================================================================== RCS file: /cvsroot/mon/mon/alert.d/trap.alert,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -C2 -d -r1.1.1.1 -r1.2 *** trap.alert 9 Jun 2004 05:18:07 -0000 1.1.1.1 --- trap.alert 14 Jun 2004 10:53:54 -0000 1.2 *************** *** 26,33 **** # use Getopt::Std; use Socket; - getopts ("s:g:h:t:l:o:uU:P:"); ! $TRAP_PRO_VERSION = 0.3807; $summary=<STDIN>; --- 26,34 ---- # use Getopt::Std; + use Mon::Client; use Socket; ! getopts ("s:g:h:t:l:o:uU:P:T:"); ! $summary=<STDIN>; *************** *** 50,81 **** } ! $pkt = ""; ! $pkt .= "pro=$TRAP_PRO_VERSION\n"; ! $pkt .= "usr=$USER\n" . "pas=$PASS\n" if ($USER ne ""); ! $pkt .= "typ=$ENV{MON_ALERTTYPE}\n"; ! $pkt .= "seq=0\n"; ! $pkt .= "grp=$ENV{MON_GROUP}\n"; ! $pkt .= "svc=$ENV{MON_SERVICE}\n"; ! $pkt .= "sta=$ENV{MON_RETVAL}\n"; ! $pkt .= "spc=$OPST\n"; ! $pkt .= "tsp=$t\n"; ! $pkt .= "sum=$summary\n"; ! $pkt .= "dtl=$detail\n.\n"; ! ! $proto = getprotobyname ("udp") || die "could not get proto\n"; ! socket (TRAP, AF_INET, SOCK_DGRAM, $proto) || ! die "could not create UDP socket: $!\n"; ! $port = getservbyname ('mon', 'udp') || 2583; foreach $host (@ARGV) { ! my $paddr = sockaddr_in ($port, inet_aton ($host)); ! if (!defined (send (TRAP, $pkt, 0, $paddr))) { ! print STDERR "could not send trap to $host: $!\n"; ! next; ! } ! } ! close (TRAP); exit; --- 51,78 ---- } ! foreach $op (keys %Mon::Client::OPSTAT) { ! $OPSTATUS = $op if ($Mon::Client::OPSTAT{$op} == $OPST); ! } ! $c = new Mon::Client ( ! port => getservbyname ('mon', 'udp') || 2583, ! ); + $c->user($USER) if ($USER); + $c->password($PASS) if ($PASS); foreach $host (@ARGV) { ! $c->host($host); ! ! $res = $c->send_trap( group => $ENV{MON_GROUP}, ! service => $ENV{MON_SERVICE}, ! retval => $ENV{MON_RETVAL}, ! opstatus => $OPSTATUS, ! summary => $summary, ! detail => $detail, ! ); ! print STDERR "Error sending trap to $host\n" if (!$res); ! print STDERR "Error is: ". $c->error() . "\n" if (!$res); ! } exit; |