本文整理匯總了Python中pysnmp.proto.rfc1902.OctetString方法的典型用法代碼示例。如果您正苦於以下問題:Python rfc1902.OctetString方法的具體用法?Python rfc1902.OctetString怎麽用?Python rfc1902.OctetString使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pysnmp.proto.rfc1902
的用法示例。
在下文中一共展示了rfc1902.OctetString方法的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: parse
# 需要導入模塊: from pysnmp.proto import rfc1902 [as 別名]
# 或者: from pysnmp.proto.rfc1902 import OctetString [as 別名]
def parse(self, line):
filters = {
'OctetString': self._stringFilter
}
try:
oid, tag, value = [x.strip() for x in octs2str(line).split(',', 2)]
except Exception as exc:
raise error.SnmpsimError(
'broken record <%s>: %s' % (line, exc))
else:
if oid and tag:
handler = filters.get(tag, lambda x: x)
return oid, tag, handler(value.strip())
raise error.SnmpsimError('broken record <%s>' % line)
示例2: probe_context
# 需要導入模塊: from pysnmp.proto import rfc1902 [as 別名]
# 或者: from pysnmp.proto.rfc1902 import OctetString [as 別名]
def probe_context(transport_domain, transport_address,
context_engine_id, context_name):
"""Suggest variations of context name based on request data
"""
if context_engine_id:
candidate = [
context_engine_id, context_name, '.'.join(
[str(x) for x in transport_domain])]
else:
# try legacy layout w/o contextEngineId in the path
candidate = [
context_name, '.'.join(
[str(x) for x in transport_domain])]
if transport_domain[:len(udp.domainName)] == udp.domainName:
candidate.append(transport_address[0])
elif udp6 and transport_domain[:len(udp6.domainName)] == udp6.domainName:
candidate.append(str(transport_address[0]).replace(':', '_'))
elif unix and transport_domain[:len(unix.domainName)] == unix.domainName:
candidate.append(transport_address)
candidate = [str(x) for x in candidate if x]
while candidate:
yield rfc1902.OctetString(
os.path.normpath(
os.path.sep.join(candidate)).replace(os.path.sep, '/')).asOctets()
del candidate[-1]
# try legacy layout w/o contextEngineId in the path
if context_engine_id:
for candidate in probe_context(
transport_domain, transport_address, None, context_name):
yield candidate
示例3: hexify_value
# 需要導入模塊: from pysnmp.proto import rfc1902 [as 別名]
# 或者: from pysnmp.proto.rfc1902 import OctetString [as 別名]
def hexify_value(self, value):
if value.tagSet in (univ.OctetString.tagSet,
rfc1902.Opaque.tagSet,
rfc1902.IpAddress.tagSet):
nval = value.asNumbers()
for x in nval:
if (value.tagSet == rfc1902.IpAddress.tagSet or
x not in self.ALNUMS):
return ''.join(['%.2x' % x for x in nval])
示例4: add_data_file
# 需要導入模塊: from pysnmp.proto import rfc1902 [as 別名]
# 或者: from pysnmp.proto.rfc1902 import OctetString [as 別名]
def add_data_file(self, *args):
for idx in range(len(args)):
self._db[
self._index_oid + (idx + 1, self._idx)
] = rfc1902.OctetString(args[idx])
self._idx += 1
示例5: set_snmp_single
# 需要導入模塊: from pysnmp.proto import rfc1902 [as 別名]
# 或者: from pysnmp.proto.rfc1902 import OctetString [as 別名]
def set_snmp_single(rwstring, ip_address, ifAlias, description):
from pysnmp.entity.rfc3413.oneliner import cmdgen
from pysnmp.proto import rfc1902
cmdGen = cmdgen.CommandGenerator()
cmdGen.setCmd(
cmdgen.CommunityData(rwstring),
cmdgen.UdpTransportTarget((ip_address, 161)),
(ifAlias, rfc1902.OctetString(description)))
示例6: checkoctetstring
# 需要導入模塊: from pysnmp.proto import rfc1902 [as 別名]
# 或者: from pysnmp.proto.rfc1902 import OctetString [as 別名]
def checkoctetstring(val):
"""
Check for OctetString
Arguments:
1.val: pysnmp object
:return: True or False
"""
if isinstance(val, OctetString):
return True
else:
return False
##TRAP Listner related method
## This will support SNMP v1 v2 V3 Trap and Inform as well
示例7: add_user
# 需要導入模塊: from pysnmp.proto import rfc1902 [as 別名]
# 或者: from pysnmp.proto.rfc1902 import OctetString [as 別名]
def add_user(cls, port, username, securityengineid,
authkey=None, privkey=None,
authProtocol=None, privProtocol=None):
"""
Add SNMP V3 User
:param port: SNMP Trap Port
:param username: SNMP User name
:param securityengineid: SNMP Engine id in Hex form
:param authkey: SNMP Authkey default is None
:param privkey: SNMP Privkey string default is None
:param authProtocol: Auth Protocol, default is None
:param privProtocol: Privacy Protocol, default is None
:return: Treu or False
"""
result = True
snmpEngine = cls.get_asyncoredispatcher(port)
# debug.setLogger(debug.Debug('all'))
try:
authprotocol = cls.authProtocol.get(authProtocol, None)
privprotocol = cls.authProtocol.get(privProtocol, None)
config.addV3User(
snmpEngine=snmpEngine, userName=username,
authProtocol=authprotocol, authKey=authkey,
privProtocol=privprotocol, privKey=privkey,
securityEngineId=v2c.OctetString(hexValue=securityengineid)
)
except:
testcase_Utils.pNote("ADD SNMPv3 User Failed", "error")
result = False
return result
示例8:
# 需要導入模塊: from pysnmp.proto import rfc1902 [as 別名]
# 或者: from pysnmp.proto.rfc1902 import OctetString [as 別名]
def ft自動(a綁定變量):
"""自動轉換成python內置類型"""
v變量 = a綁定變量[1]
v類型 = type(v變量)
if v類型 in (類型.OctetString, 類型.OctetString): #字符串
return str(v變量)
elif v類型 in (類型.Integer, 類型.Integer32, 類型.Counter32, 類型.Counter64, 類型.Unsigned32, 類型.Gauge32): #整數
return int(v變量)
elif v類型 == 類型.Null: #空
return None
else: #默認處理
return str(v變量)