Windows boot time

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
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Windows boot time

Post by Kris »

Hiya all,

I'm trying to figure out how to create a test that goes bad when the last boot time of a Windows machine is less than one hour ago.

I do have a test that shows the Windows boot time.
This test is based on a VBscript, and gives the exact value in readable format.

There must be a better way I think.

Anyone ever achieved this?

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

Post by KS-Soft Europe »

You may use Shell Script test for custom tests.
May we see your script?

Please check for details at:
http://www.ks-soft.net/hostmon.eng/mfra ... m#chkShell
http://www.ks-soft.net/hostmon.eng/mfra ... hellscript
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

LOL no, I want an alert when the last boot time was less than an hour ago :)

This is the script that returns the last boot time value....

Code: Select all

option explicit 

const statusAlive       = "scriptRes:Host is alive:" 
const statusDead        = "scriptRes:No answer:" 
const statusUnknown     = "scriptRes:Unknown:" 
const statusNotResolved = "scriptRes:Unknown host:" 
const statusOk          = "scriptRes:Ok:" 
const statusBad         = "scriptRes:Bad:" 
const statusBadContents = "scriptRes:Bad contents:" 

dim strComputer, performtest, objArgs, objWMIService, colOperatingSystems, dtmBootup, dtmLastBootupTime, dtmSystemUptime, objOS 

Set objArgs = WScript.Arguments 

strComputer = "." 
if objArgs.Count>0 then 
  strComputer = objArgs(0) 
end if 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
Set colOperatingSystems = objWMIService.ExecQuery _ 
    ("Select * from Win32_OperatingSystem") 
  
For Each objOS in colOperatingSystems 
    dtmBootup = objOS.LastBootUpTime 
    dtmLastBootupTime = WMIDateStringToDate(dtmBootup) 
Next 

Wscript.stdout.write statusOK 
WScript.StdOut.Write dtmLastBootupTime 

Function WMIDateStringToDate(dtmBootup) 
    WMIDateStringToDate = CDate(Mid(dtmBootup, 7, 2) & "/" & _ 
        Mid(dtmBootup, 5, 2) & "/" & Left(dtmBootup, 4) _ 
            & " " & Mid (dtmBootup, 9, 2) & ":" & _ 
                Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2)) 
End Function
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

This script can be modified like the following:

Code: Select all

option explicit 
On Error Resume Next
Err.Clear

const statusUnknown     = "scriptRes:Unknown:" 
const statusOk          = "scriptRes:Ok:" 
const statusBad         = "scriptRes:Bad:" 

dim strComputer, performtest, objArgs, objWMIService, colOperatingSystems, dtmBootup, dtmLastBootupTime, objOS, diff, val

Set objArgs = WScript.Arguments 

strComputer = "." 
val = 60

if objArgs.Count=1 then 
  val = CInt(objArgs(0))
end if 

if objArgs.Count=2 then 
  strComputer = objArgs(0) 
  val = CInt(objArgs(1))
end if 

Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") 
Set colOperatingSystems = objWMIService.ExecQuery _ 
    ("Select * from Win32_OperatingSystem") 

if  Err.Number <> 0  then
  WScript.StdOut.Write statusUnknown & Err.Description
  WScript.Quit
End if
  
For Each objOS in colOperatingSystems 
    dtmBootup = objOS.LastBootUpTime 
    dtmLastBootupTime = WMIDateStringToDate(dtmBootup) 
Next 

if  Err.Number <> 0  then
  WScript.StdOut.Write statusUnknown & Err.Description
  WScript.Quit
End if

diff = datediff("n",dtmLastBootupTime,Now)

if diff<val then
  Wscript.stdout.write statusBad & diff
else
  Wscript.stdout.write statusOk & diff
end if

Function WMIDateStringToDate(dtmBootup) 
    WMIDateStringToDate = CDate(Mid(dtmBootup, 7, 2) & "/" & _ 
        Mid(dtmBootup, 5, 2) & "/" & Left(dtmBootup, 4) _ 
            & " " & Mid (dtmBootup, 9, 2) & ":" & _ 
                Mid(dtmBootup, 11, 2) & ":" & Mid(dtmBootup,13, 2)) 
End Function
Scritp requires zero, one or two parameters:
0 parameters - checks local system boot time. Threshold = 60 min
1 parameter - checks local system boot time. Threshold = first parameter
2 parameters - checks remote system (1 parameter). Threshold = second parameter.
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

Hmmm doesn't work straight out of the box, might need some tweaking...
Did you actually test this? And did it work for you?
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Did you actually test this? And did it work for you?
Sure. It works on our system.
What is test Status and Reply field?
What parameters have you specified for the test?
What Start CMD do you use for VB Script
(should be: cmd /c cscript /B /E:VBScript %Script% %Params%)
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

It does run, however I get the following result on a server that was booted about 4 hours ago...

Code: Select all

[4:15:05 PM] HostMonitor is going to execute "SYSTEM: Last Boot - copy" script ...
[4:15:05 PM] Script executed, correct result received:
----------
- Status: Bad
- Reply: -341051
----------
KS-Soft Europe
Posts: 2832
Joined: Tue May 16, 2006 4:41 am
Contact:

Post by KS-Soft Europe »

Looks like function WMIDateStringToDate depends on local date/time format. That's why it works on our system and may not work on systems with different date/time format.

May be it's better to use SNMP GET test with the following settings:
Alert when OID 1.3.6.1.2.1.1.3.0 is < than 360000
Kris
Posts: 375
Joined: Wed May 12, 2010 3:22 am

Post by Kris »

What a coincidence, that's just what I was thinking! :lol:

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

Post by KS-Soft Europe »

You are welcome!
Post Reply