[EMAIL PROTECTED] wrote:
Alex ,
Thank u very much for tht . But how do i pass the enterprise variable (say hostname and ip address ) to my perl program and how do i access it . i try to access it using command line arguments ( sth like ARGV[0] ,ARGV[1] ) but tht attempt failed .
The output from snmptrapd is piped to your handler. It is not passed using command line arguments. Here is a simple Perl trap handler:
#!/usr/bin/perl $spoolfile = '/tmp/traphandler.log';
open SPOOL, ">>$spoolfile"; print SPOOL "\n".localtime()."\n";
while (defined($line = <>))
{
print SPOOL $line;
}This will dump whatever snmptrapd sends to it. You can test it by just running the script from the shell, typing a few lines of text and the pressing Ccontrol-d (control-z in Windows).
BTW, when testing you can't just print to the screen as you will never see it, even if you run snmptrapd with -f -Le, so you should output to a file like I did above.
Alex
As of now iam redirecting my snmptrapd output ( using a format string ) to a log file and reading the interface details from there using AWK to determine the interface name . It works fine but iam sure we have a better way of doing it !!!
can u pls suggest me how do we directly pass the arguments to my Perl program ??
Thanx in advance
regards , rajasekaran C
Alex Burger <[EMAIL PROTECTED] rceforge.net> To [EMAIL PROTECTED] 01/24/2005 11:03 cc PM [EMAIL PROTECTED] et Subject Re: Need help regarding snmptrapd.conf [EMAIL PROTECTED] wrote:
hi friends ,
Is it possible to send the name of the interface as an argument to the perl script we call in TRAPHANDLE command??
I have something like this in my snmptrapd.conf file and it works fine .
traphandle IF-MIB::linkDown /home/rchand/mail/sendmail.pl down
But i also like to know which interface caused this trap as i recieve
traps
from multiple interface...
The index of the interface is available in the trap and is passed to your trap handler by snmptrapd. Snmptrapd passes the following to your script:
hostname ip address uptime trapname / OID enterprise variables (one per line) ip address from trap agent trap community string enterprise
The above are passed as variable name [space] variable value pairs, except for the first two.
If you parse the enterprise variables, you will be able to find the interface index number. You will then need to retrieve the actual interface text name from the router or device using an snmpget in your script.
For example, the following is a linkDown trap (using numeric OIDs - snmptrapd was running with the -On switch).
router01 192.168.1.1 .1.3.6.1.2.1.1.3.0 31:18:27:02.00 .1.3.6.1.6.3.1.1.4.1.0 .1.3.6.1.6.3.1.1.5.3 .1.3.6.1.2.1.2.2.1.1.3 3 .1.3.6.1.2.1.2.2.1.7.3 2 .1.3.6.1.2.1.2.2.1.8.3 3
(Note: The above example is missing the ip address, community string and enterprise which is usually the last three lines.)
You want to look at these three lines, which are the 'enterprise variables':
.1.3.6.1.2.1.2.2.1.1.3 3 .1.3.6.1.2.1.2.2.1.7.3 2 .1.3.6.1.2.1.2.2.1.8.3 3
If you look in IF-MIB.txt, you will see under 'linkDown NOTIFICATION-TYPE':
OBJECTS { ifIndex, ifAdminStatus, ifOperStatus }
The three objects above are the three variables that are passed, which you see above. ifIndex has a value of 3, ifAdminStatus is 2 and ifOperStatus is 3.
If I had run snmptrapd without the -On, it would have been:
. . IF-MIB::ifIndex.3 3 IF-MIB::ifAdminStatus.3 2 IF-MIB::ifOperStatus.3 3 . .
which is easier to read..
To get the name of the interface on a (Cisco) router for the above, you would something like:
snmpget -v 1 -c public router01 .1.3.6.1.2.1.2.2.1.2.index
for example:
snmpget -v 1 -c public router01 .1.3.6.1.2.1.2.2.1.2.3 IF-MIB::ifDescr.1 = STRING: FastEthernet0/3
The tutorial should also help:
http://www.net-snmp.org/tutorial/tutorial-5/commands/snmptrap.html
Alex
------------------------------------------------------- This SF.Net email is sponsored by: IntelliVIEW -- Interactive Reporting Tool for open source databases. Create drag-&-drop reports. Save time by over 75%! Publish reports on the web. Export to DOC, XLS, RTF, etc. Download a FREE copy at http://www.intelliview.com/go/osdn_nl _______________________________________________ Net-snmp-coders mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/net-snmp-coders
