1 Star 0 Fork 46

Omiga/qytang_Python

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
2016.03.26 snmp trap 1.41 KB
一键复制 编辑 原始数据 按行查看 历史
现任明教教主-乾颐堂 提交于 2016-03-26 21:26 . new file
from pysnmp.carrier.asynsock.dgram import udp
from pysnmp.entity.rfc3413 import ntforg, context
from pysnmp.proto.api import v2c
from pysnmp.entity import engine
from pysnmp.entity import config
snmpEngine = engine.SnmpEngine()
config.addV1System(snmpEngine, 'my-area', 'public')
config.addTargetParams(snmpEngine, 'my-creds', 'my-area', 'noAuthNoPriv', 1)
config.addSocketTransport(
snmpEngine,
udp.domainName,
udp.UdpSocketTransport().openClientMode()
)
config.addTargetAddr(
snmpEngine, 'my-nms',
udp.domainName, ('192.168.1.3', 162),
'my-creds',
tagList = 'all-my-managers'
)
config.addNotificationTarget(
snmpEngine, 'my-notification', 'my-filter', 'all-my-managers', 'inform'
)
config.addContext(snmpEngine, '')
config.addVacmUser(snmpEngine, 2, 'my-area', 'noAuthNoPriv', (), (), (1,3,6))
snmpContext = context.SnmpContext(snmpEngine)
ntfOrg = ntforg.NotificationOriginator(snmpContext)
def cbFun(sendRequestHandle, errorIndication, dbCtx):
print('Notification %s, status - %s' % (
sendRequestHandle, errorIndication and errorIndication or 'delivered'
)
)
sendRequestHandle = ntfOrg.sendNotification(
snmpEngine,
'my-notification',
(1,3,6,1,6,3,1,1,5,1),
(((1,3,6,1,2,1,1,1,0),v2c.OctetString('Example Notificator')),
((1,3,6,1,2,1,1,5,0),v2c.OctetString('Notificator Example'))),
cbFun
)
print('Notification %s scheduled to be sent ' % sendRequestHandle)
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/zuoguocai/qytang_Python.git
git@gitee.com:zuoguocai/qytang_Python.git
zuoguocai
qytang_Python
qytang_Python
master

搜索帮助