Home Directory Plugins Network Protocols NTP and Time Windows time check against NTPD (check_time.vbs)

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


Remember Me

Directory Tree

Windows time check against NTPD (check_time.vbs)

8 votes
Network Monitoring Software - Download Nagios XI
Log Management Software - Nagios Log Server - Download
Netflow Analysis Software - Nagios Network Analyzer - Download
VB script to check Windows system time against NTPD server(s) V 1.01 Calls w32tm and parses the output. The script is loosely based off the check_ad_time.vbs by Mattias Ryrlén (mr@op5.com)
The options all have the hard order and all but the last one are required.
If multiple servers are specified (use commas only, not spaces), all will be querried and only succesfull offset results will be processed.By default the least offset is selected. This can be modified with the option "biggest"

Usage: cscript /NoLogo check_time.vbs serverlist warn crit [biggest]
serverlist (required): one or more server names, coma-separated
warn (required): warning offset in seconds, can be partial
crit (required): critical offset in seconds, can be partial
biggest (optional): if multiple servers, else use default least offset

Example of nsc.ini entry:

check_ntp_time=cscript.exe //T:30 //NoLogo scriptscheck_time.vbs server1,server2,server3 20 240
Reviews (6)
Script may be used to compare sub=seconds offsets but it should be patched for correct work:

1) SetLocale("en-us") should be added as mentioned above

2) Abs() should be used then comparing, around 75th line:

If result = "" Then
Err = 3
Status = "UNKNOWN"
ElseIf Abs(result) > Abs(crit) Then
Err = 2
status = "CRITICAL"
ElseIf Abs(result) > Abs(warn) Then
Err = 1
status = "WARNING"
Err = 0
status = "OK"
End If
This script runs fine and works properly but every once in a while it returns this error-

The command (cscript.exe //T:30 //NoLogo scripts\check_time.vbs +5 +10) returned an invalid return code: 128

I can't see anything wrong in the script itself... has anyone had a similar problem?
I am running into an issue with this script on Server 2008 R2. When I run the script it errors out on line 53 where it runs the following:

If myMatches(0).SubMatches(0) "" Then
result = myMatches(0).SubMatches(0)
End If

Has anyone else experienced this issue and/or know how to work around this?
I just and :


at the top of script for server with specific number format (2008R2, us, with french number format)

The PhilS second point seems to be true
by, May 26, 2011
2 of 2 people found this review helpful
Good script seems to work!

However another couple of points:

1. The /nowarn option of w32tm.exe looks like it's not supported in earlier versions of Windows including XP, but is supported in Vista,7, 2008 Server etc. So for these you need to remove this option from the following line, otherwise the script returns an error.

strCommand = "%SystemRoot%\System32\w32tm.exe /monitor /nowarn /computers:" & serverlist

2. Further to the points made abut the thresholds not working correctly, can I suggest you make the following change:

Change the statement

If result = "" Then
Err = 3
Status = "UNKNOWN"
ElseIf result > crit Then
Err = 2
status = "CRITICAL"
ElseIf result > warn Then
Err = 1
status = "WARNING"
Err = 0
status = "OK"
End If

to the following:

If result = "" Then
Err = 3
Status = "UNKNOWN"
ElseIf abs(result) > abs(crit) Then
Err = 2
status = "CRITICAL"
ElseIf abs(result) > abs(warn) Then
Err = 1
status = "WARNING"
Err = 0
status = "OK"
End If

Then it seems to work properly as far as I have tested it and you can supply the thresholds unsigned.

byFreddy, December 2, 2010
Hi! great script!

a couple of things:

1) the line (near the end):

Wscript.Echo "NTP " & status & ": Offset " & result & " secs|'offset'=" & result & "s;" & warn & ";" & crit & ";"

should be changed in:

Wscript.Echo "NTP " & status & ": Offset " & result & " secs|offset=" & result & "s;" & warn & ";" & crit & ";"

so the performance data can processed by pnp4nagios addon.

2) I think there's a problem with warning and critical thresholds... arguments must contain + and - signs...

for example, this works:
cscript.exe //T:30 //NoLogo scripts\check_time.vbs +5 +10
NTP CRITICAL: Offset +62.0905029 secs|offset=+62.0905029s;+5;+10;

this doesn't:
cscript.exe //T:30 //NoLogo scripts\check_time.vbs 5 10
NTP OK: Offset +62.0866201 secs|offset=+62.0866201s;5;10;

best regards, Federico