I've searched the archives for a solution to this, but haven't found it.
So I have an SNMP sub-agnet that talkes to master agentx over the agentx socket.
Also, cannot block on this process waiting for snmp requests. So I use select
to timeout in order to kick a watchdog.
When the snmpd restart the socket fd which I watch for select is invalid. I
assume I need to restart the subagent. When I do I get a bazillion handler
re-registration errors.
Of course the subagent handler code was created from a mib2c process, and that
script doesn't generate code to de-register the handlers. So I'm also looking
into how to handle that.
Finally, when the subagent is killed off and restarted, snmpwalk of the MIB
fails, like the subagent isn't running.
Here's the code I have right now. The reinit call basically executes the
shutdown code, and re-runs the startup code.
Code included below.
TIA,
Eldon.
void SnmpSubagent::run()
{
fd_set fds;
struct timeval timeout, tv;
int rc, numfds=0, block=1, numsocks;
// Configure snmp logging
int use_syslog = false;
if (use_syslog)
{
snmp_enable_calllog(); // syslog
}
else
{
snmp_enable_stderrlog(); // stdout
}
snmp_log(LOG_DEBUG, "Starting the SNMP Subagent...\n");
// Become Subagent
if (netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_ROLE, 1) != SNMPERR_SUCCESS)
{
mpLog->logf(Log::ERROR,"SnmpSubagent::run() - Error setting
AppID::Agent Role=1");
}
// Now register with the master Agent X process
// Set AgentX socket interface
if (netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_X_SOCKET,
NETSNMP_AGENTX_SOCKET) != SNMPERR_SUCCESS)
{
mpLog->logf(Log::ERROR,"SnmpSubagent::run() - Error setting
AppID::AgentX Socket");
}
// Initialize the agent
if (init_agent("mp") != SNMPERR_SUCCESS)
{
mpLog->logf(Log::ERROR,"SnmpSubagent::run() - Error initializing the
agent");
}
// Register callback functions ...
init_ssiSbssMIB();
init_snmp("mp");
snmp_log(LOG_INFO, "SBSS Radio Snmp Subagent started.\n");
// Sent the App Startup notification
send_sbssNotifAppStartup_trap();
// main loop here...
while(1)
{
tv.tv_sec = period;
numsocks = snmp_select_info(&numfds, &fds, &timeout, &block);
if (numsocks)
{
rc = select(numfds+1, &fds, NULL, NULL, &tv);
if (rc == -1)
{
mpLog->logf(Log::ERROR, "SnmpSubagent::run() Select error");
numfds = 0;
FD_ZERO(&fds);
reinit();
}
else if (rc == 0)
{
WDT::Instance()->Kick(tid, pthread_self());
clock_gettime(CLOCK_MONOTONIC, (timespec *)&timeout);
timeout.tv_usec = 0;
timeout.tv_sec += period;
}
else
{
WDT::Instance()->Kick(tid, pthread_self());
agent_check_and_process(0);
}
}
else
{
mpLog->logf(Log::ERROR, "SnmpSubagent::run() No open SNMP sockets.
Resetting SNMP connection.");
reinit();
}
}
// at shutdown time (never happens....)
send_sbssNotifAppShutdown_trap();
snmp_log(LOG_ERR, "SBSS Radio Snmp Subagent shutting down.\n");
snmp_shutdown("mp"); //TODO-khs: tie this into the project's properties
somehow...also maybe change it to "sbssmp"...
}
oid SnmpSubagent::reinit()
{
snmp_shutdown("mp");
// Re-configure snmp logging
int use_syslog = false;
if (use_syslog)
{
snmp_enable_calllog(); // syslog
}
else
{
snmp_enable_stderrlog(); // stdout
}
snmp_log(LOG_DEBUG, "Starting the SNMP Subagent...\n");
// Become Subagent
if (netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_ROLE, 1) != SNMPERR_SUCCESS)
{
mpLog->logf(Log::ERROR,"SnmpSubagent::run() - Error setting
AppID::Agent Role=1");
}
// Now register with the master Agent X process
// Set AgentX socket interface
if (netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
NETSNMP_DS_AGENT_X_SOCKET,
NETSNMP_AGENTX_SOCKET) != SNMPERR_SUCCESS)
{
mpLog->logf(Log::ERROR,"SnmpSubagent::run() - Error setting
AppID::AgentX Socket");
}
// Initialize the agent
if (init_agent("mp") != SNMPERR_SUCCESS)
{
mpLog->logf(Log::ERROR,"SnmpSubagent::run() - Error initializing the
agent");
}
// Register callback functions ...
init_ssiSbssMIB();
init_snmp("mp");
snmp_log(LOG_INFO, "SBSS Radio Snmp Subagent started.\n");
// Sent the App Startup notification
send_sbssNotifAppStartup_trap();
}
------------------------------------------------------------------------------
Free Software Download: Index, Search & Analyze Logs and other IT data in
Real-Time with Splunk. Collect, index and harness all the fast moving IT data
generated by your applications, servers and devices whether physical, virtual
or in the cloud. Deliver compliance at lower cost and gain new business
insights. http://p.sf.net/sfu/splunk-dev2dev
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users