Windows boot time
Windows boot time
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!
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!
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
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
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
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....

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
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
This script can be modified like the following:
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.
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
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.
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
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
----------
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact:
-
- Posts: 2832
- Joined: Tue May 16, 2006 4:41 am
- Contact: