'*** '*** check_apcaccess.vbs '*** '*** Script to check the output of "apcaccess.exe status" '*** '*** Syntax: check_apcaccess.vbs /v:XXX [/w:YY.YY] [/c:ZZ.ZZ] '*** '*** Parameters: /v: Variable to check (ITEMP, STATUS etc.) '*** /w: Value for WARNING status (something like 30.0 or 19.5) '*** /c: Value for CRITICAL status (something like 30.0 or 19.5) '*** '*** Examples: check_apcaccess.vbs /v:LOADPCT /w:70.0 /c:80.0 '*** check_apcaccess.vbs /v:STATUS '*** check_apcaccess.vbs /v:TIMELEFT /w:10.0 /c:5.0 Dim strVariable, strStatus, strText, strOutput Dim arrStatus Dim strWarning, strCritical, strValue Dim objShell, objExec Dim bolVarFound Dim retValue Set objShell = CreateObject("WScript.Shell") Const strAPCACCESS = "C:\APCUPSD\BIN\APCACCESS.EXE" 'modify this to fit your environment Const retOK = 0 Const retWarning = 1 Const retCritical = 2 Const retUnknown = 3 retValue = retUnknown If Wscript.Arguments.Named.Exists("v") Then strVariable = WScript.Arguments.Named("v") strWarning = WScript.Arguments.Named("w") strCritical = WScript.Arguments.Named("c") Set objExec = objShell.Exec(strAPCACCESS & " status") Do While objExec.Status = 0 WScript.Sleep 100 Loop bolVarFound = False While (not objExec.StdOut.AtEndOfStream AND not bolVarFound) strStatus = objExec.StdOut.ReadLine arrStatus = Split(strStatus, ":", 2) strStatus = trim(arrStatus(1)) if trim(arrStatus(0)) = strVariable then strValue = trim(left(strStatus, inStr(strStatus, " "))) if strValue = "" then strValue = strStatus bolVarFound = True end if Wend if trim(strStatus) = "" then strOutput = "No status retrieved." retValue = retUnknown else Select Case UCase(strVariable) Case "ITEMP", "LOADPCT", "TONBATT" if CDbl(strValue) >= CDbl(strCritical) then strOutput = strOutput & "CRITICAL - " retValue = retCritical elseif CDbl(strValue) >= CDbl(strWarning) then strOutput = strOutput & "WARNING - " retValue = retWarning else strOutput = strOutput & "OK - " retValue = retOK end if Case "BCHARGE", "TIMELEFT" if CDbl(strValue) <= CDbl(strCritical) then strOutput = strOutput & "CRITICAL - " retValue = retCritical elseif CDbl(strValue) <= CDbl(strWarning) then strOutput = strOutput & "WARNING - " retValue = retWarning else strOutput = strOutput & "OK - " retValue = retOK end if Case "STATUS" if strValue = "ONLINE" then strOutput = strOutput & "OK - " retValue = retOK elseif strValue = "CHARGING" then strOutput = strOutput & "WARNING - " retValue = retWarning elseif strValue = "ONBATT" then strOutput = strOutput & "CRITICAL - " retValue = retCritical else strOutput = strOutput & "UNKNOWN - " retValue = retUnknown end if Case "SELFTEST" if strValue = "OK" or strValue = "NO" then strOutput = strOutput & "OK - " retValue = retOK elseif strValue = "BT" or strValue = "NG" then strOutput = strOutput & "CRITICAL - " retValue = retCritical else strOutput = strOutput & "UNKNOWN - " retValue = retUnknown end if Case Else strOutput = strOutput & "UNKNOWN - " retValue = retUnknown End Select end if strOutput = strOutput & strStatus & " (" & strValue & ")" WScript.Echo strOutput Else Wscript.Echo "Usage: check_apcacess /v:variable [/w:value for warning] [/c:value for critcal]" End If WScript.Quit(retValue)