VBscript to view UPS specs

Hi folks!

I need a a script to monitor our customer's UPSses, i did found something but i can't understand it. We have to get the information by snmp (or by the APC powerchute software)
' ///////////////////////////////////////////////////////////////////////////////
' // ActiveXperts Network Monitor - VBScript based checks
' ///////////////////////////////////////////////////////////////////////////////
' 
 
' For RFC-1628 compliant UPS, consider this the generic script base
' http://www.faqs.org/rfcs/rfc1628
' http://support.ipmonitor.com/mibs/UPS-MIB/tree.aspx
 
' Script-based checks for Uninterrupted Power Supplies. We hardcode the OID's here 
' so we don't have to type them in over and over and over in the interface.
' It's just a matter of selecting the test name from a dropdown.
 
Option Explicit
Const retvalUnknown = 1
Dim snmp_value 
 
' Worthwhile constants, ie THRESHOLDS to panic over
Const RFCMinBattTime = 5 ' in Minutes
Const RFCMaxTemp = 120 ' in Fahrenheit
 
'//////////////////////////////////////////////////////////////////////////////
Function RFCstatusBatt ( host )
 
' Description: 
' Checks to see the status of the RFC Compliant UPS battery
' Parameters:
' host - the IP address of the management card on the UPS
' On Error Resume Next
 
'sets Unknown state if neccesary
 
snmp_value = CheckSNMP(host, "public", ".1.3.6.1.2.1.33.1.2.1")
 
if (snmp_value = "") then
RFCstatusBatt = retvalUnknown
Exit Function
End if
 
If (snmp_value = 2) Then
Explanation = "Battery is Normal"
RFCstatusBatt = True
ElseIf (snmp_value = 3) Then
Explanation = "Battery is Low"
RFCstatusBatt = False
ElseIf (snmp_value = 4) Then
Explanation = "Battery is depeleted"
RFCstatusBatt = False
Else
Explanation = "Unknown Battery Status"
RFCstatusBatt = retvalUnknown
End If
End Function
 
'/////////////////////////////////////////////////////////////////////
Function RFCTimeRemaining ( host, minruntime )
' Description:
' Checks available runtime on RFC Compliant UPS Battery upon outage
' Parameters:
' host - the IP address of the management card on the UPS
' minruntime - Time in minutes battery should be capable of running for.
' On Error Resume Next
 
' Below is an optional setting that passes a 5 minute default to minruntime
If ( minruntime = "" ) Then
minruntime = RFCMinBattTime
End If
 
snmp_value = CheckSNMP(host, "public", ".1.3.6.1.2.1.33.1.2.3") ' upsEstimatedMinutesRemaining
 
if (SNMP Value = "") then
RFCTimeRemaining = retvalunknown
Exit Function
End If
 
if (snmp_value < minruntime) then
Explanation = "Battery Runtime Capacity Too Low: " & snmp_value & " mins"
RFCTimeRemaining = False
ElseIf (snmp_value >= minruntime) then
Explanation = "Battery Runtime Capacity OK: " & snmp_value & " mins"
RFCTimeRemaining = True
Else
Explanation = "Unknown Battery Runtime Status"
RFCTimeRemaining = retvalunknown
End if
End Function
 
'///////////////////////////////////////////////////////////////////////////////
Function RFConBattery( host )
' Description:
' While there is no query that will tell us that the RFC Compliant UPS is on Battery
' This script will alert us if the UPS has been running on Battery for 30 Seconds
' Parameters:
' host - the IP address of the management card on the UPS
 
snmp_value = CheckSNMP(host, "public", ".1.3.6.1.2.1.33.1.2.2") ' upsSecondsOnBattery
if (snmp_value = "") then
RFConBattery = retvalUnknown
Exit Function
End if
 
if (snmp_value = 0) then
Explanation = "UPS Running on Wall/AC Power"
RFConBattery = True
Elseif (snmp_value >= 30) then
Explanation = "UPS RUNNING ON BATTERY" & snmp_value & " Seconds"
RFConBattery = False
Else
Explanation = "Unknown Battery Operational Status"
RFConBattery = retvalunknown
End if
 
End Function
 
'////////////////////////////////////////////////////////////////////////////////
 
Function RFCUPSHeat( host, maxtemp )
' Description:
' Checks to see if the Internal Batteries are cool, or roasting
' Parameters:
' host - the IP address if the management card on the UPS
' maxtemp - Maximum temperature for the UPS Batteries (Default 120 degrees)
 
' Sets maxtemp to a 120 F degree default if no maxtemp is specified
if (maxtemp = "") then
maxtemp=RFCMaxTemp
End If
 
'Checks temperature and converts Celcius Units to Fahrenheit
 
snmp_value = CheckSNMP(host, "public", ".1.3.6.1.2.1.33.1.2.7.0") 'upsBatteryTemperature
 
If (snmp_value = "") then
RFCUPSHeat = retvalunknown
Exit Function
End If
 
snmp_value = cel2fahr(snmp_value) ' converts to fahrenheit
 
if (snmp_value > maxtemp) then
Explanation = "Battery Temperature TOO HOT: " &snmp_value & " Fahrenheit"
RFCUPSHeat = False
ElseIf (smp_value <= maxtemp) then
Explanation = "Batery Temperature OK: " &snnp_value & " Fahrenheit"
RFCUPSHeat = True
Else
Explanation = "Unknown Battery Temperature Status"
RFCUPSHeat = retvalunknown
End If
 
End Function
 
 
' //////////////////////////////////////////////////////////////////////////////
' // Support Functions
' //////////////////////////////////////////////////////////////////////////////
 
Function CheckSnmp( strAgent, strCommunity, strOID )
 
' Description: 
' Connect to the (remote) SNMP agent, read the OID value and match it
' *** WARNING: THIS FUNCTION HAS BEEN MODIFIED, DO NOT ERASE ***
' Parameters:
' strAgent - Host name or IP address of the (remote) SNMP agent
' strCommunity - Community string. Default: "public"
' strOID - Retrieve value of this OID. 
' Sample:
' CheckSnmp( "localhost", "public", "1.3.6.1.2.1.1.5.0", "MYSERVER" )
 
' On Error Resume Next
 
Dim objSnmp, strValue, ErrorIndex, Result, snmpvar, oidvar
 
' Create instance of SNMP object
Set objSnmp = CreateObject("SScripting.SNMPManager")
 
objSnmp.Agent = strAgent
objSnmp.Community = strCommunity
Call objSnmp.Variables.Add( strOID )
Result = objSnmp.Get( ErrorIndex )
If (Result = 10) Then 
EXPLANATION = "ERROR: " & ErrorIndex 
Exit Function
End If
 
strValue = objSnmp.Variables(1).Value
CheckSNMP = strValue
 
End Function
 
' //////////////////////////////////////////////////////////////////////////////
 
Function CheckSnmpOrig( strAgent, strCommunity, strOID )
 
' Description: 
' Connect to the (remote) SNMP agent, read the OID value and match it
' *** WARNING: THIS FUNCTION HAS BEEN MODIFIED, DO NOT ERASE ***
' Parameters:
' strAgent - Host name or IP address of the (remote) SNMP agent
' strCommunity - Community string. Default: "public"
' strOID - Retrieve value of this OID. 
' Sample:
' CheckSnmp( "localhost", "public", "1.3.6.1.2.1.1.5.0", "MYSERVER" )
 
' On Error Resume Next
 
Dim objSnmp, strValue
 
' Create instance of SNMP object
Set objSnmp = CreateObject("ActiveXperts.Snmp")
 
' Initialize SNMP object
objSnmp.Initialize
If( objSnmp.LastError <> 0 ) Then
EXPLANATION = "Unable to initialize ActiveSocket SNMP object"
CheckSnmp = retvalUnknown
Exit Function
End If
 
Dim Retries : Retries = 5
Dim Failed
 
Do
Failed = 0
' Open connection to (remote) SNMP agent
objSnmp.Open strAgent, strCommunity
If( objSnmp.LastError <> 0 ) Then
EXPLANATION = "Unable to connect to agent [" & strAgent & "] in [" & strCommunity & "] community. Be sure SNMP agent is running"
CheckSnmp = retvalUnknown
Retries = Retries - 1
Failed = 1
Else
strValue = objSnmp.Get( strOID )
CheckSnmp = strValue
If( objSnmp.LastError <> 0 ) Then
EXPLANATION = "Unable to retrieve [" & strOID & "]. . Be sure SNMP agent is running AND CHECK ACCESS CONTROL!"
Retries = Retries - 1
Failed = 1
End If
End If
Loop While Failed = 1 And Retries > 0
 
objSnmp.Close()
objSnmp.Shutdown()
 
End Function
 
 
 
Function cel2fahr(celsius)
 
cel2fahr = (celsius * 9 / 5) + 32
 
End Function
 
 
 
Function Regexget(str, pattern)
 
Dim reg : Set reg = New RegExp
reg.Pattern = pattern
Dim matches : Set matches = reg.Execute(str)
If (matches.count > 0) Then
Regexget = matches(0).value
Else
Regexget = ""
End If 
 
End Function

Open in new window

DutchictAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ladarlingCommented:
This script is pretty well documented. It is apparently designed to be called from a web  browser based interface.  In order to use it, you will need the:
Set objSnmp = CreateObject("SScripting.SNMPManager")
Set objSnmp = CreateObject("ActiveXperts.Snmp")
COM objects specified registered on the target system (Lines 175 and 210 of the code).
How are you trying to use the script above?
0
DutchictAuthor Commented:
I am not, i didn't know how it worked :(  (yes i know, newbee)

We are still in search of creating a statusreport by VBscript on a APC UPS. But there is so little to find on that. The only real script is this one.

I want to embed the code in my existing HTA, in wich we are monitoring all other kinds of data, like diskspace, memory, cpu etc.

Thanks!

0
ladarlingCommented:
I am not, i didn't know how it worked :(  (yes i know, newbee)
Cool, no problem, thats what we dont get paid for, lol.
Anyway, the script you posted apparently does what you are looking for: it checks APC runtime and temperature, for example. However, it is apparently dependent on at least one of the third-party objects I mentioned above. The SScripting DLL is freeware:
http://cwashington.netreach.net/main/library/SScrRun.html
 The ActiveXperts Scripting Toolkit is not, however:
http://www.activexperts.com/sales/
Judging from the way the functions are layed out, you may be able to approximate the functionality of the script above using just the freeware tool. Ill investigate the script a little close and get back to you on that.
0
DutchictAuthor Commented:
Cool, thanks in advance, and yes, we don't get paid for answers, but we do share knowledge and respect. A new member with thesame question could get there answer here :)

So, respect!
0
DutchictAuthor Commented:
We have currently loaded MIBs for UPSs into our monitoring software (Kaseya) and are reading SNMP values this way for a UPS.

Therefore we no longer need a VBscript.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.