Tiime on server check

All questions related to installations, configurations and maintenance of Advanced Host Monitor (including additional tools such as RMA for Windows, RMA Manager, Web Servie, RCC).
Post Reply
menno
Posts: 158
Joined: Fri May 21, 2010 1:27 am

Tiime on server check

Post by menno »

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
KS-Soft
Posts: 13012
Joined: Wed Apr 03, 2002 6:00 pm
Location: USA
Contact:

Post by KS-Soft »

Is there SNMP service running on the server?
Then you can use NTP test method

Regards
Alex
menno
Posts: 158
Joined: Fri May 21, 2010 1:27 am

Post by menno »

Is there SNMP service running on the server?
yes there is ..
do you know the OID ?

menno
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

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
menno
Posts: 158
Joined: Fri May 21, 2010 1:27 am

Post by menno »

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: Select all

cmd /c cscript /B /E:VBScript %Script% %Params%
the script

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

KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Or you may use Shell Script test with the following VB Script:

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
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}
menno
Posts: 158
Joined: Fri May 21, 2010 1:27 am

Post by menno »

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: 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
----------
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: 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
----------
and with parameters (22.22.22.22 10)

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
----------
after changing the time back ..the normal output ( just time check . no parameters) gives :

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
----------
can you help me out here ...

many thanks in advanve
menno[/i]
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

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
Post Reply