Greeting Monks,
I am new to PERL so forgive me if this is a trival question. I am building a script to be run via Openview to query an SNMP MIB for get status of an indexed interface. Based on the description of the interface and status, I want to formulate a custom trap.
At this point, I am using Net::SNMP to gain the information from the network device using SNMPv1 (only support by device). Where I am running into trouble is exacting the variables from the FOREACH loop so I can utilize them in a if/else loop. I started from a well know bit of code and modified it.
Here is the code so far:
#!/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;
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.
Thanks
Rick