Reputation: 5
I'm not an snmp expert; I just started some weeks ago in my leisure time to implement a new function in a system of the company.
I copy pasted an answer I found here
from pysnmp.hlapi import *
from pysnmp import debug
debug.setLogger(debug.Debug('msgproc'))
next(sendNotification(SnmpEngine(),
CommunityData('public'),
UdpTransportTarget(('192.168.1.92',162)),
ContextData(),
'trap',
[ObjectType(ObjectIdentity('1.3.6.1.2.7.8'), Integer32(5)),
ObjectType(ObjectIdentity('1.3.6.6.7'),Integer32(45))]
)
)
My receiver catch 4 varbinds not just 2 like I specified and the debug shows the next
2017-03-24 09:07:53,015 pysnmp: running pysnmp version 4.3.4
2017-03-24 09:07:53,016 pysnmp: debug category 'msgproc' enabled
2017-03-24 09:07:54,115 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.AccessAllowed object at 0x762eb170>}
2017-03-24 09:07:54,116 pysnmp: StatusInformation: {'errorIndication': <pysnmp.proto.errind.AccessAllowed object at 0x762eb170>}
2017-03-24 09:07:54,120 pysnmp: prepareOutgoingMessage: using contextEngineId SnmpEngineID() contextName b''
2017-03-24 09:07:54,123 pysnmp: generateRequestMsg: Message:
version=1
community=public
data=PDUs:
snmpV2-trap=SNMPv2TrapPDU:
request-id=10292983
error-status='noError'
error-index=0
variable-bindings=VarBindList:
VarBind:
name=1.3.6.1.2.1.1.3.0
=_BindValue:
value=ObjectSyntax:
application-wide=ApplicationSyntax:
timeticks-value=0
VarBind:
name=1.3.6.1.6.3.1.1.4.1.0
=_BindValue:
value=ObjectSyntax:
simple=SimpleSyntax:
objectID-value=1.3.6.1.6.3.1.1.5.1
VarBind:
name=1.3.6.1.2.7.8
=_BindValue:
value=ObjectSyntax:
simple=SimpleSyntax:
integer-value=5
VarBind:
name=1.3.6.6.7
=_BindValue:
value=ObjectSyntax:
simple=SimpleSyntax:
integer-value=45
The problem I have is that I don't really know what are the meaning of the first two OIDS.
**1.3.6.1.2.1.1.3.0 = 0
1.3.6.1.6.3.1.1.4.1.0 = 1.3.6.1.6.3.1.1.5.1**
1.3.6.1.2.7.8 = 5
1.3.6.6.7 = 45
looking out seems like they are a OID from the snmpv2-mib but I'm not sure.
Upvotes: 0
Views: 991
Reputation: 5555
So, you are sending a SNMPv2 TRAP (CommunityData(mpModel=1) implies). According to the chapter 4.2.6 of RFC1905:
The first two variable bindings in the variable binding list of an SNMPv2-Trap-PDU are sysUpTime.0 and snmpTrapOID.0 respectively.
Since you have not supplied those yourself, pysnmp adds them automatically to produce a well-formed PDU.
Note that, depending on the ID of TRAP you are sending, pysnmp may attempt to find and attach more OID-value pairs to the var-binds as RFC mandates:
If the OBJECTS clause is present in the invocation of the corresponding NOTIFICATION-TYPE macro, then each corresponding variable, as instantiated by this notification, is copied, in order, to the variable-bindings field.
You can pass a lookup map ("objects" parameter) to initialize those OBJECTS OIDs. Otherwise pysnmp will search them in its local MIB.
Finally, the OIDs you are explicitly passing belong to this part of the RFC:
If any additional variables are being included (at the option of the generating SNMPv2 entity), then each is copied to the variable-bindings field.
Upvotes: 1