Hi,
I have the following problem and thought you can help me out. Apologies for
sending a direct email.
We have this requirement of storing,processing and then selectively
forwarding the traps.
I have around 20 traphandle statements(all of them calling the same handler)
in snmptrapd.conf and one default embeded perl handler.
What I have seen is that either some traps are dropped or a long delay in
processing. I have a very high volume of incoming traps. Would appreciate
your advise.
Here is my snmptrapd.conf
perl NetSNMP::TrapReceiver::register("default", \&my_receiver);
perl do "/usr/local/fnmt/bin/genericTrapHandler.pl";
#traphandle for snmpv2 traps
# traphandle .1.3.6.1* /usr/local/fnmt/bin/snmpv2_2ana_trap
#traphandle .1.3.6.1.4.1.18289* /usr/local/fnmt/bin/cmm2ana_trap
#traphandle for Infovista
traphandle .1.3.6.1.4.1.1899* /usr/local/fnmt/bin/iv2ana_trap
#traphandle for MWTM
traphandle 1.3.6.1.4.1.9.9.311* /usr/local/fnmt/bin/mwtm2ana_trap
#traphandle default /usr/local/fnmt/bin/trap2syslog
traphandle .1.3.6.1.4.1.236* /usr/local/fnmt/bin/gen_co_forward
traphandle .1.3.6.1.4.1.3631* /usr/local/fnmt/bin/gen_co_forward
traphandle .1.3.6.1.4.1.2281* /usr/local/fnmt/bin/gen_co_forward
traphandle .1.3.6.1.4.1.6642.815* /usr/local/fnmt/bin/gen_co_forward
traphandle .1.3.6.1.4.1.11858* /usr/local/fnmt/bin/gen_co_forward
traphandle .1.3.6.1.4.1.9608.9999* /usr/local/fnmt/bin/gen_co_forward
traphandle 1.3.6.1.4.1.16258* /usr/local/fnmt/bin/gen_co_forward
traphandle .1.3.6.1.4.1.16258* /usr/local/fnmt/bin/gen_co_forward
traphandle 1.3.6.1.4.1.6649* /usr/local/fnmt/bin/gen_co_forward
traphandle 1.3.6.1.4.1.7569* /usr/local/fnmt/bin/gen_co_forward
traphandle 1.3.6.1.4.1.9148* /usr/local/fnmt/bin/gen_co_forward
#traphandle .1.3.6.1.4.1.3902.3400.* /usr/local/fnmt/bin/gen_co_forward
And here is the traphandle
#!/usr/local/fnmt/bin/perl
#############################################################
# gen_co_forward
#
#
#
# Description : This program should be called by snmptrapd via the
# traphandler option. This program will read STDIN input and convert
# it to a syslog-ng log format. It will then send the log message to
the
# syslogng server listed in the global defines section.
#
#
#############################################################
use DBI;
use Socket;
use Sys::Hostname;
use Net::SNMP;
use Time::localtime;
# Global defines
$GEN_CO_HOST = "GEN_CO Server"
$FNMT_HOST = "HOST";
$GEN_CO_PORT= "1162";
$SESS_COMMUNITY="public";
#############################################################
# Main code starts here
#############################################################
$tm = localtime;
my $YEAR=$tm->year+1900 ;
my $MONTH=$tm->mon+1 ;
my $DAY=$tm->mday ;
my $HOUR=$tm->hour ;
my $MIN=$tm->min ;
my $SEC=$tm->sec;
my $LOG_PATH="/FNMT_SAN_DISK/fnmt/logs";
my $hostname, $ipaddr, $agentaddress;
my $sysuptime, $oid, $value, $traptype, $trapdata, $msg, $oid_str;
my $validtrap = 0;
my @varBindArray;
my @varBindArraysam;
#open(LOGGER, ">>/usr/local/fnmt/logs/gen_co_forward.log");
#open(PIPE,">>/var/run/db.pipe");
my ($session, $error) = Net::SNMP->session(
-hostname => $GEN_CO_HOST,
-community => $SESS_COMMUNITY,
-port => $GEN_CO_PORT,
-localaddr => $FNMT_HOST
);
if (!defined($session)) {
`echo "ERROR: $error" >> $LOG_PATH/gen_co_forward.log`;
exit 1;
}
# process the trap:
# 1st line is the hostname
$hostname = <STDIN>;
chomp($hostname);
# 2nd line is the IP address
$ipaddress = <STDIN>;
chomp($ipaddress);
$ipaddress =~ s/(.*\[)(.*)(\].*)/$2/;
$agentaddress = $ipaddress;
$samsungIndex = -1;
# Loop through remaining lines.
while(<STDIN>) {
($oid, $value) = /([^\s]+)\s+(.*)/;
# printf LOGGER "value pair $oid,$value\n ";
# Process the trap PDU's.
if ($oid =~ /sysUpTimeInstance|1.3.6.1.2.1.1.3.0/) { # Store the uptime
$sysuptime = $value;
}
elsif ($oid =~ /snmpTrapAddress.0|1.3.6.1.6.3.18.1.3.0/) { # Store real
source address
if ($value !~ /^127\..*|^0\..*/) { # Make sure the address is valid.
$agentaddress = $value;
push(@varBindArray, ($oid,IPADDRESS, $value));
}
}
elsif ($oid =~ /snmpTrapOID.0|1.3.6.1.6.3.1.1.4.1.0/) { # Store trap
type
$traptype = $value;
push(@varBindArray, ($oid,OCTET_STRING, $value));
`echo "Trap snmpTrapOID-->".$value."\n" >>
$LOG_PATH/gen_co_forward.log`;
}
elsif ($oid =~ /snmpTrapOID.0|1.3.6.1.6.3.1.1.4.1/) { # Store trap
type
$traptype = $value;
push(@varBindArray, ($oid,OCTET_STRING, $value));
`echo "Trap snmpTrapOID-->".$value."\n" >>
$LOG_PATH/gen_co_forward.log`;
} elsif ($oid =~/^snmpTrapEnterprise|1.3.6.1.6.3.1.1.4.3/) { # check
the snmpTrapententerprice id
$snmpTrapEnterpriseId=$value;
push(@varBindArray, ($oid,OCTET_STRING, $value));
}
elsif ($oid !~ /snmpTrapCommunity.0|1.3.6.1.6.3.18.1.4/) { # Store
the trap data values
$value =~ s/"//g;
$oid_str=$oid_str.",".$oid."=".$value;
push(@varBindArray, ($oid,OCTET_STRING, $value));
}
} # end of while(stdin)
#print LOGGER "\nTRAP ends here\n";
$specifictrap=26; #snmp epm-notification specific
$enterprise="1.3.6.1.4.1.239";
# Storing traps into DB
if(!(is_device_in_maintenance($agentaddress))){
$result = $session->trap(
-enterprise => $enterprise,
-agentaddr => $agentaddress,
-generictrap => $specifictrap,
-varbindlist => \...@varbindarray
);
`echo "Trap sent-->".$result."OID->".$oid_str."\n" >>
$LOG_PATH/gen_co_forward.log`;
if(length($oid_str) > 2000){
$oid_str = substr($oid_str,0,2000);
}
`echo "insert into trap_data
(id,host,hostname,fullhost,facility,PRIORITY,errorname,message,TIMESTAMP,SUPPRESSION_FLAG)
VALUES
(test_seq.nextval,'$agentaddress','$agentaddress','$agentaddress','local','info','$traptype','SNMPTRAP-$oid_str',to_date('$MONTH
$DAY $HOUR:$MIN:$SEC', 'mm dd hh24:mi:ss'),'0');\ncommit;\n" >
/var/run/db.pipe`;
}else{
print "\n Trap not stored in DB, for devices in maintanance";
`echo "Trap not sent-->OID->".$oid_str."\n" >>
$LOG_PATH/gen_co_forward.log`;
#print PIPE "insert into trap_data
(id,host,hostname,fullhost,facility,PRIORITY,errorname,message,TIMESTAMP,SUPPRESSION_FLAG)
VALUES
(test_seq.nextval,'$agentaddress','$agentaddress','$agentaddress','local','info','$traptype','SNMPTRAP-$oid_str',to_date('$MONTH
$DAY $HOUR:$MIN:$SEC', 'mm dd hh24:mi:ss'),'1');\ncommit;\n" or die("Unable
to write the trap details in db.pipe") ;
}
Thanks in advance.
Regards
Sateesh
------------------------------------------------------------------------------
Oracle to DB2 Conversion Guide: Learn learn about native support for PL/SQL,
new data types, scalar functions, improved concurrency, built-in packages,
OCI, SQL*Plus, data movement tools, best practices and more.
http://p.sf.net/sfu/oracle-sfdev2dev
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users