Hey guys,
I am new to perl programing. The problem I have is that I am trying to take the output of the snmptrapd daemon form linux and put it in the input of my program. The purpose is to count how many times I have received a certain trap. This code works if I substitute the open(IN, snmptraps... say open(IN, ifconfig|); but since the daemon sits and waits for a trap i think has something to do with it.Please help!!!!
PERL CODE
_________________________________________________________________________________________
open (IN, "snmptrapd -P -o /home/kevin/supdude.log -F \"\nDATE %y-%m-%l TIME %h:%j:%k\n\n
Received From: %b
Enterprise: %N
Trap Type: %w
Trap Description: %W
Community: %P
OID: %v
Up Time: %T\n\"|");
while (<IN>) {
chomp;
if (/OID:/) {
@words = $_;
foreach $word (@words) {
$count{$word} += 1;
%count;
}
}
print "$_\n";
}
foreach $word (keys %count) {
print "\n$word has been seen $count{$word} times\n" ;
}
output from the daemon
__________________________________________________________________________________________
2002-11-15 16:48:33 UCD-snmp version 4.2.6 Started.
DATE 2002-11-15 TIME 16:48:37
Received From: 192.168.0.4
Enterprise: enterprises.2789.2005
Trap Type: 6
Trap Description: Enterprise Specific
Community: TRAP, SNMP v1, community public
OID: enterprises.2789.2005.1 = "www Server Has Been Restarted"
Up Time: 12216473
I am new to perl programing. The problem I have is that I am trying to take the output of the snmptrapd daemon form linux and put it in the input of my program. The purpose is to count how many times I have received a certain trap. This code works if I substitute the open(IN, snmptraps... say open(IN, ifconfig|); but since the daemon sits and waits for a trap i think has something to do with it.Please help!!!!
PERL CODE
_________________________________________________________________________________________
open (IN, "snmptrapd -P -o /home/kevin/supdude.log -F \"\nDATE %y-%m-%l TIME %h:%j:%k\n\n
Received From: %b
Enterprise: %N
Trap Type: %w
Trap Description: %W
Community: %P
OID: %v
Up Time: %T\n\"|");
while (<IN>) {
chomp;
if (/OID:/) {
@words = $_;
foreach $word (@words) {
$count{$word} += 1;
%count;
}
}
print "$_\n";
}
foreach $word (keys %count) {
print "\n$word has been seen $count{$word} times\n" ;
}
output from the daemon
__________________________________________________________________________________________
2002-11-15 16:48:33 UCD-snmp version 4.2.6 Started.
DATE 2002-11-15 TIME 16:48:37
Received From: 192.168.0.4
Enterprise: enterprises.2789.2005
Trap Type: 6
Trap Description: Enterprise Specific
Community: TRAP, SNMP v1, community public
OID: enterprises.2789.2005.1 = "www Server Has Been Restarted"
Up Time: 12216473