What I want is to send snmp traps just as the way that one of our network equipment do. The trap contains a name-value of DataTime and it's something like HEX String.
e.g. 1.3.6.1.4.1.193.82.1.8.1.4.0 : 07:de:07:10:0a:0c:1e:00:2b:08:00
When I use snmptrap
command of the net-snmp
to send the trap, our Trap decoder can successfully parse the hex string to dateandtime
format(YYYY-MM-HH hh:mm:ss
) just like that it got a real trap from our Network equipment.
The command I use is like this:
sudo /usr/local/net-snmp/bin/snmptrap -v 2c -c LI_OSS 10.184.74.66:162 "" 1.3.6.1.4.1.193.82.2.0.1 1.3.6.1.4.1.193.82.1.8.1.4.0 x "07de07100a0c1e002b0800"
x
means that the string "07de07100a0c1e002b0800
" is some kind of hex format.
When I try to use pysnmp to send complete the same task, our Trap decoder program do have received the trap but fail to parse the dateandtime. Here is the code that I use to send the trap, it's the official example of pysnmp, here.
I only modified the host and below part:
ntfOrg.sendNotification(
snmpEngine,
# Notification targets
'my-notification',
# Trap OID (SNMPv2-MIB::coldStart)
(1,3,6,1,4,1,193,82,2,0,1),
# ( (oid, value), ... )
(
('1.3.6.1.4.1.193.82.1.8.1.4.0', rfc1902.OctetString('07de07100a0c1e002b0800'))
)
)
In order to figure out the differences, I captured the packages of sending traps that using snmptrap
and pysnmp
using WireShark, and here are the differences. Note that I am not using the same TRAP OID, but the phenomenon remain the same.
The first picture is that using snmptrap to send the trap, the other one is when using pysnmp.
The Octet Strings are just different.
Is anyone know why this happened? And how can I make it work to use pysnmp to send the trap in my situation? Thanks a lot in advance!