Hi,all
     I am new to snmp.As we know,the agent sends a 'coldStart(0)' trap when it first starts up, and an enterprise-specific trap 'nsNotifyShutdown' (or 'ucdShutdown') when it  stops. in order to capture the  'coldStart(0)' trap and  'ucdShutdown' trap. I configured the snmptrapd.conf in /usr/local/share/snmp/snmptrapd.conf as follow:
 
traphandle default /path/to/traphandle.pl
 
and the contents of  the script traphandle.pl are as follow:
 
#!/usr/bin/perl
# A simple trap handler
my $TRAP_FILE = "/var/snmp/traps.all.log";
my $host = <STDIN>; # Read the Hostname - First line of input from STDIN
chomp($host);
my $ip = <STDIN>; # Read the IP - Second line of input
chomp($ip);
while(<STDIN>) {
chomp($_);
push(@vars,$_);
}
open(TRAPFILE, ">> $TRAP_FILE");
$date = 'date';
chomp($date);
print(TRAPFILE "New trap received: $date for $OID\n\nHOST: $host\nIP: $ip\n");
foreach(@vars) {
print(TRAPFILE "TRAP: $_\n");
}
print(TRAPFILE "\n----------\n");
close(TRAPFILE);
 
   And of course i have installed net-snmp-5.2.1 in default prefix on my PC(redhat9.0 Linux) .But when i started the snmptrapd and snmpd in my PC,There was no information on trap printed out,so is it when i stopped snmpd.
   what  did i do wrong? Any answers and guide are greatly appreciated .
   Thank you in advance

Reply via email to