Search Exchange
Search All Sites
Nagios Live Webinars
Let our experts show you how Nagios can help your organization.Login
Directory Tree
Check Windows Time Offset (check_windows_time.bat)
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!
To make installation simple it is just a .bat file that is basically a glorified nagios wrapper for w32tm. Tested on Windows 2k3/2k8/2k8r2. While a bit raw, it does return some common errors (i.e. - server not found)
A windows domain controller can used as a time source as well as a other NTP servers.
To get the plugin going, copy the check_windows_time.bat file to your nagios client /scripts folder on the Windows machine and define the script in your nsc.ini. Don't forget to enable command arguments if you wish to pass the ntp source and other arguments from check_nrpe.
check_windows_time.bat - Nagios plugin that checks time offset against a specified ntp server.
Usage: check_windows_time.bat timeserver warning critical
* warning and critical in seconds
C:>check_windows_time.bat pool.ntp.org 180 300
OK: Time is -01.0821202s from pool.ntp.org|'Offset'=01s;180;300;0
$ /usr/local/nagios/libexec/check_nrpe -H my-server.domain.local -c check_windows_time -a pool.ntp.org 180 300
OK: Time is +00.0120138s from pool.ntp.org|'Offset'=00s;180;300;0
check_windows_time.bat - Nagios plugin that checks time offset against a specified ntp server.
Usage: check_windows_time.bat timeserver warning critical
* warning and critical in seconds
C:>check_windows_time.bat pool.ntp.org 180 300
OK: Time is -01.0821202s from pool.ntp.org|'Offset'=01s;180;300;0
$ /usr/local/nagios/libexec/check_nrpe -H my-server.domain.local -c check_windows_time -a pool.ntp.org 180 300
OK: Time is +00.0120138s from pool.ntp.org|'Offset'=00s;180;300;0
Reviews (8)
byMorello, September 20, 2016
Hi all,
This script works great but i can not see check_time on nagios server when i open the gui, i should be able to see it as listed services. I can only see modules like checkdisk, currentload, check, checkservice, checkprocess etc these are all listed under modules and set to 1 in nsclient.ini file. Any ideas?
Thanks in advance.
BR,
This script works great but i can not see check_time on nagios server when i open the gui, i should be able to see it as listed services. I can only see modules like checkdisk, currentload, check, checkservice, checkprocess etc these are all listed under modules and set to 1 in nsclient.ini file. Any ideas?
Thanks in advance.
BR,
byscubacat3, April 29, 2015
To allow arguments from Windows, add this section above the definition in nsclient.ini:
[/settings/external scripts]
allow arguments = 1
[/settings/external scripts]
allow arguments = 1
I am a Noob and here is my instructions for getting it to work.
This will hard code the arguments ( I am still trying to figure out why I get errors passing arguments )
Tested on NSClient++ 0.4.1.101
on client machine
1. Open
C:\Program Files\NSClient++\nsclient.ini
add to the bottom:
[/settings/external scripts/wrapped scripts]
; check_windows_time -
check_windows_time = check_windows_time.bat pool.ntp.org 30 10
2. Copy check_windows_time.bat to
C:\Program Files\NSClient++\scripts
3. Restart NSClient++ service
4. open command prompt
Navigate to script folder
Check with this command(check_windows_time.bat pool.ntp.org 30 10)
C:\Program Files\NSClient++\scripts>check_windows_time.bat pool.ntp.org 30 10
You should see
C:\Program Files\NSClient++\scripts>check_windows_time.bat pool.ntp.org 30 10
OK: Time is -00.0274625s from pool.ntp.org|'Offset'=00s;30;10;0
On Nagios server
1. Go to Nagios server and setup the check without arguments ( they are hard coded in the nsclient.ini file on client machine ).
$USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c check_windows_time
To test from nagios server in Putty
cd /usr/local/nagios/libexec
./check_nrpe -H YOUR_SERVER_TO_CHECK -c check_windows_time
You should see
OK: Time is -00.1961396s from ralpdc01|'Offset'=0s;30;10;0
I hope this helps
If anyone has the Noob steps to allow arguments to be passed from Nagios server to client that could be added to this it would be great if you shared it.
Thanks.
This will hard code the arguments ( I am still trying to figure out why I get errors passing arguments )
Tested on NSClient++ 0.4.1.101
on client machine
1. Open
C:\Program Files\NSClient++\nsclient.ini
add to the bottom:
[/settings/external scripts/wrapped scripts]
; check_windows_time -
check_windows_time = check_windows_time.bat pool.ntp.org 30 10
2. Copy check_windows_time.bat to
C:\Program Files\NSClient++\scripts
3. Restart NSClient++ service
4. open command prompt
Navigate to script folder
Check with this command(check_windows_time.bat pool.ntp.org 30 10)
C:\Program Files\NSClient++\scripts>check_windows_time.bat pool.ntp.org 30 10
You should see
C:\Program Files\NSClient++\scripts>check_windows_time.bat pool.ntp.org 30 10
OK: Time is -00.0274625s from pool.ntp.org|'Offset'=00s;30;10;0
On Nagios server
1. Go to Nagios server and setup the check without arguments ( they are hard coded in the nsclient.ini file on client machine ).
$USER1$/check_nrpe -H $HOSTADDRESS$ -p 5666 -c check_windows_time
To test from nagios server in Putty
cd /usr/local/nagios/libexec
./check_nrpe -H YOUR_SERVER_TO_CHECK -c check_windows_time
You should see
OK: Time is -00.1961396s from ralpdc01|'Offset'=0s;30;10;0
I hope this helps
If anyone has the Noob steps to allow arguments to be passed from Nagios server to client that could be added to this it would be great if you shared it.
Thanks.
byfmdupre, October 28, 2014
I made the following change to no longer be rounding the numbers a point lower to 1.
Do not round numbers
for /f "tokens=*" %%t in ('w32tm /stripchart /computer:%time_server% /samples:1 /dataonly') do set output=%%t
if not "x%output:0x80072af9=%"=="x%output%" goto host_error
if not "x%output:0x800705B4=%"=="x%output%" goto comm_error
if not "x%output:error=%"=="x%output%" goto unknown_error
if not "x%output:)=%"=="x%output%" goto unknown_error
set time_org=%output:*, =%
set time=%time_org%
rem set time=%time_org:~1,-9%
Do not round numbers
for /f "tokens=*" %%t in ('w32tm /stripchart /computer:%time_server% /samples:1 /dataonly') do set output=%%t
if not "x%output:0x80072af9=%"=="x%output%" goto host_error
if not "x%output:0x800705B4=%"=="x%output%" goto comm_error
if not "x%output:error=%"=="x%output%" goto unknown_error
if not "x%output:)=%"=="x%output%" goto unknown_error
set time_org=%output:*, =%
set time=%time_org%
rem set time=%time_org:~1,-9%
byarigaud, July 18, 2014
Excellent ! Add check windows version, tested ont w2k, w2003, 2008, 7 (not in xp)
for /f "tokens=2 delims=[]" %%x in ('ver') do set cmdver=%%x
set cmdver=%cmdver:Version =%
for /f "tokens=1,2,3* delims=." %%g in ("%cmdver%") do (
set major=%%g
set minor=%%h
set build=%%i
)
rem Windows 3.1,95,95 OSR2,NT 4.0,98,98 SE,ME
IF %major% LEQ 4 goto ver_false
rem Windows 2000
echo %cmdver% | FINDSTR /C:"5.0" > nul
IF %ERRORLEVEL% EQU 0 goto ver_false
:ver_false
echo UNKNOWN: OS Version not supported [%cmdver%]
exit /b 3
heklp source : http://ss64.org/viewtopic.php?pid=3151#p3151
for /f "tokens=2 delims=[]" %%x in ('ver') do set cmdver=%%x
set cmdver=%cmdver:Version =%
for /f "tokens=1,2,3* delims=." %%g in ("%cmdver%") do (
set major=%%g
set minor=%%h
set build=%%i
)
rem Windows 3.1,95,95 OSR2,NT 4.0,98,98 SE,ME
IF %major% LEQ 4 goto ver_false
rem Windows 2000
echo %cmdver% | FINDSTR /C:"5.0" > nul
IF %ERRORLEVEL% EQU 0 goto ver_false
:ver_false
echo UNKNOWN: OS Version not supported [%cmdver%]
exit /b 3
heklp source : http://ss64.org/viewtopic.php?pid=3151#p3151
bypestigarribia, November 7, 2012
This was very useful, only one note that I have to do:
NSC.INI
I have to enable:
; Script to check external scripts and/or internal aliases.
CheckExternalScripts.dll
NSC.INI
I have to enable:
; Script to check external scripts and/or internal aliases.
CheckExternalScripts.dll
bystaso, September 27, 2012
Works for me ! Thanks !