0

I have embedded a net-snmp agentx subagent in my c++ application code on Ubuntu Linux. I want to disable the agentx subagent once it is working and then re-enable it again. I am successfully able to setup the agent, poll the mib using snmpget from the command line and disable agentx socket connection by using snmp_shutdown but I am unable to re-enable the socket connection again once I disable it.

Appreciate any help/pointers.

I use the following code to initialise the SNMP library and the agentx socket connection.

In the beginning, initialise the AgentX subagent -

netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
        netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL, 120);
        netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_X_SOCKET, m_agentx_socket.c_str());


/* initialize the agent library */
init_agent("MyApp");
// initialise MIB module
init_snmp("MyApp");

The poll the MIB using snmpget and disable the connection using the function below -

snmp_shutdown("MyApp");
SOCK_CLEANUP;

Works fine so far.

Then I re-enable the connection using the code below but this does not work.

netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
        netsnmp_ds_set_int(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_AGENTX_PING_INTERVAL, 120);
        netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_X_SOCKET, m_agentx_socket.c_str());


/* initialize the agent library */
init_agent("MyApp");
init_snmp("MyApp");
John Qualis
  • 1,663
  • 4
  • 33
  • 52

2 Answers2

0

I think you have to re-run binary itself after it got shut down. You have not clarified here why you want to restart agentx. if you are doing this for fetching some data frequently. than I guess you can try infinite for loop with sleep command of a time span in your code. this will be better option.

jatin bodarya
  • 72
  • 3
  • 8
0

I found the following information in the README.agentx file from net-snmp-5.7.2 (currently visible at http://www.net-snmp.org/docs/README.agentx.html :

Similarly, a subagent will not be able to re-register in place of a defunct colleague until the master agent has received three requests for the dead connection (and hence unregistered it).

It seems likely, therefore, that the master still has your subagent registered despite your attempt at a clean shutdown. Perhaps you could try making three or more requests while your subagent is disabled and then proceeding with your re-registration.