KS-Soft. Network Management Solutions
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister    ProfileProfile    Log inLog in 

Windows boot time

 
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting
View previous topic :: View next topic  
Author Message
Kris



Joined: 12 May 2010
Posts: 375

PostPosted: Tue Mar 11, 2014 7:10 am    Post subject: Windows boot time Reply with quote

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
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Tue Mar 11, 2014 7:34 am    Post subject: Reply with quote

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/mframe.htm#tests.htm#chkShell
http://www.ks-soft.net/hostmon.eng/mframe.htm#tests.htm#createshellscript
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Kris



Joined: 12 May 2010
Posts: 375

PostPosted: Tue Mar 11, 2014 7:41 am    Post subject: Reply with quote

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
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Tue Mar 11, 2014 8:21 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Kris



Joined: 12 May 2010
Posts: 375

PostPosted: Tue Mar 11, 2014 8:59 am    Post subject: Reply with quote

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
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Tue Mar 11, 2014 9:09 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Kris



Joined: 12 May 2010
Posts: 375

PostPosted: Tue Mar 11, 2014 9:17 am    Post subject: Reply with quote

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
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Tue Mar 11, 2014 9:54 am    Post subject: Reply with quote

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
View user's profile Send private message Send e-mail Visit poster's website
Kris



Joined: 12 May 2010
Posts: 375

PostPosted: Wed Mar 12, 2014 2:09 am    Post subject: Reply with quote

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

Thanks!
Kris
Back to top
View user's profile Send private message
KS-Soft Europe



Joined: 16 May 2006
Posts: 2832

PostPosted: Wed Mar 12, 2014 9:43 am    Post subject: Reply with quote

You are welcome!
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    KS-Soft Forum Index -> Configuration, Maintenance, Troubleshooting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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

KS-Soft Forum Index