python - Do I need different MIB with those OID? -


i got legacy powershell script retrieve information via snmp, i'm trying port in python using snimpy.

$printersip = '10.100.7.47', '10.100.7.48' function get-snmpinfo ([string[]]$printers) {     begin {         $snmp = new-object -comobject oleprn.olesnmp     }     process {         foreach ($ip in $printers) {             $snmp.open($ip,"public",2,3000)             [pscustomobject][ordered]@{                 name        = $snmp.get(".1.3.6.1.2.1.1.5.0")                 ip          = $ip                 uptime      = [timespan]::fromseconds(($snmp.get(".1.3.6.1.2.1.1.3.0"))/100)                 model       = $snmp.get(".1.3.6.1.2.1.25.3.2.1.3.1")                 description = $snmp.get(".1.3.6.1.2.1.1.1.0")                 #contact     = $snmp.get(".1.3.6.1.2.1.1.4.0")                 #sn          = $snmp.get(".1.3.6.1.2.1.43.5.1.1.17.1")                 #location    = $snmp.get(".1.3.6.1.2.1.1.6.0")                 #tonername   = $snmp.get("43.11.1.1.6.1.1")             }         }     }     end {         $snmp.close()     } } get-snmpinfo $printersip | ft -autosize * 

snimpy usage

from section usage of official documentation use load method load mib file.

from snimpy.manager import manager m snimpy.manager import load  load("if-mib") m = m("localhost") print(m.ifdescr[0]) 

finding oid name

i can't find oid name of identifiers. instance:

question

  • depending on oid's name i'm trying use, need load different mib file ? (e.g. printer-mib, if-mib, etc.)
  • where can find missing oid's name

if use load() method scalars , row names made available instance attributes hence you're able query 'syscontact' etc, 'sysdescr' , 'sysname' not part of if-mib not able it.

you need load in relevant mib such snmpv2-mib or attempt value via oid directly.

update: i've had , snimpy , loooks pysnmp doing collection, user directly. sample below collecting new different snmp values oid , others via named variable within mib (you need have relevant mib available if want via name). sample pretty taken pysnmp documentation

from pysnmp.entity.rfc3413.oneliner import cmdgen  cmdgen = cmdgen.commandgenerator()  errorindication, errorstatus, errorindex, varbinds = cmdgen.getcmd(     cmdgen.communitydata('public'),     cmdgen.udptransporttarget(('demo.snmplabs.com', 161)),     '1.3.6.1.2.1.1.1.0',            # sysdescr     '1.3.6.1.2.1.1.2.0',            # sysobjectid     '1.3.6.1.2.1.1.3.0',            # uptime     '1.3.6.1.2.1.1.4.0',            # contact     '1.3.6.1.2.1.1.5.0',            # sysname     '1.3.6.1.2.1.1.6.0',            # location     cmdgen.mibvariable('snmpv2-mib', 'sysdescr', 0),     #.1.3.6.1.2.1.1.1.0 sysdescr     cmdgen.mibvariable('snmpv2-mib', 'sysname', 0)     #.1.3.6.1.2.1.1.5.0 sysname )    # check errors , print out results if errorindication:     print(errorindication) else:     if errorstatus:         print('%s @ %s' % (             errorstatus.prettyprint(),             errorindex , varbinds[int(errorindex)-1] or '?'             )         )     else:         name, val in varbinds:             print('%s = %s' % (name.prettyprint(), val.prettyprint())) 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -