Problem trying to add a host using addhost.php

Hello,

I’m trying to add some hosts using the addhost.php script and I’m having some problems.

I’m running addhost.php as follow:

$: ./addhost.php -g 0 -p ifIndex hostname community v2c 161 udp
Could not connect to hostname, please check the snmp details and snmp reachability

I’m passing the poller group 0 because that’s the default poller group and I have other two poller groups.

I can ping the hostname, I can connect to it and I can run a snmpwalk on the hostname, also I was able to add the hostname using the web interface, but it did not work in the command line.

I also tried the command with less parameters, like ./addhost.php hostname community v2c, but got the same error.

What else do I need to check to be able to add hosts using the command line?

That syntax works for me so this must be an snmp config issue or firewall.

It is not a firewall problem, the snmpwalk works fine and adding the host using the web ui, which runs in the same server also works, only the script is not working.

Is there any way to debug what the script is doing?

Hello,

Anyone has any idea of what I can do to try to find the problem?

For example, I’m trying to add a device through addhost.php and it fails, but it is not a snmp connectivity problem because I can snmpwalk the same device from the same server, also I can add the device through the web from the same server.

In the image below I hide the server nanme, community name and device name, but you can see that addhost.php fails, but snmpwalk do not fail.

What else could affect addhost.php?

Using any odd chars in the community string? LIke $?

No, only letters.

Linux distribution ?

It’s a CentOS 7.4 and my librenms version is:

====================================
Component | Version
--------- | -------
LibreNMS  | 1.33-259-ge57c311
DB Schema | 226
PHP       | 7.1.11
MySQL     | 5.5.56-MariaDB
RRDTool   | 1.6.0
SNMP      | NET-SNMP 5.7.2
====================================

can you please print the output of snmpwalk from libre host to that device?

jc

What information do you need from the snmpwalk? The device is a Junos SRX 300 and the snmpwalk output gives me around 8000 lines.

Are you running the command as root or librenms user?
It works ok for me here, I can add hosts via CLI or WebGUI.
what is the output of ./validate.php?

I’m running as librenms, tried as root also but got the same error, I have three pollers and I can’t add devices using CLI in none of them, works fine from the WebGUI which runs in one of the pollers.

I can snmpwalk the device, I can ping and connect to the device using SSH and I can add the device using the WebGUI, only the addhost.php throws an error.

Could not connect to device, please check the snmp details and snmp reachability

./validate.php returns OK for the database connection and warnings and fails fo the polling time, which is normal, since I’m polling the devices every 10 minutes, not 5.

====================================
Component | Version
--------- | -------
LibreNMS  | 1.33-297-g34ed39c
DB Schema | 227
PHP       | 7.1.11
MySQL     | 5.5.56-MariaDB
RRDTool   | 1.6.0
SNMP      | NET-SNMP 5.7.2
====================================

[OK]    Database connection successful
[OK]    Database schema correct
[FAIL]  The poller (XXXX) has not completed within the last 5 minutes, check the cron job.
[FAIL]  The poller (XXXX) has not completed within the last 5 minutes, check the cron job.
[WARN]  Some devices have not been polled in the last 5 minutes. You may have performance issues.
	[FIX] Check your poll log and see: http://docs.librenms.org/Support/Performance/
	Devices:
          list of devices

I really don’t know what else to look.

Hello?

Anyone has any idea what could cause the addhost.php to not work, but anything else work? WebGUI works, snmpwalk works, snmpbulkwalk works, only addhost.php do not work, the librenms is updated.

Or at least anything else that I could check, I tried to read the code but didn’t find anything that could cause the problem.

Your install looks out of date, you can try updating that first just in case it’s a bug that’s been fixed.

My install is up to date, daily.sh is enabled, just ran daily.sh again, then validate.php and addhost.php and still nothing.

I can ping the devices, I can connect to them using ssh, I can snmpwalk and snmpbulkwalk the devices and I can add the devices using the WebUI from the same server that I am trying to add using addhost.php, only addhost.php throws an error.

I am trying to understand what addhost.php does different from the ‘add device’ page in the WebUI to see if I can find the problem.

Hello?

Any idea of what I can do to solve this?

As you are using snmpv2 try doing a tcpdump when adding the host, to see what the packets looks like.

Hello,

I ran the following commands and captured it with tcpdump.

  • addhost.php
  • snmpwalk
  • ping -c 2

addhost.php fails and tcpdump shows that it only tried to ping the host, it didn’t show me any snmp connection, snmpwalk works fine and I can see the request, ping also works fine, as expected.

For some reason the addhost.php stops after the ping, but the web ui version, addhost.inc.php works without any problem.

What addhost.php does different from addhost.inc.php, from the web ui?

Could you please make the tcpdump show both directions during the capture, instead of only packets destined for the given host.

Well, I have the reply from the device that I’m trying to add.

In the image bellow you can see that the server replies for the ping from addhost and after that it replies for a snmpwalk that asked for sysDescr.

The script addhost.php stops after the ping, but the web version, addhost.inc.php works fine, what this script does different? This problem happens with any device, this is not a firewall problem, the servers in the example above do not have a firewall between them.

I did a strace of the addhost.php and I can see that it calls HostUnreachableException.php after the ping results.

fstat(5, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
fcntl(5, F_SETFD, FD_CLOEXEC)           = 0
close(7)                                = 0
fstat(6, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
fcntl(6, F_SETFD, FD_CLOEXEC)           = 0
close(9)                                = 0
fstat(8, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
fcntl(8, F_SETFD, FD_CLOEXEC)           = 0
close(5)                                = 0
read(6, "az-kb001 : xmt/rcv/%loss = 3/3/0"..., 8192) = 64
read(6, "", 8192)                       = 0
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=6311, si_uid=1001, si_status=0, si_utime=0, si_stime=0} ---
close(6)                                = 0
wait4(6311, [{WIFEXITED(s) && WEXITSTATUS(s) == 0}], WNOHANG|WSTOPPED, NULL) = 6311
close(8)                                = 0
wait4(6311, 0x7ffd5c422694, 0, NULL)    = -1 ECHILD (No child processes)
access("/opt/librenms/vendor/composer/../../LibreNMS/Exceptions/HostUnreachableException.php", F_OK) = 0
lstat("/opt/librenms/vendor/composer/../../LibreNMS/Exceptions/HostUnreachableException.php", {st_mode=S_IFREG|0664, st_size=1509, ...}) = 0
lstat("/opt/librenms/vendor/composer/../../LibreNMS/Exceptions", {st_mode=S_IFDIR|0775, st_size=4096, ...}) = 0
open("/opt/librenms/LibreNMS/Exceptions/HostUnreachableException.php", O_RDONLY) = 4
fstat(4, {st_mode=S_IFREG|0664, st_size=1509, ...}) = 0
fstat(4, {st_mode=S_IFREG|0664, st_size=1509, ...}) = 0
fstat(4, {st_mode=S_IFREG|0664, st_size=1509, ...}) = 0
mmap(NULL, 1509, PROT_READ, MAP_SHARED, 4, 0) = 0x7fc713269000
munmap(0x7fc713269000, 1509)            = 0
close(4)                                = 0
write(1, "\33[0;31mCould not connect to az-k"..., 94) = 94
close(2)                                = 0
close(1)                                = 0
close(0)                                = 0
munmap(0x7fc6fd800000, 2097152)         = 0
write(3, "\1\0\0\0\1", 5)               = 5
shutdown(3, SHUT_RDWR)                  = 0
close(3)                                = 0