In a previous subroutine we poll the switch to get various pieces of information, including checking that the switch is reachable and online. The SNMP MIB sysObjectID is one of the MIB values we poll and store in a global variable $sysObjectID. We do this so we can tell what type of switch we are dealing with and how we should treat the different values.
Here's the subroutine that fills in those values;
###################################################################
# Subroutine grab_snmpsystem
#
# Purpose: perform SNMP query against device and return sysObjectID
###################################################################
sub grab_snmpsystem {
# DEBUG
print "DEBUG: IN grab_snmpsystem VAR snmphost = $snmphost\n" if ($DEBUG);
# Let's create a new SNMP session and object using global variables
my $grab_sess = new SNMP::Session ( DestHost => $snmphost,
Community => $community,
Version => SNMPVER );
# SNMP OIDs
my $grab_vars = new SNMP::VarList(
['sysDescr', 0],
['sysObjectID', 0],
['sysUpTime', 0],
['sysContact', 0],
['sysName', 0],
['sysLocation', 0],
['s5AgInfoVer',0] );
# DEBUG
print "DEBUG: snmphost = $snmphost and community = $community\n" if ($DEBUG);
# Let's actually retrieve some information
my @grab_vals = $grab_sess->get($grab_vars);
# If there was an error let's catch that and output an error
if ( $grab_sess->{ErrorStr} ) {
print "ERROR: sess->{ErrorStr} = $grab_sess->{ErrorStr}\n";
}
# If we don't get any values from the sysObjectID let's assume that we are
# unable to poll the switch for whatever reason and return errorlevel 99 (abort)
if ($grab_vals[0] eq "") {
print "ERROR: Unable to poll the switch $snmphost. !!!\n";
return 99;
}
# Let's assign the variables from the array
$sysDescr = $grab_vals[0];
$sysObjectID = $grab_vals[1];
$sysUpTime = $grab_vals[2];
$sysContact = $grab_vals[3];
$sysName = $grab_vals[4];
$sysLocation = $grab_vals[5];
$sysSoftware = $grab_vals[6];
# Old hack when using numeric OIDs, should be removed
$sysObjectID =~ s/.1.3.6.1.4.1/enterprises/;
# DEBUG
print "DEBUG: $snmphost sysObjectID = $sysObjectID \n" if ($DEBUG);
return 1;
};
#end sub grab_snmpsystem ########################################
Let me spend a little time sanitizing the script and I'll post it here in it's entirety. You may not want/need to use it in it's entirety but it should be helpfully enough so you can code your own solution.
Cheers!