This article applies as of PRTG 22
Inverse ping with a Windows script file
With an EXE/Script sensor, you can use a Windows command script (.cmd or .bat) to send a ping request to a device and return an error when it is actually reachable.
We have successfully tested the following script:
@echo off
PING %1 > nul
if errorlevel 1 (echo 0:OK - Ping to %1 failed && EXIT /B 0) else (echo 1:Error - Ping to %1 successful && EXIT /B 2)
For Windows 2008 and Windows 7, use this script (see answer below):
@echo off
ping -n 2 %1|Findstr /I /C:"timed out" /C:"host unreachable" /C:"could not find host" > nul
if %errorlevel%==0 (echo 0:OK - Ping to %1 failed && EXIT /B 0) else (echo 1:Error - Ping to %1 successful && EXIT /B 2)
Steps to take
- In the \Custom Sensors\EXE subfolder of the PRTG program directory, create a .bat or .cmd file inverse_ping.cmd that contains the script shown above. In a cluster installation, copy this file to every cluster node.
- In PRTG, add a new EXE/Script sensor.
- In the sensor settings, choose inverse_ping.cmd from the EXE/Script dropdown list.
- In the Parameters field, enter the DNS name or IP address of the device you want to ping.
- Save your settings.
- The sensor starts monitoring immediately.
- If the configured device does not answer to a ping, the sensor shows a green OK status, the last message OK - Ping to xyz failed, and the last result 0.
- If the configured device does actually answer to a ping, the sensor shows a red Down status, the last message Error - Ping to xzy successful, and the last result 1.
Notes
- The values returned by the script do not correspond to the measured ping times, but merely indicate the status. To additionally measure ping times, you can add another sensor. See How to create/customize statistical Ping sensor? for more information.
- As usual, you can set up notification triggers to be notified when the EXE/Script sensor's status changes.
- Issues related to custom sensors are not covered by the 24-hour support offer from Paessler.
Add comment