Skip to content Skip to sidebar Skip to footer

Sending Snmp Traps Containing Custom Data

A client has requested that instead of email alerts that we send SNMP Traps to their Nagios server instead. The only thing I knew about SNMP before yesterday was that it sounded li

Solution 1:

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.

Solution 2:

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))]))

Post a Comment for "Sending Snmp Traps Containing Custom Data"