Sudip
Sudip

Reputation: 583

Warning: Failed to connect to the agentx master agent ([NIL])

I have installed net-snmp5.7.2 on my system, I have written my app_agent.conf for my application and

agentXSocket    udp:X.X.X.X:1610

and exported SNMPCONFIGPATH=path_to_app_agent.conf

I have also wrtten snmpd.conf in /usr/etc/snmp/snmp.conf

trap2sink  X.X.X.Y 
agentXSocket    udp:X.X.X.X:1610

I have two more snmpd.conf present in my /etc/snmp/ and /var/net-snmp/

Config from /etc/snmp:

com2sec notConfigUser  default       public
com2sec notConfigUser  v1            notConfigUser
com2sec notConfigUser  v1            notConfigUser
view    systemview    included   .1.3.6.1.2.1.1
view    systemview    included   .1.3.6.1.2.1.25.1.1
access notConfigGroup "" any noauth exact systemview none none 
pass .1.3.6.1.4.1.4413.4.1 /usr/bin/ucd5820stat

Config from /var/net-snmp:

   setserialno 1322276014
   ifXTable .1 14:0 18:0x $
   ifXTable .2 14:0 18:0x $
   ifXTable .3 14:0 18:0x $
   engineBoots 14
   oldEngineID 0x80001f888000e17f6964b28450

I have started snmpd and snmptrapd. Now in my code I am calling

netsnmp_ds_set_boolean(NETSNMP_DS_APPLICATION_ID, NETSNMP_DS_AGENT_ROLE, 1);
init_agent("app_agent");
init_snmp("app_agent");

init_snmp is throwing a warning

Warning: Failed to connect to the agentx master agent ([NIL]):

I have no idea why?? Thanks in advance for any help

Upvotes: 5

Views: 29793

Answers (6)

Ivan Plascencia
Ivan Plascencia

Reputation: 151

This is not the answer to your problem, but I too got "Warning: Failed to connect to the agentx master agent ([NIL]):" message when my snmpd service didn't startup properly or went down. For my SNMP Sub-Agent, I used the example they provide, example-demon.c, and found I get this message nonstop (about every second) when processing agent_check_and_process(0) on every loop.

while (true) {
    agent_check_and_process(0); /* 0 == don't block */
}

This is how I fixed it.

netsnmp_transport *snmpTransport;
while( true ) {
        // Check to see snmpd is still running
        snmpTransport = netsnmp_transport_open_client("agentx", NULL);
        if (snmpTransport == NULL)
        {
            // Just went down?
            if (snmpAgentDown == false)
            {
                snmp_log( LOG_INFO, "Net-SNMP Agent is down\n" );
                snmpAgentDown = true;
            }

            Sleep(5000); // Sleep for a 5 sec
        } else
        {
            if (snmpAgentDown)
            {
                snmp_log( LOG_INFO, "Net-SNMP Agent is back up\n" );
                snmpAgentDown = false;
            }

            // Close connection test
            snmpTransport->f_close(snmpTransport); // This burn me without; its needed
            netsnmp_transport_free(snmpTransport);

            // Process SNMP request and notifications
            agent_check_and_process( 0 ); // 0 == don't block, 1 = block
            Sleep(1); // Sleep for 1ms; Need to sleep thread, but need subAgent to be responsive too
        }
        i++;
    }

Now if the snmpd goes down, my app can detect it being down and not process agent_check_and_process() stopping the "Warning: Failed to connect to the agentx master agent ([NIL]):" from ever appearing. If snmpd comes back up, then it processes it.

Final Note: I determine that code based off subagent.c file subagent_open_master_session() funtion in net-snmp-5.7.2 package. snmpTransport->f_close(snmpTransport) is also needed and determine that by following what snmp_close() did at the end of subagent_open_master_session() function.

Upvotes: 0

dorsey1138
dorsey1138

Reputation: 51

I ran into this problem right now with quagga and ospfd and after doing an strace -f -p PID, noticed this among the output:

connect(14, {sa_family=AF_FILE, path="/var/agentx/master"}, 110) = -1 EACCES (Permission denied)

so I:

$ ls -al /var/agentx/
total 8
drwx------   2 root root 4096 Sep 12 20:50 .
drwxr-xr-x. 27 root root 4096 Sep 12 20:13 ..
srwxrwxrwx   1 root root    0 Sep 12 20:50 master

and then I:

$ chmod 755 /var/agentx/

and immediately zebra and ospfd had their Agentx subnets connect.

$ tail -10f /var/log/quagga/zebra.log
2014/09/12 20:52:59 ZEBRA: snmp[info]: NET-SNMP version 5.5 AgentX subagent connected

$ tail -10f /var/log/quagga/ospfd.log
2014/09/12 20:52:59 OSPF: snmp[info]: NET-SNMP version 5.5 AgentX subagent connected

This is running quagga-0.99.23-2014062401 on RHEL6. hope this helps.

Upvotes: 5

toschev.andrey
toschev.andrey

Reputation: 1

I have solved problem next comands line in OS Ubuntu 17.07

  1. Change code (add line)

view systemview included .1.3.6.1.2.1.1

view systemview included .1.3.6.1.2.1.2

view systemview included .1.3.6.1.2.1.25.1.1

instead of

view systemview included .1.3.6.1.2.1.1

view systemview included .1.3.6.1.2.1.25.1.1

  1. Write down new line master agentx in /etc/snmpd.conf
  2. Restart snmpd demon:

sudo /etc/init.d/snmpd restart or sudo service snmpd restart

Upvotes: -1

soni
soni

Reputation: 85

As the subagent of Net-SNMP sometimes unable to read the adress of master agent from the configuration file, so you can even try

  /* set the location of master agent */
  netsnmp_ds_set_string(NETSNMP_DS_APPLICATION_ID,
                        NETSNMP_DS_AGENT_X_SOCKET, "udp:X.X.X.X:1610");

Write these lines in the agentx code before calling init_agent().

Upvotes: -1

Damien
Damien

Reputation: 11

Had a similar problem, whether it be with the unix Sockets or Tcp:localhost:750 i was still getting the same error message:

/var/log/quagga/ospfd.log:  warning, failed to connect to Master AgentX [nill] or [tcp:localhost:750].

I resolved the issue by disabling SELINUX.

Upvotes: 1

James Liu
James Liu

Reputation: 69

This is basically saying the sub-agent you wrote failed to connect to NetSNMP master agent, as the message suggested. In Linux, by default agentx will attempt to make the connection via socket using /var/agentx/master. The following hint might help:

  1. Running your sub-agent under appropriate privilege that has access to sockets e.x. sudo
  2. Check socket setting in your snmpd.conf (which located varies) if not already specified, such as agentxsocket /var/agentx/master and agentxperms 777 777
  3. Restart NetSNMP for any change to take effect with sudo service snmpd restart; or as an option you can try stop the service with sudo service snmpd stop and run an instance with debugging mode snmpd -f -Lo -Dagentx which most likely will output useful information on sub-agent connection.

Upvotes: 6

Related Questions