Guides‎ > ‎NRPE‎ > ‎Proxying or Double Hopping‎ > ‎

NSClient++

Consider the following scenario:
  • Nagios (Host_A) wants to execute a check on Host_C (Windows 2008 R2)
  • Host_C is not directly contactable by Host_A however it can contact Host_B (Windows 2008 R2)
  • Host_B will receive a NRPE request and it's command definition will allow it run it's own NRPE request to Host_C

Host_A ---> Host_B ---> Host_C

In all examples I'm using Host_xxx instead of an IP Address. Please replace any examples with an IP Address. This just makes it easier to read.


Host_C

Host_C is running Windows 2008 R2 and has NSClient++ 0.4.1.105 installed as per these instructions.

Host_C has allowed Host_B to connect to it as per:

[/settings/default]
; ALLOWED HOSTS - A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.
allowed hosts = 127.0.0.1, HOST_B_IP_ADDRESS

Restart the NSClient++ service if you make any changes to nsclient.ini.

The next step will be to test this from Host_B.


Host_B

Host_B is running Windows 2008 R2 and has NSClient++ installed as per these instructions.

Host_B has allowed Host_A to connect to it as per:

[/settings/default]
; ALLOWED HOSTS - A comaseparated list of allowed hosts. You can use netmasks (/ syntax) or * to create ranges.
allowed hosts = 127.0.0.1, HOST_A_IP_ADDRESS

When logged onto Host_B, it is able to run NRPE checks against Host_C, here is an example:

Open a command prompt with Administrator rights

cd "\Program Files\NSClient++\"

Command:

nscp client -M NRPEClient -H Host_C -c CheckCPU --arguments warn=80 crit=90 time=1m time=5m time=15m

Output:

OK CPU Load ok.|'1m'=0%;80;90 '5m'=0%;80;90 '15m'=0%;80;90

Great, we know there is communication from Host_B to Host_C.


Now we need to configure NSClient++ on Host_B to listen for requests from Host_A to execute checks on Host_C.

In the command prompt you have open:

nscp settings --activate-module NRPEClient

Then restart the NSClient++ service

nscp service --stop
nscp service --start

The next step will be to test this from Host_A.


Host_A

Host_A is the nagios server. Lets execute check_nrpe to Host_B to execute the command npre_query command which in turn will contact Host_C.

Command:

check_nrpe -H Host_B -c nrpe_query -a host=Host_C query-command=CheckCPU query-arguments="warn=80" query-arguments="crit=90" query-arguments="time=1m" query-arguments="time=5m" query-arguments="time=15m"

Output:

OK CPU Load ok.|'1m'=0%;80;90 '5m'=0%;80;90 '15m'=0%;80;90


How easy was that!

All checks work in a similar fashion:

Command:

check_nrpe -H Host_B -c nrpe_query -a host=Host_C query-command=CheckDriveSize query-arguments="ShowAll" query-arguments="MinWarn=10G" query-arguments="MinCrit=5G" query-arguments="Drive=C:"

Output:

OK: C:: 16.9G|'C: %'=72%;83;91 'C:'=16.9G;10;5;0;59


Command:

check_nrpe -H Host_B -c nrpe_query -a host=Host_C query-command=CheckCounter query-arguments="Counter:% Processor Used Total=\Processor(_Total)\% Processor Time" query-arguments="ShowAll" query-arguments="MaxWarn=80" query-arguments="MaxCrit=90"

Output:

OK: % Processor Used Total: 10.7688|'% Processor Used Total'=10.76881;80;90


Command:

check_nrpe -H Host_B -c nrpe_query -a host=Host_C query-command=CheckServiceState query-arguments="ShowAll" query-arguments="Spooler=stopped"

Output:

CRITICAL: Spooler: started (critical)


Command:

check_nrpe -H Host_B -c nrpe_query -a host=Host_C query-command=CheckMEM query-arguments="ShowAll" query-arguments="type=physical" query-arguments="MaxWarn=1536" query-arguments="MaxCrit=1792"

Output:

CRITICAL: physical memory: Total: 2G - Used: 635M (31%) - Free: 1.38G (69%) > critical|'physical memory %'=31%;99;99 'physical memory'=650404K;1;1.7;0;2096632



What About Host Ping Checks???

Normally when you monitor hosts with Nagios, you ping the host to make sure it's up or down. We can do the same thing in this scenario by using Host_B to ping Host_C.

Host_C

There is nothing special required here.


Host_B

NSClient++ comes with a script called check_ping.bat which can ping an address and return an OK or CRITICAL result.

We need to enable some extra settings on Host_B.

Open a command prompt with Administrator rights and type the following commands:

cd "\Program Files\NSClient++\"

nscp settings --activate-module CheckExternalScripts --add-defaults

nscp settings --path "/settings/NRPE/server" --key "allow arguments" --set true

nscp settings --path "/settings/external scripts" --key "allow arguments" --set true

nscp settings --path "/settings/external scripts/scripts" --key check_ping --set "scripts\\check_ping.bat $ARG1$"

Then restart the NSClient++ service

nscp service --stop
nscp service --start

The next step will be to test this from Host_A.


Host_A

Host_A is the nagios server. Lets execute check_nrpe to Host_B to execute the script check_ping which in turn will ping Host_C.

Command:

check_nrpe -H Host_B -c check_ping -a Host_C

Output IF Host_C is Up:

OK: Ping succeded

Yes, I did notice the spelling mistake!

Output IF Host_C is Down:

OK: Ping check failed


NOTE:

While creating this guide, it identified two issues with the check_ping.bat script.

  1. The command used to ping a host by the script, "ping", does not correctly let the script know when it cannot ping a host in the same subnet
  2. There is a spelling mistate
    • On line 16, "succeded" should be spelt "succeeded"


Can I Also Query NPRE Clients On Linux From NSClient++???

Yes, yes you can!

Host_D

Host_D is running CentOS 6.5 and has the NRPE client installed as per these instructions.

On Host_D, these commands are already defined as part of the client install as per the instructions

command[check_users]=/usr/local/nagios/libexec/check_users $ARG1$
command[check_load]=/usr/local/nagios/libexec/check_load $ARG1$
command[check_swap]=/usr/local/nagios/libexec/check_swap $ARG1$
command[check_cpu_stats]=/usr/local/nagios/libexec/check_cpu_stats.sh $ARG1$
command[check_mem]=/usr/local/nagios/libexec/custom_check_mem -n $ARG1$

Host_D has allowed Host_B to connect to it as per the only_from setting in /etc/xinetd.d/nrpe .

If you need to make any changes then restart the NRPE service afterwards:

service xinetd restart


The next step will be to test this from Host_A.

Command:

check_nrpe -H Host_B -c nrpe_query -a host=Host_D query-command=check_mem query-arguments="-w 20 -c 10"

Output:

OK - 821 / 988 MB (83%) Free Memory, Used: 205 MB, Shared: 0 MB, Buffers: 26 MB, Cached: 38 MB |'total'=988MB 'free'=821MB 'used'=205MB 'shared'=0 'buffers'=26MB 'cached'=38MB


How easy was that!

All checks work in a similar fashion:

Command:

check_nrpe -H Host_B -c nrpe_query -a host=Host_D query-command=check_users query-arguments="-w 5 -c 10"

Output:

USERS OK - 1 users currently logged in |'users'=1;5;10;0


Command:

check_nrpe -H Host_B -c nrpe_query -a host=Host_D query-command=check_load query-arguments="-w 15,10,5 -c 30,20,10"

Output:

OK - load average: 0.00, 0.00, 0.00|'load1'=0;15;30;0 'load5'=0;10;20;0 'load15'=0;5;10;0


Command:

check_nrpe -H Host_B -c nrpe_query -a host=Host_D query-command=check_swap query-arguments="-w 50 -c 20"

Output:

SWAP OK - 100% free (1983 MB out of 1983 MB) |'swap'=1983MB;0;0;0;1983


Command:

check_nrpe -H Host_B -c nrpe_query -a host=Host_D query-command=check_cpu_stats query-arguments="-w 85 -c 95"

Output:

CPU STATISTICS OK: user=0.00% system=0.00% iowait=0.00% idle=100.00% |'user'=0% 'system'=0% 'iowait'=0%;85;95 'idle'=100%


Notes

If you followed the guide for NRPE then you know we couldn't pass any arguments that have a minus sign. This is not a problem in this scenario as NSClient++ has no problems receiving arguments that have a minus sign (and passing them on).


In relation to the Host_A IP Address. In the scenario where Host_A is and Host_B have the internet between them, the IP Address that Host_B will see requests coming from is more than likely the WAN IP of the firewall at the Host_A site.