-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
implement send_trap() #22
base: master
Are you sure you want to change the base?
Conversation
extract from _prepareRegistration() to separate function _prepareOID() which returns tuple of (c_oid) oid and (size_t) oid_len The code is improved by trimming trailing zeroes from the oid array
depending on function arguments it is possible to send all types of traps actually tested v1 and v2c traps, informs are received too When sending traps with Counter64 there is warning issued by net-snmp: send_trap: v1 traps can't carry Counter64 varbinds send_trap: failed to convert v2->v1 template PDU In this case snmptrapd receives the trap only on trap2sink and informsink interfaces
Looks very interesting, I'll have to take a closer look this weekend :) Once I close #20, I'll prepare a new 0.5.1 stable release. |
I just spot small bug in the init of snmp_pdu class: def __init__(self, pduType = SNMP_MSG_TRAP2):
"""create PDU object """
self.pdu = libnsX.snmp_pdu_create(SNMP_MSG_TRAP2) I am not passing pduType variable to snmp_pdu_create() function usiing hardcoded value instead. It is not important because I use the PDU structure as temporary container where snmp_add_var() function is doing its magic to pdu.variables. Everything other is not used at all so it does not matter actually. |
sync fork with parent
sync sendTrap branch with master
Are there any issues blocking this pull request from being merged? |
Please note that this PR is still on my to-do list. |
@atodorov-storpool Can you please merge master in your branch? are your commits stable.. can I use it? |
@sewashinobi merged. They are working for me, sure you can try using them :) |
@sewashinobi Does it work for you too, then? |
Sorry for delayed response
Although there is some discussion about it in netsnmp mailing list, FYI.. I have configured snmpd for only v2c, and there is only one trap and that is configured as follows.. not sure then why this warning is coming..
Netsnmp Version ( Ubuntu)
|
@atodorov-storpool I have trap running in production and looks good, but sometime there is race condition and same trap is getting send twice.. from the log I am sure that my agentx is calling it only once.. in my implementation, the trap function is running in separate thread and in the main thread I have called the check_and_process.. Once I bombard approx 20 traps then few traps are coming twice.. I looked in your code but couldn't find the issue.. Appreciate if you can spot something |
@atodorov-storpool digged a little more for duplicate trap issue, it is happening when the data update and trap both happen same time ( In production it is very much possible that get request and trap both happen at same time, correct me if this shouldn't be the case ) |
@atodorov-storpool any suggestion, I tried to debug in your implementation but no luck. This happens when the data update and traps are happening in parallel. |
@atodorov-storpool you code doesn't work with Python 3, this part has problem. The c_char expects bytes, I tried to encode but then trap has corrupted data.
I fixed following as has_key is not supported
While not able to figure out the c_char solution, Will you be able to help? |
I was able to fix it with encode, earlier I was trying the ctypes.c_wchar, ctypes.c_wchar_p which was giving unexpected results. ret = libnsX.snmp_add_var( |
This no longer works, because in Net-SNMP v 5.8 and up, there is additional field |
Hello,
I choose your library to implement snmp agent for our company project. It is working fine but there was need to implement functionality to send traps. I am beginner Python developer and it took some time to figure out your code flow and how to add sending trap functionality how to glue python ctypes to libnetsnmp. I do not use your code for defining ASN types because I found net-snmp function that is used in sendtrap tool for creating the needed varbind list for send_trap(). You can find some example scripts for using it. The traps that are received by snmptrapd ara passed to simple shell handler for logging to syslog - I do not found a way to log on console because the handler is started by snmptrapd.
I see in your TODO list that such functionality is planned and I hope the code will help to faster extend your library.
Best Regards,
Anton Todorov
ps. Please bump the pip package - I can confirm the recent commit in master about the string handling are working but pip is not updated.