Tiime on server check
Tiime on server check
Hello HM team
Can you help me with the following...
We need a test script thats comparing the checked server time with the HM server time.
I was busy with the Win32_LocalTime on the remote server but i do not know how to compare it with the HM server time.
Is there a way to do that ?
off course there can be a small time difference but the max must be 5min (or so )
Can your team help me please with such a script ?
Many many thanks in advance
Menno
Can you help me with the following...
We need a test script thats comparing the checked server time with the HM server time.
I was busy with the Win32_LocalTime on the remote server but i do not know how to compare it with the HM server time.
Is there a way to do that ?
off course there can be a small time difference but the max must be 5min (or so )
Can your team help me please with such a script ?
Many many thanks in advance
Menno
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
I think Alex ment NTP service (or Windows Time service).
If this service is configured and running on target system, HostMonitor may retrieve time from remote host and compare it with time on HostMonitor system.
You need to configure Windows Time Service using Group Policy Object Editor (Start -> Run -> gpedit.msc, then click Computer Configuration -> Administrative Templates -> System, click Windows Time Service and enable Global Configuration Settings, configure Windows Time Providers and enable Windows NTP Server).
Please check for details at:
http://www.ks-soft.net/hostmon.eng/mfra ... ts.htm#ntp
If this service is configured and running on target system, HostMonitor may retrieve time from remote host and compare it with time on HostMonitor system.
You need to configure Windows Time Service using Group Policy Object Editor (Start -> Run -> gpedit.msc, then click Computer Configuration -> Administrative Templates -> System, click Windows Time Service and enable Global Configuration Settings, configure Windows Time Providers and enable Windows NTP Server).
Please check for details at:
http://www.ks-soft.net/hostmon.eng/mfra ... ts.htm#ntp
i managed to create a script that is displaying the local time of the server
if i run it in my CMD box on my local machine it goes OK
but if i run it in HM as a vbscript it receives no output
can you help me out here ???
start cmd
the script
if i run it in my CMD box on my local machine it goes OK
but if i run it in HM as a vbscript it receives no output
can you help me out here ???
start cmd
Code: Select all
cmd /c cscript /B /E:VBScript %Script% %Params%
Code: Select all
Option Explicit
const statusAlive = "Host is alive:"
const statusDead = "No answer:"
const statusUnknown = "Unknown:"
const statusNotResolved = "Unknown host:"
const statusOk = "Ok:"
const statusBad = "Bad:"
const statusBadContents = "Bad contents:"
Dim strComputer, objWMIService, colItems, objItem
strComputer = "."
Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2")
Set colItems = objWMIService.ExecQuery("Select * from Win32_LocalTime")
For Each objItem in colItems
WScript.StdOut.Write objItem.Hour &":"& objItem.Minute &"."& objItem.Second
Next
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
Or you may use Shell Script test with the following VB Script:
Start cmd: cmd /c cscript /B /E:VBScript %Script% %Params%
Script requires 1,2,3 or 4 parameters.
Parameters may look like the following:
10.8.0.32 {check time on 10.8.0.32}
10.8.0.32 5 {check time on 10.8.0.32 and compare to local. Set Bad status if difference is more than 5 sec}
10.8.0.32 5 admin adminpassword {same as previous, but with login/password}
10.8.0.32 admin adminpassword {check time on 10.8.0.32 using login/password}
Code: Select all
Option Explicit
On Error Resume Next
Err.Clear
const statusUnknown = "scriptRes:Unknown:"
const statusOk = "scriptRes:Ok:"
const statusBad = "scriptRes:Bad:"
Dim objSWbemLocator, objWMIService, objItem, colItems, strComputer, strUser, strPsw, remote_time, objArgs, dd, alert, rd
Set objArgs = WScript.Arguments
strUser = ""
strPsw = ""
alert = 0
If objArgs.Count = 1 then
strComputer = objArgs(0)
elseif objArgs.Count = 2 then
strComputer = objArgs(0)
alert = int(objArgs(1))
elseif objArgs.Count = 3 then
strComputer = objArgs(0)
strUser = objArgs(1)
strPsw = objArgs(2)
elseif objArgs.Count = 4 then
strComputer = objArgs(0)
alert = int(objArgs(1))
strUser = objArgs(2)
strPsw = objArgs(3)
else
WScript.StdOut.Write statusUnknown & "Required parameters are: <hostname> [<time difference in sec.>] [<username> <password>]"
WScript.Quit
end if
Set objSWbemLocator = CreateObject("WbemScripting.SWbemLocator")
if Err.Number <> 0 then
WScript.StdOut.Write statusUnknown & Err.Description
WScript.Quit
End if
Set objWMIService = objSWbemLocator.ConnectServer(strComputer, "root\cimv2", strUser, strPsw)
if Err.Number <> 0 then
WScript.StdOut.Write statusUnknown & Err.Description
WScript.Quit
End if
Set colItems = objWMIService.ExecQuery("Select * From Win32_LocalTime")
if Err.Number <> 0 then
WScript.StdOut.Write statusUnknown & Err.Description
WScript.Quit
End if
For Each objItem in colItems
remote_time = objItem.Year & "-" & objItem.Month & "-" & objItem.Day & " " & objItem.Hour & ":" & objItem.Minute & ":" & objItem.Second
Next
rd = CDate(remote_time)
dd = DateDiff("s",Now,rd)
if alert = 0 then
WScript.StdOut.Write statusOk & rd
elseif (alert > 0) and (Abs(dd) > alert) then
WScript.StdOut.Write statusBad & dd
else
WScript.StdOut.Write statusOk & dd
end if
Script requires 1,2,3 or 4 parameters.
Parameters may look like the following:
10.8.0.32 {check time on 10.8.0.32}
10.8.0.32 5 {check time on 10.8.0.32 and compare to local. Set Bad status if difference is more than 5 sec}
10.8.0.32 5 admin adminpassword {same as previous, but with login/password}
10.8.0.32 admin adminpassword {check time on 10.8.0.32 using login/password}
Thanks but it does not work for me
i created a VB script test just like you showed me in the above example
UPDATE: 14:25
I found out why i have an issue , i changed the region settings on the server.
The reply is now the same a the HM server
Still if i set the remote server 10 seconds later or earlier the script still gives 0 as reply
No BAD or warning
The HM server gives : 25-9-2016 14:25:00 as reply
The remote server gives :25-9-2016 14:25:10 as reply
Still NO warning or Bad as status in HM
The paramaeters are : 22.22.22.22 5 ( so IP address of the remote server and 5 sec difference )
i think somthings wrong with the line : dd = DateDiff("s",Now,rd)
Can you please help me out here ...
many thanks in advance
OLD ISSUE:
my results :
It allways says OK.
i tried to set the clock on te remote server (in this case EXTERNAL-SERVER) two hours back but still it gives an OK back
and with parameters (22.22.22.22 10)
after changing the time back ..the normal output ( just time check . no parameters) gives :
can you help me out here ...
many thanks in advanve
menno[/i]
i created a VB script test just like you showed me in the above example
UPDATE: 14:25
I found out why i have an issue , i changed the region settings on the server.
The reply is now the same a the HM server
Still if i set the remote server 10 seconds later or earlier the script still gives 0 as reply
No BAD or warning
The HM server gives : 25-9-2016 14:25:00 as reply
The remote server gives :25-9-2016 14:25:10 as reply
Still NO warning or Bad as status in HM
The paramaeters are : 22.22.22.22 5 ( so IP address of the remote server and 5 sec difference )
i think somthings wrong with the line : dd = DateDiff("s",Now,rd)
Can you please help me out here ...
many thanks in advance
OLD ISSUE:
my results :
Code: Select all
Test by : Agent : EXTERNAL-SERVER
Params : 22.22.22.22 10
result:
[11:39:09] Agent: EXTERNAL-SERVER is going to execute "TimeCheck" script ...
[11:39:09] Script executed, correct result received:
----------
- Status: Ok
- Reply: 0
----------
i tried to set the clock on te remote server (in this case EXTERNAL-SERVER) two hours back but still it gives an OK back
Code: Select all
[11:43:05] Agent: EXTERNAL-SERVER is going to execute "TimeCheck" script ...
[11:43:05] Script executed, correct result received:
----------
- Status: Ok
- Reply: 9/25/2016 9:43:03 AM
----------
Code: Select all
[11:43:48] Agent: ECHOXPERT is going to execute "TimeCheck" script ...
[11:43:48] Script executed, correct result received:
----------
- Status: Ok
- Reply: 0
----------
Code: Select all
[11:41:16] Agent: EXTERNAL-SERVER is going to execute "TimeCheck" script ...
[11:41:16] Script executed, correct result received:
----------
- Status: Ok
- Reply: 9/25/2016 11:41:16 AM
----------
many thanks in advanve
menno[/i]
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
When only one parameter is specified (host IP), script will not check time difference. It only outputs time on remote system.
When second parameter is specified (max time difference), script should calculate time difference in seconds.
If remote time is displayed correctly, but difference is not calculated - issue
can be related to one of these lines:
rd = CDate(remote_time)
dd = DateDiff("s",Now,rd)
We tried on different systems with different time formats and script works well.
Could you try adding error checking after these lines:
rd = CDate(remote_time)
dd = DateDiff("s",Now,rd)
if Err.Number <> 0 then
WScript.StdOut.Write statusUnknown & Err.Description
WScript.Quit
End if
When second parameter is specified (max time difference), script should calculate time difference in seconds.
If remote time is displayed correctly, but difference is not calculated - issue
can be related to one of these lines:
rd = CDate(remote_time)
dd = DateDiff("s",Now,rd)
We tried on different systems with different time formats and script works well.
Could you try adding error checking after these lines:
rd = CDate(remote_time)
dd = DateDiff("s",Now,rd)
if Err.Number <> 0 then
WScript.StdOut.Write statusUnknown & Err.Description
WScript.Quit
End if