Package: scrippy-snmp
scrippy_snmpBasicSNMPcapabilities for theScrippyframework.PrerequisitesPython modulesList of required modulesThe modules listed below will be automatically installed.pysnmppysnmp-mibsInstallationManualgitclonehttps://codeberg.org/scrippy/scrippy-snmp.gitcdscrippy-snmp
python-mpipinstall-rrequirements.txt
makeinstallWithpippipinstallscrippy-snmpUsageThis module allows basicSNMPoperations such asget,walkandset.it supportsSNMPversion 1 and version 2.  Version 3 is still in depveloppment.SNMPoperationsSetupAs in shellSNMPimplementation it is first needed to set the connection up, typically by providing the remote hostname or IP address, theUDPport on which join the host and thecommunity stringwhich is a sort of secret identifier that is allowed to perform some operations on the remote host.fromscrippy_snmp.snmpimportSnmpHOST="127.0.0.1"PORT=161RO_COMMUNITY="read-only-community"RW_COMMUNITY="read-write-community"VERSION="2c"snmp=Snmp(host=HOST,port=PORT,community=RO_COMMUNITY,version=VERSION)GetThegetoperation allows to retrieve a specificOIDvalue:LOCATION_OID=".1.3.6.1.2.1.1.6.0"snmp=Snmp(host=HOST,port=PORT,community=RO_COMMUNITY,version=VERSION)location=snmp.get(LOCATION_OID)print(location)("SNMPv2-MIB::sysLocation.0","Room 42")The return value is a 2 elementsTuplecontaining:TheOIDin text formatTheOIDvalueWalkThewalkoperation allow to retrieve a collection ofOIDvalue directly under the specifiedOIDSYSTEM_OID=".1.3.6.1.2.1.1"snmp=Snmp(host=HOST,port=PORT,community=RO_COMMUNITY,version=VERSION)result=snmp.walk(SYSTEM_OID)forvalueinresult:print(value)('SNMPv2-MIB::sysDescr.0','arcadia.local.mcos.nc 1148685499 FreeBSD 13.2-RELEASE')('SNMPv2-MIB::sysObjectID.0','SNMPv2-SMI::enterprises.12325.1.1.2.1.1')('SNMPv2-MIB::sysUpTime.0','320223')('SNMPv2-MIB::sysContact.0','sysmeister@example.com')('SNMPv2-MIB::sysName.0','scrippy.example.com')('SNMPv2-MIB::sysLocation.0','Room 42')...The return value is a list of 2 elementsTuples, each containing:TheOIDin text formatTheOIDvalueSetThesetoperation allows to set the value of a specificwrittableOID.LOCATION_OID=".1.3.6.1.2.1.1.6.0"snmp=Snmp(host=HOST,port=PORT,community=RW_COMMUNITY,version=VERSION)snmp.set(oid=LOCATION_OID,value="Room 200",datatype="str")location=snmp.get(LOCATION_OID)print(location)("SNMPv2-MIB::sysLocation.0","Room 200")Note:TheSnmpobject must have been set up with a community with write permission on the remote hostThedatatypemustbe provided to theSnmp.set()method (see below for availabledatatypes)TheSnmp.set()method does not return any value.Available data typesDatatypeSNMPequivalentInfonullNullNull valuebitsBitsThe BITS construct represents an enumeration of named bits. This collection is assigned non-negative, contiguous values, starting at zero.intInteger32The Integer32 type represents integer-valued information between -2^31 and 2^31-1 inclusivestrOctetStringThe OCTET STRING type represents arbitrary binary or textual data. Size limit is variable. 255 octets allow max interoperabilityipaddrIpAddressThe IpAddress type represents a 32-bit internet address. It is represented as an OCTET STRING of length 4, in network byte-ordercounterCounter32The Counter32 type represents a non-negative integer which monotonically increases until it reaches a maximum value of 2^32counter64Counter64The Counter64 type represents a non-negative integer which monotonically increases until it reaches a maximum value of 2^64-1, when it wraps around and starts increasing again from zerogaugeGauge32The Gauge32 type represents a non-negative integer, which may increase or decrease, but shall never exceed a maximum value, nor fall below a minimum value. The maximum value can not be greater than 2^32-1unisgnedUnsigned32The Unsigned32 type represents integer-valued information between 0 and 2^32-1 inclusive (0 to 4294967295 decimal)ticksTimeTicksThe TimeTicks type represents a non-negative integer which represents the time, modulo 2^32 (4294967296 decimal), in hundredths of a second between two epochs.