NTP and Time

Windows time check against NTPD (check_time.vbs)

Description:

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)

Current Version

Last Release Date

February 1, 2010

Compatible With


Project Files
Project Notes
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] Options: 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) Add a Review
Patch proposals
by supportex.net, June 30, 2015
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"
Else
Err = 0
status = "OK"
End If
Helpful? Yes  No 
returned an invalid return code: 128
by Brick, April 30, 2013
This script runs fine and works properly but every once in a while it returns this error-

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

I can't see anything wrong in the script itself... has anyone had a similar problem?
Helpful? Yes  No 
Problem on Server 2008 R2
by Lee-TIC, March 31, 2012
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?
Helpful? Yes  No 
With decimal symbol different of "."
by Cyril, December 31, 2011
I just and :

SetLocale("en-us")

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
Helpful? Yes  No 
Two more things
by egalstad, May 31, 2011
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%System32w32tm.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"
Else
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"
Else
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.

Regards
Phil
2 of 2 found this review helpful.
Helpful? Yes 2 No 0
a couple of things
by Freddy, December 31, 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 scriptscheck_time.vbs 10.65.0.100 +5 +10
NTP CRITICAL: Offset +62.0905029 secs|offset=+62.0905029s;+5;+10;

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


best regards, Federico
Helpful? Yes  No 
Add a Review

You must be logged in to submit a review.

Thank you for your review!

Your review has been submitted and is pending approval.

Recommend

To:


From:


Thank you for your recommendation!

Your recommendation has been sent.

Project Stats
Rating
3.9 (8)
Favorites
0
Views
180,065