本文整理汇总了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变量)