tx_sailor has asked for the wisdom of the Perl Monks concerning the following question:
Any thoughts would be greatly appreciated as I cannot seem to figure this out. Since it is SNMPv1 the getbulk and other options do not work.#!/usr/local/bin/perl # use strict; use Net::SNMP '5.0' || die("Cannot Load SNMP Module\n"); ############################## CONFIGURATION ######################### +######### $snmpnotify = "nnmsnmpnotify.ovpl"; $trap3 = ".1.3.6.1.4.1.13169.9999.0.5"; #Context trap with informatio +n(used by the Pairwise correlation) #$snmp_target = '10.180.89.81'; $snmp_target = ''; $snmp_community = '$@g3on'; ########### Check to see that the number of args is correct ########## +######### if (!($#ARGV == 0)){ exit 1; } $snmp_target = $ARGV[0]; ################################### OIDs ############################# +######### my $oid_ifIndex = '.1.3.6.1.4.1.13169.1.2.10.4.1.1'; my $oid_ifDescr = '.1.3.6.1.4.1.13169.1.2.11.5.1.3'; my $oid_ifOperStatus = '.1.3.6.1.4.1.13169.1.2.10.4.1.2'; my @interfaceList = [$oid_ifDescr, $oid_ifOperStatus]; ################################### CODE ############################# +######### my ($session, $error, $result, @ifindex, $key); my %alarmpoint_status = ( 1 => 'off', 2 => 'on', 3 => 'unknown'); ###################################################################### +######### ## Creation Session ($session, $error) = Net::SNMP->session( -hostname => shift || $snmp_target, -community => shift || $snmp_community, -port => shift || 161, -version => 'snmpv1' ); if (!defined($session)) { printf("ERROR: %s.\n", $error); exit 1; } ## Get AlarmPoint Indexes $result = $session->get_table( -baseoid => $oid_ifIndex ); printf("%s\n", $result ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } foreach $key ($session->var_bind_names) { push(@ifindex, $result->{$key}); } ## Get AlarmPoint Details $result = $session->get_entries( -columns => @interfaceList); printf("%s\n", $result ); if (!defined($result)) { printf("ERROR: %s.\n", $session->error); $session->close; exit 1; } ## Loop through indexes and Output Interface Description and Status foreach $key (@ifindex) { my $alarmd = $result->{$oid_ifDescr.'.'.$key}; my $alarms = $alarmpoint_status{ $result->{$oid_ifOperStatus.'.'. +$key} }; printf("%s : %s\n", $alarmd, $alarms ); } ### Here is where I want to take the value $alarmd and $alarms and uti +lize them in an if state like below: if ($alarms = "off") { $cmd = `$snmpnotify -v 2c -a $snmp_target 10.180.52.58 $trap3 1.3. +6.1.4.1.13169.9999.5.1 OCTETSTRINGASCII $alarmd "Alarm" 1.3.6.1.4.1.1 +3169.9999.5.2 OCTETSTRINGASCII $snmp_target 1.3.6.1.4.1.13169.9999.5. +3 OCTETSTRINGASCII $alarms`; } else {} $session->close;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: FOREACH Variables
by NetWallah (Canon) on Aug 11, 2009 at 01:17 UTC | |
|
Re: FOREACH Variables
by snoopy (Curate) on Aug 11, 2009 at 04:43 UTC | |
|
Re: FOREACH Variables
by jbt (Chaplain) on Aug 11, 2009 at 03:17 UTC | |
|
Re: FOREACH Variables
by cdarke (Prior) on Aug 11, 2009 at 07:41 UTC | |
|
Re: FOREACH Variables
by snoopy (Curate) on Aug 11, 2009 at 03:18 UTC | |
by GrandFather (Saint) on Aug 11, 2009 at 03:27 UTC |