Sending SNMP Traps containing custom data

孤人 提交于 2019-12-01 19:50:37

On a purely technical level you could use any OID for any purpose. However, SNMP was designed to be a committee-managed protocol.

If your traps or their varbinds do not conform to standard messages/types your OIDs should begin with 1.3.6.1.4.1.YOUR_ENTERPRISE_NUMBER. If your company or your client do not have a registered Private Enterprise Number (PEN) you can request one from IANA without charge. If someone is managing your PEN you should ask them for an OID for your product domain.

The PEN list is full of individual's email addresses. There is an element of industry-level trust in this system. It is not unusual to work with someone who controls the enterprise number of a competitor. If you assume responsibility for a PEN then you assume the ethical responsibilities that go with it.

You do not have to write or publish MIBs for enterprise ranges though you may want to author them for your client's benefit.

SNMP is an old protocol. The preferred replacement is NETCONF, or so I am told.

In general, SNMP trap contents is well structured to facilitate data exchange between random systems. The contents is defined by MIB in a quite cumbersome way. However, if you are building an ad-hoc, custom system, nothing stops you from stuffing whatever OID-values into a trap.

Example code (with debugging enabled to give you a hint what is being sent out):

from pysnmp.hlapi import *
from pysnmp import debug

debug.setLogger(debug.Debug('msgproc'))

next(sendNotification(SnmpEngine(),
     CommunityData('public'),
     UdpTransportTarget(('demo.snmplabs.com', 162)),
     ContextData(),
     'trap',
     # sequence of custom OID-value pairs
     [ObjectType(ObjectIdentity('1.3.6.1.2.1.1.1.0'), OctetString('my string')),
      ObjectType(ObjectIdentity('1.3.6.1.2.1.1.3.0'), Integer32(42))]))
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!