Home Directory Plugins Operating Systems Windows NRPE ping_remote.bat ( with check_nrpe and nsclient)

Search Exchange

Search All Sites

Nagios Live Webinars

Let our experts show you how Nagios can help your organization.

Contact Us

Phone: 1-888-NAGIOS-1
Email: sales@nagios.com

Login

Remember Me

Directory Tree

ping_remote.bat ( with check_nrpe and nsclient)

Rating
11 votes
Favoured:
0
Hits
94103
Files:
FileDescription
ping_remote.batping_remote.bat
Nagios CSP

Meet The New Nagios Core Services Platform

Built on over 25 years of monitoring experience, the Nagios Core Services Platform provides insightful monitoring dashboards, time-saving monitoring wizards, and unmatched ease of use. Use it for free indefinitely.

Monitoring Made Magically Better

  • Nagios Core on Overdrive
  • Powerful Monitoring Dashboards
  • Time-Saving Configuration Wizards
  • Open Source Powered Monitoring On Steroids
  • And So Much More!
Basically it takes the ping stats (between nsclient + desired ip) then forwards the
info to nagios svr.

when testing this on the nsclient, ensure to "rem" out the "@exit" lines
to test it or you will not see the results when it exits using the "@exit" cmd.

C:>ping_remote 192.168.0.1 5 200,1 400,10
this command above will ping "192.168.0.1" with 5 packets and
gives the warning value if RTA is "200", Packet Loss 1% or above
gives the Critical value if RTA is "400", Packet Loss 10% or above

C:Program FilesNSClient++scripts>ping_remote.bat
Usage:ping_remote , ,

example: /usr/local/nagios/libexec/check_nrpe -H 172.19.4.1 -c ping_remote -t 90 -a 172.19.40.30 65 450,1 700,5 (From Nagios SVR.)
: ping_remote 192.168.0.1 5 200,1 400,10 (From a local win wks where
ping_remote.bat resides)
: (wplcpl are in percent, without the "%" symbol!!)
Reviews (6)
This plugin seems to work ok, but it does fail if the device you're pinging completely vanishes. This causes the ping command to return a destination host unreachable error the the script can't handle it and returns bad data (error code 255). I believe I have fixed this by adding these lines after the "Special handler for TTL" section:

REM ######## special handler for complete loss #######
FOR /F "tokens=3 delims= " %%k in ('findstr /c:"Destination host unreachable" %randomfilename%') do (
set LST=100
set AVG=1000
)

I've tested this on my system and it seems to work now instead of kicking back bad data.
bydragonvs, April 10, 2016
The command (check_ping_ru) returned an invalid return code: 255

Plugin no work
byWolkodaw, January 21, 2016
./check_nrpe -H 192.168.0.254 -c ping_remote -t 10 -a 192.169.0.1 5 20,1 100,5

The command (ping_remote) returned an invalid return code: 255

Two days struggling with the plugin has not earned
All kinds of forums have not helped
byLordVaderXIII, April 26, 2013
Ok so Im not sure if this is the right place but anyway.

This is exactly what Im looking for, however I have no clue how to use it.

Im new to Nagios and have just gotten the thing working on Windows hosts but I do not know how to implement this bat file. Can someone help please?
byandy232, October 24, 2012
Hi there,

in some situations ping_remote returns "OK" although the device is turned off.
I found out that a manual ping returns the following:

Pinging 192.168.90.200 with 32 bytes of data:

Reply from 192.168.90.10: Destination host unreachable.
Reply from 192.168.90.10: Destination host unreachable.
Reply from 192.168.90.10: Destination host unreachable.
Reply from 192.168.90.10: Destination host unreachable.

Ping statistics for 192.168.90.200:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 0ms, Maximum = 0ms, Average = 0ms

So ping returns a "0% Paket loss". That is the problem I think.

Any hints ?

Greetings, Andy.
bybriandent, September 20, 2012
1 of 1 people found this review helpful
This is an excellent script to call from within Windows to verify another device is available.

I've added three enhancements: 1) randomized the temp file name to avoid a collision if called concurrently (eg: two nagios servers), 2) explicitly delete the temp file and 3) added perfdata in the return.

I also capitalized the file.

@ECHO OFF
SETLOCAL


REM ####### ENSURE ALL REQUIRED INFO IS PRESENT --UNIX VAR--######
@ECHO %1%2%3%4%5%6|FIND "ARG"
IF NOT ERRORLEVEL 1 GOTO MSEOF

REM ####### ENSURE ALL REQUIRED INFO IS PRESENT --WIN VAR--######
IF "%1"=="" GOTO MSEOF
IF "%2"=="" GOTO MSEOF
IF "%3"=="" GOTO MSEOF
IF "%4"=="" GOTO MSEOF
IF "%5"=="" GOTO MSEOF
IF "%6"=="" GOTO MSEOF

REM PAUSE

@ECHO %4 |FIND "%%%"
IF NOT ERRORLEVEL 1 GOTO MSEOF
@ECHO %6 |FIND "%%%"
IF NOT ERRORLEVEL 1 GOTO MSEOF



REM ####### ASSIGN EACH TO A VARIABLE TO REFERENCE IT LATER..######
SET IP=%1
SET PKT=%2
SET WRTA=%3
SET WPL=%4
SET CRTA=%5
SET CPL=%6

REM ######## CAPTURE FRESH DATA TO A FILE #######
REM 20120920 TO AVOID COLLISIONS DURING CONCURRENT CALLS CREATE A SEMI-RANDOM FILE NAME
SET RANDOMFILENAME=%RANDOM%-%1-TMP
@ECHO ->%RANDOMFILENAME%

PING %IP% -n %PKT% >>%RANDOMFILENAME%

REM ######## PICKOUT THE DATA WE NEED FROM THE FILE #######
FOR /F "TOKENS=11 DELIMS= " %%K IN ('findstr /c:"Lost" %RANDOMFILENAME%') DO SET LST=%%K

IF ERRORLEVEL 1 GOTO TIMEOUT
FOR /F "TOKENS=9 DELIMS= " %%K IN ('findstr /c:"Average" %RANDOMFILENAME%') DO SET AVG=%%K


REM PAUSE
DEL /Q %RANDOMFILENAME%


REM ######## TRIM THE VARIABLES...####
SET AVG=%AVG:M=%
SET AVG=%AVG:S=%

:TIMEOUT
SET LST=%LST:(=%
SET LST=%LST:~0,-1%


REM ######## NOW THE FUN STUFF, COMPARE THE WARNING, CRITICAL VALUES..####

IF %LST% GEQ %CPL% GOTO CPL-2
IF %AVG% GEQ %CRTA% GOTO CRTA-2
IF %LST% GEQ %WPL% GOTO WPL-1
IF %AVG% GEQ %WRTA% GOTO WRTA-1

REM PAUSE

GOTO OK-0

:CPL-2
@ECHO REMOTE CONNECTION TO %IP% IS DOWN: LOSS=%LST%%% (%PKT% PKTS)^|rta=%CRTA%;%WRTA% pl=%LST%%%;%WPL%;%CPL%
REM GOTO EOF
@EXIT 2

:CRTA-2
@ECHO REMOTE CONNECTION TO %IP% IS DOWN: LOSS=%LST%%%, AVE=%AVG%ms (%PKT% PKTS)^|rta=%AVG%ms;%WRTA%;%CRTA% pl=%LST%%%;%WPL%;%CPL%
REM GOTO EOF
@EXIT 2

:WPL-1
@ECHO REMOTE CONNECTION TO %IP% IS SLOW: LOSS=%LST%%%, AVE=%AVG%ms (%PKT% PKTS)^|rta=%WRTA%;%CRTA% pl=%LST%%%;%WPL%;%CPL%
REM GOTO EOF
@EXIT 1

:WRTA-1
@ECHO REMOTE CONNECTION TO %IP% IS SLOW: LOSS=%LST%%%, AVE=%AVG%ms (%PKT% PKTS)^|rta=%AVG%ms;%WRTA%;%CRTA% pl=%LST%%%;%WPL%;%CPL%
REM GOTO EOF
@EXIT 1



:OK-0
@ECHO REMOTE CONNECTION TO %IP% IS UP: LOSS=%LST%%%, AVE=%AVG%ms (%PKT% PKTS)^|rta=%AVG%ms;%WRTA%;%CRTA% pl=%LST%%%;%WPL%;%CPL%
REM GOTO EOF
@EXIT 0




:MSEOF
@ECHO USAGE:PING_REMOTE ^ ^^,^ ^,^
@ECHO EXAMPLE: /USR/LOCAL/NAGIOS/LIBEXEC/CHECK_NRPE -H 172.19.48.139 -C PING_REMOTE -T 90 -A 172.19.88.30 65 450,1 700,5 (FROM NAGIOS SVR.)
@ECHO : PING_REMOTE 192.168.0.1 5 200,1 400,10 (FROM A LOCAL WIN WKS WHERE PING_REMOTE.BAT RESIDES)
@ECHO : (WPL\CPL ARE IN PERCENT, WITHOUT THE "%%%" SYMBOL!!)

REM GOTO EOF
@EXIT 0



:EOF