# main section my ( $sysChassisID, #and other stuff ); # define OID of system Chassis ID attribute (serial number) my @sysChassisIDOID = ( "1.3.6.1.4.1.9.3.6.3", # .chassisId "1.3.6.1.2.1.47.1.1.1.1.11.0", # .entPhysicalSerialNumber.0 "1.3.6.1.2.1.47.1.1.1.1.11.1", # .entPhysicalSerialNumber.1 "1.3.6.1.4.1.9.5.1.2.19.0", # .CiscoStackMIB.chassisSerialNumberString ); # calling the sub: (this takes place inside a while loop as # the script goes through a list of IP addresses. # I borrowed heavily from cdppoll.pl. $sysChassisID = getSnmpInfo (@sysChassisIDOID) sub getSnmpInfo { my($crap , $value , $result); my $varType = ref($_[0]); # Get the variable type from ref() if ($varType eq "ARRAY") { my @tmp = $_[0]; print "\n DEBUG::GET_SNMP_INFO: OID is an array" if $debugging; # march through the array until a valid value is collected then # return that value. while (@tmp) { my $tOID = shift @tmp; $value = getSnmpInfo($tOID); return $value if ((ref($value) eq "SCALAR") and ($value =~ m/[A-Za-z0-9]{1,}/)); next; } } elsif ($varType eq "SCALAR") { print "\n DEBUG::GET_SNMP_INFO: OID is a scalar" if $debugging; } else { print "\n DEBUG:GET_SNMP_INFO:: OID is an illegal variable type ($varType)" if $debugging; return 0; } my($oid) = $_[0]; $session = (defined $_[1]) ? ($_[1]) : ($session); unless ($session) { print "\n DEBUG::GET_SNMP_INFO: session not established in getSnmpInfo sub-routine, check scopes and pass as option 2 to getSnmpInfo" if $debugging; print "\n WARN::GET_SNMP_INFO: getSnmpInfo returning null, session unavailable."; return 0; } print "\n DEBUG::GET_SNMP_INFO: fetching OID: $oid" if $debugging; $result = $session->get_request("$oid"); return unless (defined $result); ($crap , $value) = %$result; print "\n DEBUG::GET_SNMP_INFO: OID value: $value" if $debugging; return $value; }