|
View previous topic :: View next topic |
Author |
Message |
Kris
Joined: 12 May 2010 Posts: 375
|
Posted: Tue Mar 11, 2014 7:10 am Post subject: 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! |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
|
Back to top |
|
|
Kris
Joined: 12 May 2010 Posts: 375
|
Posted: Tue Mar 11, 2014 7:41 am Post subject: |
|
|
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: |
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
|
|
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Tue Mar 11, 2014 8:21 am Post subject: |
|
|
This script can be modified like the following:
Code: | 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. |
|
Back to top |
|
|
Kris
Joined: 12 May 2010 Posts: 375
|
Posted: Tue Mar 11, 2014 8:59 am Post subject: |
|
|
Hmmm doesn't work straight out of the box, might need some tweaking...
Did you actually test this? And did it work for you? |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Tue Mar 11, 2014 9:09 am Post subject: |
|
|
Quote: | 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%) |
|
Back to top |
|
|
Kris
Joined: 12 May 2010 Posts: 375
|
Posted: Tue Mar 11, 2014 9:17 am Post subject: |
|
|
It does run, however I get the following result on a server that was booted about 4 hours ago...
Code: | [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
---------- |
|
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Tue Mar 11, 2014 9:54 am Post subject: |
|
|
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 |
|
Back to top |
|
|
Kris
Joined: 12 May 2010 Posts: 375
|
Posted: Wed Mar 12, 2014 2:09 am Post subject: |
|
|
What a coincidence, that's just what I was thinking!
Thanks!
Kris |
|
Back to top |
|
|
KS-Soft Europe
Joined: 16 May 2006 Posts: 2832
|
Posted: Wed Mar 12, 2014 9:43 am Post subject: |
|
|
You are welcome! |
|
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
|