big change n parsing logic passing

This commit is contained in:
Rafael.Timmerberg 2013-06-18 00:10:14 +02:00
commit 127dacd778
17 changed files with 570 additions and 127 deletions

View file

@ -2,45 +2,56 @@
The snmpget service in pure Python.
"""
from pysnmp.entity.rfc3413.oneliner import cmdgen
#from pysnmp.entity.rfc3413.oneliner import cmdgen
from service import Service
from Cython.Compiler.Naming import kwds_cname
from wx.lib.pubsub.core import kwargs
class SnmpgetService(Service):
def __init__(self, parser, log, **kwargs):
super(Service, self).__init__(parser)
if "community" in kwargs:
self.community = kwargs["community"]
def __init__(self, **kwargs):
super(SnmpgetService, self).__init__(**kwargs)
args = self.get_arguments()
if "community" in args:
self.community = args["community"]
else:
log.w("There is no community")
raise
if "oid" in kwargs:
self.oid = kwargs["oid"]
raise Exception("There is no community")
if "oid" in args:
self.oid = args["oid"]
else:
log.w("There is no oid")
raise
if "port" in kwargs:
self.port = kwargs["port"]
else:
self.port = "161"
raise Exception("There is no oid")
self.port = "161"
if "port" in args:
self.port = args["port"]
def needs_arguments(self):
return True
def execute(self):
cmdGen = cmdgen.CommandGenerator()
pass
#cmdGen = cmdgen.CommandGenerator()
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
cmdgen.CommunityData(self.community),
cmdgen.UdpTransportTarget((self.host, self.port)),
cmdgen.MibVariable(self.oid)
)
if errorIndication:
print(errorIndication)
else:
if errorStatus:
print('%s at %s' % (
errorStatus.prettyPrint(),
errorIndex and varBinds[int(errorIndex) - 1] or '?'
))
else:
for name, val in varBinds:
print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
#errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
# cmdgen.CommunityData(self.community),
# cmdgen.UdpTransportTarget((self._host, self.port)),
# cmdgen.MibVariable(self.oid)
#)
#if errorIndication:
# print(errorIndication)
#else:
# if errorStatus:
# print('%s at %s' % (
# errorStatus.prettyPrint(),
# errorIndex and varBinds[int(errorIndex) - 1] or '?'
# ))
# else:
# for name, val in varBinds:
# print('%s = %s' % (name.prettyPrint(), val.prettyPrint()))
def create(**kargs):
return SnmpgetService(**kwargs)