markabrahams / node-net-snmp

JavaScript implementation of the Simple Network Management Protocol (SNMP)
209 stars 97 forks source link

Question: guidance on building a callback-driven agent #243

Closed thom-nic closed 5 months ago

thom-nic commented 9 months ago

I have an existing application that implements an agent with about 130 OIDs including 3 tables. It is implemented using snmpjs (this app is ~7 years old.) The snmpjs API is essentially all callback-driven by registering handlers for OIDs to handle Get/Set/GetNext. It is of course only v1 & v2c. I'm trying to gauge effort to port my handlers to net-snmp, mainly to take advantage of SNMPv3 support.

From what I understand, to achieve the same in net-snmp, I would create an agent, import and set my MIB, then use mib.registerProvider() to register providers for each OID with a handler property to handle each incoming request on the fly. Is this roughly correct?

My tables are read-mostly and also dynamic and table data changes over time based on the state of the system (both presence of rows and data in the rows.) Values have potential to change every few seconds. The documentation covers the methods to get and set row and column data, but can I also handle requests for tabular OIDs on the fly rather than "pushing" the data into the MIB? The data changes frequently, especially compared to the frequency of SNMP requests. So calculating responses on the fly via callbacks is relatively cheap compared to, say, updating table data every time some value changes in the system.

So again, looking for overall advice as to whether a callback-driven implementation will work with net-snmp or if it is not compatible or works against the spirit of how this library is designed. Thanks in advance, and I apologize for posting a "help" question here. I don't see a dedicated forum or better place help style questions.

markabrahams commented 9 months ago

Hi @thom-nic - your custom handler function can do arbitrary processing whenever the agent processes a Get/Set/GetNext request, but agent calls the handler function after it first finds an existing MIB object - the given OID(s) for Get/Set or the next one(s) in the MIB tree for GetNext (or series of these for GetBulk). It sounds like net-snmp could at the very least partially meet your requirements, but, if I've understood correctly, you might be after a little more control than this library provides - for example you can't replace the library's default and mandatory GetNext's OID selection mechanism with your own handler to manage the whole GetNext operation, and so your MIB would require at least some measure of pre-population for the agent to find any OIDs for incoming requests.

thom-nic commented 9 months ago

can't replace the library's default and mandatory GetNext's OID selection mechanism with your own handler to manage the whole GetNext operation, and so your MIB would require at least some measure of pre-population for the agent to find any OIDs for incoming requests.

Yes that would be a change from how we operate today. Today, snmpjs lets us choose the next instance to send back during a GetNext request. That being the case, adding and removing rows occurs much less frequently, so it seems reasonable that we could make calls to add and remove table rows when those instances come and go in the system. But we would still use callback-style handlers for the Get and Set calls to columns in those rows, yes?

Mark are you potentially available for paid consulting? Not for the implementation work but for priority support, troubleshooting and implementation questions assuming we move forward on this migration effort. If yes, I could send an email to the address on your profile.

markabrahams commented 9 months ago

Hi @thom-nic - yes, if you are able to keep the number of rows accurate in each table, that would ensure the correct OIDs are always always found for Get/GetNext, etc. protocol operations. You could then use the handler functions to update the MIB values as these are accessed via the protocol operations.

Yes, feel free to email me about consulting for your project.