im trying to send traps over snmpv3, this is my first attempt:
#!/usr/bin/python
from pysnmp.hlapi import *
TARGET="localhost"
TARGET_PORT=162
COMMUNITY_STR="PASSWORD"
IDENTIFIER="1.3.6.1.2.1.xxx"
USER="trapadm"
KEY="PASSWORD"
# OID NODE : MESSAGE
values = { ".100.5": "LOL",
".100.6": "ROFL",
}
def notification(
NODE,
MESSAGE,
TARGET=TARGET,
TARGET_PORT=TARGET_PORT,
#COMMUNITY_STR=COMMUNITY_STR,
IDENTIFIER=IDENTIFIER
):
errorIndication, errorStatus, errorIndex, varBinds = next(
sendNotification(
SnmpEngine(),
UsmUserData(userName=USER, privKey=KEY, authKey=KEY
#authProtocol=usmHMACMD5AuthProtocol,
#privProtocol=usmDESPrivProtocol
#authProtocol=(1, 3, 6, 1, 6, 3, 10, 1, 1, 2),
#privProtocol= (1, 3, 6, 1, 6, 3, 10, 1, 2, 2)
),
#CommunityData(COMMUNITY_STR, mpModel=0),
UdpTransportTarget((TARGET, TARGET_PORT)),
ContextData(),
'trap',
NotificationType(
ObjectIdentity(IDENTIFIER)
).addVarBinds(
(IDENTIFIER+NODE, OctetString(MESSAGE)))
)
)
if errorIndication:
print(errorIndication)
CASE = True
def main():
for key in values:
if CASE is True:
notification(key, values[key])
if __name__ == '__main__':
main()
I have tested the functionality of my trap receiver with the following command (which worked right away)
snmptrap -Ci -v 3 -a MD5 -A PASSWORD -x DES -X PASSWORD -l authPriv -u trapadm localhost 0 linkUp.0
Now with the python script above, i can see via tcpdump, that it was sended, but it does not appear in the trapd logfile. i suspect that it depends somehow on auth-/privProtocol. Btw the commented lines (auth-/privProtocol). were tested, too.
Anyone ideas here?