mickem / nscp

NSClient++
http://nsclient.org
GNU General Public License v2.0
239 stars 94 forks source link

scripts\op5\check_time.vbs needs to be updated #707

Open candergart opened 3 years ago

candergart commented 3 years ago

Issue and Steps to Reproduce

op5-command check_time is broken.

This vbs-script defined in the commands is running a windows executable with arguments and parses the output.

In the vbs-script, there is a string match for the text "NTP" in the output from the windows command. Somewhere around row 43 or so.

The output of the windows executable is : C:\Users\test>C:\windows\system32\w32tm.exe /monitor /computers:ntp.swip.net


ntp.swip.net[130.244.0.42:123]: ICMP: 29ms delay NTP: +0.6606963s offset from local clock RefID: bck-core-1.tele2.net [130.244.0.72] Stratum: 3

Warning: Reverse name resolution is best effort. It may not be correct since RefID field in time packets differs across NTP implementations and may not be using IP addresses.


Problem 1: The string match catches the last row about NTP implementations instead of the actual row containing the offset information.

Solution 1 If I edit the match from NTP to "NTP:" (Adding colon to it), then it starts to work fine for me.

Problem 2: There is a date/number-format issue also. On some servers, the code expects decimals to be separated by comma, on others by a single dot.

Solution 2 Add a replace function on a new row before "If (Left(dir, 1)" .. somewhere around row 80-82 or so. The new row should be : result = Replace(result,".",Mid(1.3, 2, 1))

This "should" hopefully fix it.

I have uploaded my edit of the vbs-script to this issue.

PLEASE PROVIDE COMMAND HERE

From op5.ini check_time = cscript.exe //T:30 //NoLogo scripts\op5\check_time.vbs $ARG1$ $ARG2$

Expected Behavior

The ntp check should work and give an output similar to NTP OK: Offset -0,706864 secs|'offset:'=0 '-0,706864'=0

Actual Behavior

Result from Problem 1: C:\Program Files\NSClient++\scripts\op5\check_time.vbs(75, 3) Microsoft VBScript runtime error: Type mismatch: 'CDbl'

Result from Problem 2 (After fixing problem 1) NTP CRITICAL: Offset -6937897 secs|'offset:'=0 '-6937897'=0

Details


I am uploading my version here: 
I would love if someone else could test and verify if it works for you too.
[check_time.zip](https://github.com/mickem/nscp/files/5566502/check_time.zip)

check_nrpe example:
./check_nrpe -H <hostaddress> -c check_time -a <some ntp server> <offset in seconds for alarm>

Best Regards
Charlie Candergart
candergart commented 3 years ago

check_time.zip