Cacti / spine

Spine C Based Poller for Cacti
GNU Lesser General Public License v2.1
80 stars 45 forks source link

Spine didn't support IPv6 only host (hostname with only AAAA record) #57

Closed ndeffayet closed 4 years ago

ndeffayet commented 6 years ago

With the last version (1.1.38) of Cacti and Spine:

1) cmd.php works fine with IPv6 only host (hostname with only AAAA record) 2) Spine didn't works with IPv6 only host (hostname with only AAAA record)

It's not possible to add anymore udp6: in front of hostname/address as workaround in Cacti because it result of: "Session SNMP error - SNMP::__construct(): php_network_getaddresses: getaddrinfo failed: Name or service not known"

It's critical to have Spine able to poll IPv6 only host.

netniV commented 6 years ago

I think this was already addressed recently. I"ll see if I can find the previous issue that was opened aobut IPv6 as i'm sure this is identical.

netniV commented 6 years ago

This may be related to the library problems we experienced here https://github.com/Cacti/cacti/issues/1634

ndeffayet commented 6 years ago

It can't be related to https://github.com/Cacti/cacti/issues/1634 because:

netniV commented 6 years ago

Actually the udp6: thing was for net-snmp which is used by both cacti and spine. However, as Cacti also uses the same hostname for other calls outside of net-snmp, you are correct it wouldn't work globally.

I'm not saying it's exactly the same bug as 1634, but it is likely to introduced due to changes in the libraries, not that it's the same bug. What OS and library versions are you running? It's probably easier to post the output from the technical support page (feel free to block out any confidential parts).

netniV commented 6 years ago

Also, whilst you say spine doesn't work, you've not actually said why / how it doesn't work? eg, provide logs of the actual issues

ndeffayet commented 6 years ago

Spine didn't work:

For recall host is IPv6 only.

netniV commented 6 years ago

OK so to try and narrow this down, I have decided to break down the spine code for you under spine 1.1.38 (and I still believe the error comes outside of spine):

The first message you listed in your first post does not even appear. The "Invalid SNMP Session" message appears only once in ping.c under ping_snmp() function. That is called by ping_host() which is again in ping.c and is called from poller.c.

They all rely on the snmp_session pointer on the host object which is built as such:

if (((host->snmp_version >= 1) && (host->snmp_version <= 2) &&
        (strlen(host->snmp_community) > 0)) ||
        (host->snmp_version == 3)) {
        host->snmp_session = snmp_host_init(host->id,
                host->hostname,
                host->snmp_version,
                host->snmp_community,
                host->snmp_username,
                host->snmp_password,
                host->snmp_auth_protocol,
                host->snmp_priv_passphrase,
                host->snmp_priv_protocol,
                host->snmp_context,
                host->snmp_engine_id,
                host->snmp_port,
                host->snmp_timeout);
} else {
        host->snmp_session = NULL;
}

So, either you have not got an SNMP version set (which I doubt) or the snmp_host_init() is failing. snmp_host_init() is in snmp.c and does a lot of work building the various parameters specific for the host into the session object that will be used to open the SNMP connection to the device. The first thing that it does is to call snmp_sess_init() which is an external function and then runs through a load of parameter settings under it gets to the host name:

snprintf(hostnameport, BUFSIZE, "%s:%i", hostname, snmp_port);
session.peername    = hostnameport;

Peername is never set or read from again within the spine code. It's only used by the netsnmp library as part of the session.

$grep "peername" * -R
snmp.c: session.peername    = hostnameport;

I'll check with one of my colleagues, see if he believes one of our recent fixes in the cmd.php code is applicable here (I suspect it is). Then hopefully we can mark the issue as resolved.

netniV commented 6 years ago

In the meantime, could you make sure you are using the same spine / cacti versions.

ndeffayet commented 6 years ago

Many thanks for your feedback. I confim I use the same version of Spine and Cacti (1.1.38).

netniV commented 6 years ago

Looked at the fix for the PHP side of things and that was to use quick_print = true. However, when I just looked to see if I could work out the C code version of this, I couldn't find that as a parameter on the session structure so that has me slightly confused.

cigamit commented 6 years ago

How is the host addressed in the host description in Cacti. Also, what version of Net-SNMP were you compiling against? Does the host have an IPv4 address as well? Can you use the IPv6 address instead of the dns hostname till we have this fixed. I know the issue and just have not had the time to address it.

TheWitness commented 4 years ago

Okay, ping has been updated to issue a warning of a ping_[tcp|udp|icmp] are attempted on an IPv6 host. If that option is selected, the ping will be ignored. If the ping type does not include snmp, an error will be issued.