|
View previous topic :: View next topic |
Author |
Message |
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Fri Sep 23, 2016 5:57 am Post subject: 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 |
|
Back to top |
|
|
KS-Soft
Joined: 03 Apr 2002 Posts: 12795 Location: USA
|
Posted: Fri Sep 23, 2016 8:03 am Post subject: |
|
|
Is there SNMP service running on the server?
Then you can use NTP test method
Regards
Alex |
|
Back to top |
|
|
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Fri Sep 23, 2016 8:07 am Post subject: |
|
|
Quote: | Is there SNMP service running on the server? |
yes there is ..
do you know the OID ?
menno |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Fri Sep 23, 2016 8:31 am Post subject: |
|
|
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/mframe.htm#tests.htm#ntp |
|
Back to top |
|
|
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Fri Sep 23, 2016 8:52 am Post subject: |
|
|
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
Code: | cmd /c cscript /B /E:VBScript %Script% %Params% |
the script
Code: |
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
|
|
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Fri Sep 23, 2016 8:54 am Post subject: |
|
|
Or you may use Shell Script test with the following VB Script:
Code: | 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 |
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} |
|
Back to top |
|
|
menno
Joined: 21 May 2010 Posts: 157
|
Posted: Sun Sep 25, 2016 3:47 am Post subject: |
|
|
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 :
Code: |
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
----------
|
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
Code: |
[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
----------
|
and with parameters (22.22.22.22 10)
Code: |
[11:43:48] Agent: ECHOXPERT is going to execute "TimeCheck" script ...
[11:43:48] Script executed, correct result received:
----------
- Status: Ok
- Reply: 0
----------
|
after changing the time back ..the normal output ( just time check . no parameters) gives :
Code: |
[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
---------- |
can you help me out here ...
many thanks in advanve
menno |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Mon Sep 26, 2016 10:20 am Post subject: |
|
|
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 |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|