monitors:winuptime

Windows Uptime

Author Craig Boyce
Compatibility Xymon 4.2
Requirements Windows, BBWin
Download None
Last Update 2007-07-16

A .vbs script that works with bbwin that you can use to alert when a client exceeds a specified number of days without a restart.

Client side

  1. Copy the script to the bbwin\ext directory or any sub directory you would prefer.
  2. Update the bbwin\etc\bbwin.cfg externals section to include the script as per below making sure the path is correct.
    <externals>
    	<setting name="timer" value="3m" />
    	<setting name="logstimer" value="60s" />
    	<load value="cscript //B ..\ext\Uptime.vbs" timer="5m" /> 
    </externals>

The script allows the changing of the test column name and uptime duration before alerting by changing the following lines in the script.

strTestName = “uptime” Change this to what you want the test column to be.
strUpTime = “30” Change this to the length of time required before alerting a reboot is required.

Server side

  • None

Show Code ⇲

Hide Code ⇱

'==========================================================================
' NAME: Uptime.vbs
' COMMENT: Check Uptime of server and report if greater than 30 days
' AUTHOR: Craig Boyce, Rodney District Council
' EMAIL: craig.boyce@rodney.govt.nz
' DATE  : 30/10/2006
' VERSION : 2.00
'==========================================================================
 
On Error Resume Next
 
Dim objShell, objWMIService, WSHNetwork
Dim ServerName, strTestName, strAlarmState, strUpTime, strOutput
Dim logmessage, logfile, fso, f
 
' Set Variables
 
Set objShell = WScript.CreateObject("WScript.Shell")
Set WSHNetwork = WScript.CreateObject("WScript.Network")
 
ServerName = objShell.ExpandEnvironmentStrings("%COMPUTERNAME%")
 
strTestName = "uptime" ' Change this to what you want the test column to be.
strUpTime = 30 ' Change this to the length of time required before alerting a reboot is required.
 
strAlarmState = "green"
strOutput   = ""
 
' Check to see If used with BBWin or Big Brother client and set extPath.
extPath = objShell.RegRead("HKLM\SOFTWARE\BBWin\tmpPath")
If extPath = "" Then
	extPath = objShell.RegRead("HKLM\SOFTWARE\Quest Software\BigBrother\bbnt\ExternalPath\")
End If
 
' ========================================
' Main Code Starts Here
 
strComputer = "."   ' "." for local computer 
 
On Error Resume Next 
Set objWMIService = GetObject("winmgmts:" & "{impersonationLevel=impersonate}!\\" & strComputer & "\root\cimv2") 
 
If Err.Number = 0 Then 
     On Error Goto 0 
     strQuery = "select * from Win32_PerfRawData_PerfOS_System" 
     Set colObjects = objWMIService.ExecQuery(strQuery) 
 
 
     For Each objWmiObject In colObjects 
       intPerfTimeStamp = objWmiObject.Timestamp_Object 
       intPerfTimeFreq = objWmiObject.Frequency_Object 
       intCounter = objWmiObject.SystemUpTime 
     Next 
 
     ' Calculation in seconds: 
     'Calculations for Raw Counter Data:PERF_ELAPSED_TIME 
     'http://msdn.microsoft.com/library/en-us/perfmon/base/perf_elapsed_tim... 
     iUptimeInSec = (intPerfTimeStamp - intCounter)/intPerfTimeFreq 
 
     ' convert the seconds 
     sUptime = ConvertTime(iUptimeInSec)
 
	If CInt(Left(sUptime, 2)) > CInt(strUpTime) Then
		strOutput = strOutput & "Uptime: " & sUptime & "exceeds " & strUpTime & " Days , This Server needs to be scheduled for a monthly restart"
		strAlarmState = "red"
	Else
		strOutput = strOutput & "Uptime: " & sUptime
		strAlarmState = "green"
	End If
 
End If 
 
' Write the file for BB
WriteFile extPath, strTestName, strAlarmState, strOutput
 
'===========================================================
' FUNCTIONS and SUBS start here
 
' This SUB is used for outputting the file to the external's directory in bb
 
SUB WriteFile(strExtPath, strTestName, strAlarmState, strOutput)
    Set fso = CreateObject("Scripting.FileSystemObject")	
    strOutput = strAlarmState & " " & Date & " " & Time & vbcrlf & vbcrlf & strOutput & vbcrlf
    Set f = fso.OpenTextFile(strExtPath & "\" & strTestName , 8 , TRUE)
    f.Write strOutput
    f.Close
    Set fso = Nothing
END Sub
 
Function ConvertTime(seconds) 
     ConvSec = seconds Mod 60 
     ConvMin = (seconds Mod 3600) \ 60 
     ConvHour =  (seconds Mod (3600 * 24)) \ 3600 
     ConvDays =  seconds \ (3600 * 24) 
     ConvertTime = ConvDays & " days " & ConvHour & " hours " & ConvMin & " minutes " 
End Function
  • None
  • 2007-07-16
    • Initial release
  • monitors/winuptime.txt
  • Last modified: 2009/11/23 06:13
  • by 127.0.0.1