Hi there I new to perl and SNMP....I need to write a trap handler in Perl that handle traps in SNMP environment such as link up/down and also it must do some configuration as a respond/correct to what happen,in my case I look for linkdown status and it should turn the alternative port up,that's all
so fa r I got the:
1- snmptrapd.conf file
authCommunity log,execute,net public
ignoreauthfailure no
format1 %#02.2h:%#02.2j TRAP%w.%q (%W) from %A Event:%v\n
traphandle "{abc}" eq "IF-MIB::LinkUp" || "{def}" eq "IF-MIB::LinkDown" | perl.exe traph.pl
2-traph.pl file
my $TRAP_FILE = "traps.all.log";
print "Executing Trap Handler...";
my $host = <STDIN>; # Read the Hostname - First line of input from STDIN
my $ip = <STDIN>; # Read the IP - Second line of input
my $result = index($ip,"127.0.0.1");
if ($result==-1) {
while(<STDIN>) {
push(@vars,$_);
}
open(TRAPFILE, ">> $TRAP_FILE");
print(TRAPFILE "New trap received: $OID\n\nHOST: $host\nIP: $ip\n");
foreach(@vars) {
print(TRAPFILE "TRAP: $_\n");
}
print(TRAPFILE "\n----------\n");
close(TRAPFILE);
}
print "finished.\n";
but I don't know how to write the piece of script that will do the configuration changes from linkdown to linkup...
can somebody help please...
so fa r I got the:
1- snmptrapd.conf file
authCommunity log,execute,net public
ignoreauthfailure no
format1 %#02.2h:%#02.2j TRAP%w.%q (%W) from %A Event:%v\n
traphandle "{abc}" eq "IF-MIB::LinkUp" || "{def}" eq "IF-MIB::LinkDown" | perl.exe traph.pl
2-traph.pl file
my $TRAP_FILE = "traps.all.log";
print "Executing Trap Handler...";
my $host = <STDIN>; # Read the Hostname - First line of input from STDIN
my $ip = <STDIN>; # Read the IP - Second line of input
my $result = index($ip,"127.0.0.1");
if ($result==-1) {
while(<STDIN>) {
push(@vars,$_);
}
open(TRAPFILE, ">> $TRAP_FILE");
print(TRAPFILE "New trap received: $OID\n\nHOST: $host\nIP: $ip\n");
foreach(@vars) {
print(TRAPFILE "TRAP: $_\n");
}
print(TRAPFILE "\n----------\n");
close(TRAPFILE);
}
print "finished.\n";
but I don't know how to write the piece of script that will do the configuration changes from linkdown to linkup...
can somebody help please...