My setup:
hosts.cfg
- contains definitions for each host under monitoring, e.g.:
define host{
use linux-server
host_name rdss-vpn
display_name VPN
address 54.***.***.176
}
hosts_groups.cfg
- define groups:
define hostgroup{
hostgroup_name rdss-service-server
alias RDSS services
members [...], rdss-vpn
}
services.cfg
:
define service{
use local-service
hostgroup_name rdss-web-server, rdss-service-server
service_description Memory usage
check_command check_linux_memory!50!80
notifications_enabled 1
}
And check_linux_memory
in commands.cfg
:
define command{
command_name check_linux_memory
command_line $USER1$/check_nrpe -H $HOSTNAME$ -c check_linux_memory -a '-f -w $ARG1$ -c $ARG2$'
}
Here is example of host, where check_linux_memory
works:
define host{
use linux-server
host_name www.dev.domain.com
display_name DEV
address 54.***.***.136
}
It's group:
define hostgroup{
hostgroup_name rdss-web-server
alias RDSS web servers
members www.dev.domain.com, www.qa.domain.com, www.staging.domain.com
}
Problem is with few new added hosts, like rdss-vpn
- Nagios won't get it's IP from hosts (please note - I have few other servers (also in groups) in check_linux_memory
- all works).
Instead - I have an error in nagios.log
:
[1437473407] SERVICE ALERT: rdss-vpn;Memory usage;WARNING;HARD;4;(No output on stdout) stderr: Could not resolve hostname rdss-vpn: Name or service not known
Your problem is that you wrote your check command to use
$HOSTNAME$
instead of$HOSTADDRESS$
.This happens to work for your other hosts, because they are named with FQDNs (e.g., www.dev.domain.com). It doesn't work for
rdss-vpn
because that's not a valid hostname from the perspective of your Nagios box.You should use the address, not the hostname, in checks. This removes DNS as a dependency for Nagios checks. If you really need to use a hostname instead of the IP, put the hostname in as the host address.
Also, traditionally one would just pass the check to
check_nrpe
as an ARG, likecheck_nrpe!check_memory
orcheck_nrpe!check_memory!50 80
. But it's up to you, ultimately.