04 Aug 2023 04:19 PM
Hi Folks,
We have recently added SNMP extension to the monitoring and during testing we received some traps.
Now, we wanted to test it again however, it would be difficult for SNMP team to send the traps again just for testing.
Hence I'm looking out a way to send to traps via Dynatrace API.
Has anyone successfully ingested a SNMP traps to Dynatrace. Can someone please suggest.
This is how trap looks when sent to Dynatrace,
Regards,
AK
Solved! Go to Solution.
08 Aug 2023 12:01 AM
@AK,
I have a client where we have managed to ingest more than 10K traps per minute. And it works pretty well.
If you want to inject traps into Dynatrace, I would suggest using pysnmp. Something like the following:
from pysnmp.hlapi import *
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(
SnmpEngine(),
CommunityData('public', mpModel=1),
UdpTransportTarget(('receiver_ip', 162)),
ContextData(),
'trap',
NotificationType(ObjectIdentity('SNMPv2-MIB', 'linkDown')),
('1.3.6.1.2.1.2.2.1.2.1', OctetString('Interface eth0 is down')),
)
)
14 Aug 2023 08:43 AM - edited 14 Aug 2023 08:44 AM
@AntonioSousa, thank you for the response.
What prep work I need do to post it? like, anything I need to install on my local system (e.g.-python)?
I never did anything like this before.
I was successfully able to post dummy log via log monitoring API with the static content however, "Device Statistics" graphs are not populating, see the screengrab below.
I just wanted to post it one time for testing, this is my use case.
Regards,
AK
14 Aug 2023 10:15 AM
@AK,
If you have Linux, most certainly python is preinstalled. If you have Windows, you would have to install it.
I tried this on an out of the box Linux machine, and it did not work immediately. So here's what you need to do:
from pysnmp.hlapi import *
receiver_ip = '192.168.1.232'
trap_oid = '1.3.6.1.4.1.12345.1.0'
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(
SnmpEngine(),
CommunityData('public', mpModel=0),
UdpTransportTarget((receiver_ip, 162)),
ContextData(),
'trap',
NotificationType(ObjectIdentity(trap_oid)),
)
)