pysnmp

How to get SNMP data using pysnmp?

馋奶兔 提交于 2019-12-05 22:12:02
I want to get snmp data by using python pysnmp module. I was using command line to get SNMP data but now I want to read it using pysnmp module. SNMP command - snmpwalk -v 1 -c public <ip address>:<port> xyz::pqr I was using command like above. Now I tried something like below - import netsnmp def getmac(): oid = netsnmp.VarList(netsnmp.Varbind('.1.3.6.1.2.1.17.7.1.2.2.1.2')) res = netsnmp.snmpgetbulk(oid, Version = 1, DestHost='ip', Community='pub') return res print getmac() I'm facing error - import netsnmp. No module netsnmp Anyone can give me suggestion how I can get snmp data from the snmp

Listen traps with pysnmp

故事扮演 提交于 2019-12-05 12:41:43
Hello I'm trying to listen for traps with this code from pysnmp doc: from pysnmp.carrier.asynsock.dispatch import AsynsockDispatcher from pysnmp.carrier.asynsock.dgram import udp, udp6 from pyasn1.codec.ber import decoder from pysnmp.proto import api def cbFun(transportDispatcher, transportDomain, transportAddress, wholeMsg): print('cbFun is called') while wholeMsg: print('loop...') msgVer = int(api.decodeMessageVersion(wholeMsg)) if msgVer in api.protoModules: pMod = api.protoModules[msgVer] else: print('Unsupported SNMP version %s' % msgVer) return reqMsg, wholeMsg = decoder.decode( wholeMsg

Using pySNMP to write an SNMP agent (for OpenNMS)

孤街浪徒 提交于 2019-12-05 09:59:13
I'm trying to write a python SNMP agent that I can embed within my python application so that the application can be monitored remotely by OpenNMS. OpenNMS expects the Agent to implement the HOST-RESOURCES-MIB querying two fields hrSWRunName and hrSWRunStatus . I took a pysnmp example as the basis of my code and edited it as I believed necessary. The resulting code looks like this: import logging from pysnmp import debug from pysnmp.carrier.asyncore.dgram import udp from pysnmp.entity import engine, config from pysnmp.entity.rfc3413 import cmdrsp, context from pysnmp.proto.api import v2c from

Convert snmp octet string to human readable date format

99封情书 提交于 2019-12-04 20:09:55
问题 Using the pysnmp framework i get some values doing a snmp walk. Unfortunately for the oid 1.3.6.1.21.69.1.5.8.1.2 (DOCS-CABLE-DEVICE-MIB) i get a weird result which i cant correctly print here since it contains ascii chars like BEL ACK When doing a repr i get: OctetString('\x07\xd8\t\x17\x03\x184\x00') But the output should look like: 2008-9-23,3:24:52.0 the format is called "DateAndTime". How can i translate the OctetString output to a "human readable" date/time ? 回答1: You can find the

how to load and walk a custom mib in pysnmp?

天大地大妈咪最大 提交于 2019-12-04 15:29:01
I'm new to SNMP/pysnmp and I'm trying to implement an agent that uses a custom MIB. I'm looking at the following example on the pysnmp site, but I can't seem to get it to work. Here are the steps I'm taking: convert my MIB file to a pysnmp module using build-pysnmp-mib (this succeeds without errors) set MIB source and load the MIB module using MibBuilder() use the example referenced above to set up the agent (only thing I added is the mibBuilder) use net-snmp's snmpwalk to view the loaded MIB: The snmpwalk command is: snmpwalk -v3 -u usr-md5-none -l authNoPriv -A authkey1 -E 8000000001020304

Sending SNMP Traps containing custom data

末鹿安然 提交于 2019-12-04 03:44:05
问题 A client has requested that instead of email alerts that we send SNMP Traps to their Nagios server instead. The only thing I knew about SNMP before yesterday was that it sounded like an acronym, so please excuse (and correct me on) any misconceptions about it that I may have. The only information that needs to be sent in the trap pertains to data about the event we are alerting our client about, which is just a couple of values pulled from our database. Needless to say these aren't in any

Convert snmp octet string to human readable date format

北慕城南 提交于 2019-12-03 14:21:51
Using the pysnmp framework i get some values doing a snmp walk. Unfortunately for the oid 1.3.6.1.21.69.1.5.8.1.2 (DOCS-CABLE-DEVICE-MIB) i get a weird result which i cant correctly print here since it contains ascii chars like BEL ACK When doing a repr i get: OctetString('\x07\xd8\t\x17\x03\x184\x00') But the output should look like: 2008-9-23,3:24:52.0 the format is called "DateAndTime". How can i translate the OctetString output to a "human readable" date/time ? You can find the format specification here . A date-time specification. field octets contents range ----- ------ -------- ----- 1

Implementing a custom MIB in a PySNMP agent

五迷三道 提交于 2019-12-03 09:09:33
I'm having difficulty implementing a custom MIB in a PySNMP agent. I've started with: http://pysnmp.sourceforge.net/examples/4.x/v3arch/agent/cmdrsp.html created my own MIB file, used build-pysnmp-mib to make a Python module and successfully imported the symbol. I can't see where to go next. I need to somehow mount the imported symbol on the list of served MIBs and provide an implementation. (It's currently a MIB with one read-only INTEGER property.) The MIB file passes smilint without warnings, but I've had to manually add a missing MibScalar import to the generated module. MIB: TRS-MIB

Can't get pysnmp to work with pyinstaller

岁酱吖の 提交于 2019-12-02 17:50:50
问题 Attempting to get pyinstaller to work with pysnmp Here is the spec file # -*- mode: python -*- a = Analysis(['app.py'], pathex=['/home/robertja/pysnmp'], hiddenimports=None, hookspath=None, runtime_hooks=None, ) x = Tree('</long prefix>/pysnmp/smi/mibs',prefix='pysnmp_mibs',excludes=None) pyz = PYZ(a.pure) exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, x, name='app', debug=False, strip=None, upx=True, console=True ) Here is the program file #!/usr/bin/python from pysnmp.entity

Can't get pysnmp to work with pyinstaller

百般思念 提交于 2019-12-02 11:38:46
Attempting to get pyinstaller to work with pysnmp Here is the spec file # -*- mode: python -*- a = Analysis(['app.py'], pathex=['/home/robertja/pysnmp'], hiddenimports=None, hookspath=None, runtime_hooks=None, ) x = Tree('</long prefix>/pysnmp/smi/mibs',prefix='pysnmp_mibs',excludes=None) pyz = PYZ(a.pure) exe = EXE(pyz, a.scripts, a.binaries, a.zipfiles, a.datas, x, name='app', debug=False, strip=None, upx=True, console=True ) Here is the program file #!/usr/bin/python from pysnmp.entity.rfc3413.oneliner import cmdgen from pysnmp.smi import builder from pysnmp import debug import sys import