[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [hobbit] UPS units



Hi Josh
 
Here they are, for what they are worth.
Please note
1. These are probably the ugliest scripts I have written in years. I
acknowledge that, and accept that. 
    They both started as a "Gee! Let's see if this works" and grew from
there. A horrible way to code.
2. I make no claims regarding fitness for purpose or correctness
3. They are to be used at your own risk. (Standard disclaimer of
liability applies)
4. They were written to monitor 2 different Models of the MGE Galaxy
range of UPS - they may work on others. YMMV.
5. The scripts, particularly the second one, illustrates my complete
ignorance of SNMP. Please do not judge me on that. :-)
 
The script runs on the server, and polls the UPS devices, so there needs
to be a route to the UPS.
The one talks to the device on port 80, pulling the data from the web
console.
The other uses snmp on the appropriate ports.
Make sure adequate firewall rules are in place.
 
The SNMP script uses the ksh string handling tools, which are unique to
ksh (and possibly bash)
Do not try and run this in sh - it will not work.
 
Have fun.
 
Cheers 
     V
 
In bb-hosts you need an entry like this
IP_Address    Host_name    # status_web_interface ups UPS_type
1.2.3.4   galaxy3000             # http://1.2.3.4/ups_prop.htm
<http://1.2.3.4/ups_prop.htm>  ups galaxy3000 COMMENT:"Level 3 UPS"
The keyword ups is important, because the script scans bb-hosts to pull
out the ups entries.
(I said it was ugly)
There is a UPS_type entry, because I was planning to upscale it for more
UPS types, but never got mych further than the Galaxy range.

Changes to hobbitserver.cfg
To TEST2RRD, add "ups=ncv"
To GRAPHS, add "ups"
Also add following variable 
NCV_ups="Load:GAUGE,Charge:GAUGE"

Add the following to hobbitgraph.cfg
[ups]
        TITLE UPS Charge
        YAXIS Power
        -u 100
        -l 0
        DEF:u=ups.rrd:Charge:AVERAGE
        DEF:p=ups.rrd:Load:AVERAGE
        LINE2:u#00CC00:Charge
        LINE2:p#0000FF:Load
        COMMENT:\n
        GPRINT:u:LAST:Charge   \: %5.1lf%s (cur)
        GPRINT:u:MAX: \: %5.1lf%s (max)
        GPRINT:u:MIN: \: %5.1lf%s (min)
        GPRINT:u:AVERAGE: \: %5.1lf%s (avg)\n
        GPRINT:p:LAST:Load   \: %5.1lf%s (cur)
        GPRINT:p:MAX: \: %5.1lf%s (max)
        GPRINT:p:MIN: \: %5.1lf%s (min)
        GPRINT:p:AVERAGE: \: %5.1lf%s (avg)\n

On the server
Add the following to hobbitlaunch.cfg
[ups]
        ENVFILE /usr/lib/hobbit/server/etc/hobbitserver.cfg
        NEEDS hobbitd
        CMD $BBHOME/ext/ups.ksh
        LOGFILE $BBSERVERLOGS/ups.log
        INTERVAL 5m
 
The wget script
#!/bin/ksh
set -x
COLOUR=green
DATE=$(date)
SPACER="
"
OUT=$BBTMP/upspage
grep " ups " $BBHOSTS | grep -v "^page" | while read IP UPSNAME HASH URL
UPS TYPE OTHER
do
   cat $UPSNAME
   case $TYPE in
      galaxy3000)
         PAGE="$IP/ups_prop.htm"
         wget -O $OUT ${PAGE} > /dev/null
         echo > $OUT.tmp
         cat $OUT | sed -e :a -e 's/<[^>]*>//g;/</N;//ba' |\
                    sed 's/^[ \t]*//;s/[ \t]*$//' |\
                    grep -v ^$ | grep -v "()" |\
                    sed -e :a -e '/:$/N; s/:\n/~ /; ta' |\
                    egrep -v "^Help|^About|^Master|^&nbsp" |\
                    sed 's/\&nbsp;/:/g' |\
                    sed -e :a -e '/:$/N; s/:\n/ /; ta' |\
                    sed 's/Last update ~/\nLast update ~/g' |\
                    uniq \
                    >> $OUT.tmp
         #Assign a colour
 
         #FORMAT OUTPUT
         grep -v "~"  $OUT.tmp > $OUT.final
         echo >> $OUT.final
         grep "~" $OUT.tmp | while read a
         do
            LEN=$(echo "$a" | cut -d"~" -f1 | wc -c)
            ((FIL=30-LEN))
            FILLER="${SPACER:1:$FIL}"
            echo "$a" | sed "s/~/$FILLER/g" >> $OUT.final
         done
         echo '<FONT COLOR="Black">' >> $OUT.final
         cat $OUT.tmp | egrep "Battery charge level|Output load level"
|\
                        sed 's/Battery charge level/Charge=/g' |\
                        sed 's/Output load level/Load=/g' |\
                        sed 's/%//g' | sed 's/~//g' |\
                        sed 's/[ \t]*//g' >> $OUT.final
         echo '</FONT>'  >> $OUT.final
      ;;
   esac
   $BB $BBDISP "status $UPSNAME.ups $COLOUR $DATE $(cat $OUT.final)"
   rm $OUT.tmp $OUT.final $OUT
done

------------------------------------------------------------------------
-------------------------------
 
The script using SNMP - rename as appropriate.
#!/bin/ksh
DATE=$(date)
#set -x
SPACER="
"
BBTMP=/tmp
#BBHOSTS=/etc/hobbit/bb-hosts
#OUT=$BBTMP/upspage
grep " ups " $BBHOSTS | grep -v "^page" | while read IP UPSNAME HASH URL
UPS TYPE OTHER
do
   # echo $IP $UPSNAME
   # Do a single ping to make sure there is something there.
   ping -c1 $IP > /dev/null # This might be different in other versions
of Unix
   if [ $? -eq 0 ]
   then
      COLOUR=green
      case $TYPE in
         galaxy3000)
            > $OUT.warn
            > $OUT.tmp
            TEMP=$(snmpget -v1 -c public $IP
SNMPv2-SMI::mib-2.33.1.1.1.0)
            DEVICE=${TEMP##*:}       # String
            TEMP=$(snmpget -v1 -c public $IP
SNMPv2-SMI::mib-2.33.1.1.2.0)
            MODEL=${TEMP##*:}        # String
            TEMP=$(snmpget -v1 -c public $IP SNMPv2-MIB::sysLocation.0)
            LOCATION=${TEMP##*:}             # String
            TEMP=$(snmpget -v1 -c public $IP
SNMPv2-SMI::mib-2.33.1.1.4.0)
            SERIAL=${TEMP##*:}               # String
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.4.8.0)
            LOWBATTERY=${TEMP##*:}           # Integer % Point at which
shutdown triggered
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.5.1.0)
            TIME_REMAIN=${TEMP##*:}     # Integer seconds
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.5.2.0)
            BATTERY_LEVEL=${TEMP##*:}   # Integer %
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.5.9.0)
            BATTERY_FAULT=${TEMP##*:}   # Integer 1=yes 2=no
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.5.11.0)
            BATTERY_REPLACE=${TEMP##*:} # Integer 1=yes 2=no
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.5.15.0)
            CHARGER_FAULT=${TEMP##*:}   # Integer 1=yes 2=no
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.7.3.0)
            OUT_ON_BAT=${TEMP##*:}      # Integer 1=yes 2=no
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.7.4.0)
            OUT_ON_BYPASS=${TEMP##*:}   # Integer 1=yes 2=no
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.7.10.0)
            OUT_OVERLOAD=${TEMP##*:}    # Integer 1=yes 2=no
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.7.10.0)
            COMMSOK=${TEMP##*:}         # Integer 1=yes 2=no
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.6.1.0)
            INPHASES=${TEMP##*:}        # Integer 1 or 3
 
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.6.2.1.2)
            INVOLT=${TEMP##*:}          # Integer 10ths of a volt
 
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.6.2.1.3)
            INFREQ=${TEMP##*:}          # Integer 10ths of a Hertz
 
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.6.2.1.6)
            INAMPS=${TEMP##*:}          # Integer 10ths of an Amp
 
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.6.3.0)
            INOK=${TEMP##*:}            # Integer 1=yes 2=no
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.6.4.0)
            INFAILCAUSE=${TEMP##*:}     # Integer 1=no fault
                                     #         2=bad voltage
                                     #         3=bad frequency
                                     #         4=no voltage
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.7.1.0)
            OUTPHASES=${TEMP##*:}       # Integer 1 or 3
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.7.2.1.2)
            OUTVOLT=${TEMP##*:}         # Integer 10ths of a volt
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.7.2.1.3)
            OUTFREQ=${TEMP##*:}         # Integer 10ths of a Hertz
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.7.2.1.4)
            OUTLOAD=${TEMP##*:}         # Integer %
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.7.2.1.5)
            OUTAMPS=${TEMP##*:}         # Integer 10ths of an Amp
            TEMP=$(snmpget -v1 -c public $IP 1.3.6.1.4.1.705.1.7.11.0)
            OVERTEMP=${TEMP##*:}        # Integer 1=yes 2=no
            echo "Manufacturer                          "$DEVICE | sed
's/"//g' >> $OUT.tmp
            echo "Model                                "$MODEL | sed
's/"//g' >> $OUT.tmp
            echo "Serial Number                        "$SERIAL | sed
's/"//g' >> $OUT.tmp
            echo "Location                             "$LOCATION | sed
's/"//g' >> $OUT.tmp
            echo >> $OUT.tmp
            #$LOWBATTERY
            WARN=""
            [ -z "$TIME_REMAIN" ] && TIME_REMAIN=0
            [ $TIME_REMAIN -lt 1200 -a "$COLOUR" != "red" ] &&
COLOUR=yellow
            [ $TIME_REMAIN -lt 1200 ] && WARN="Time Remaining low"
            [ $TIME_REMAIN -lt 600 ] && COLOUR=red
            [ $TIME_REMAIN -lt 600 ] && WARN="Time Remaining critical"
            [ "$WARN" != "" ] && echo $WARN >> $OUT.warn
            ((s=$TIME_REMAIN%60))
            ((m=$TIME_REMAIN/60))
            echo "Time Remaining                        "$m Minutes $s
Seconds >> $OUT.tmp
            WARN=""
            [ -z "$BATTERY_LEVEL" ] && BATTERY_LEVEL=0
            [ $BATTERY_LEVEL -lt 70 -a "$COLOUR" != "red" ] &&
COLOUR=yellow
            [ $BATTERY_LEVEL -lt 70 ] && WARN="Battery level low"
            [ $BATTERY_LEVEL -lt 50 ] && COLOUR=red
            [ $BATTERY_LEVEL -lt 50 ] && WARN="Battery level critical"
            [ "$WARN" != "" ] && echo $WARN >> $OUT.warn
            echo "Battery Level                        "$BATTERY_LEVEL %
>> $OUT.tmp
            BATTERY_LEVEL=$(echo $BATTERY_LEVEL | sed 's/[ \t]*//')
            if [ $BATTERY_FAULT -eq 1 ]
            then
               BF=Yes
               COLOUR=red
               echo "Battery Fault!" >> $OUT.warn
            else
               BF=No
            fi
            echo "Battery Fault                         "$BF >> $OUT.tmp
            if [ $BATTERY_REPLACE -eq 1 ]
            then
               BR=Yes
               COLOUR=red
               echo "Battery replacement required" >> $OUT.warn
            else
               BR=No
            fi
            echo "Replace Battery                       "$BR >> $OUT.tmp
            if [ $BATTERY_FAULT -eq 1 ]
            then
               BR=Yes
               COLOUR=red
               echo "Battery replacement required" >> $OUT.warn
            else
               BR=No
            fi
            if [ $CHARGER_FAULT -eq 1 ]
            then
               CF=Yes
               COLOUR=red
               echo "Charger Fault" >> $OUT.warn
            else
               CF=No
            fi
            echo "Charger Fault                         "$CF >> $OUT.tmp
            if [ $OUT_ON_BAT -eq 1 ]
            then
               OUT_ON_BAT=Yes
               COLOUR=red
               echo "UPS running on battery" >> $OUT.warn
            else
               OUT_ON_BAT=No
            fi
            echo "On Battery                            "$OUT_ON_BAT >>
$OUT.tmp
            if [ $OUT_ON_BYPASS -eq 1 ]
            then
               OUT_ON_BYPASS=Yes
               COLOUR=red
               echo "UPS on power bypass" >> $OUT.warn
            else
               OUT_ON_BYPASS=No
            fi
            echo "On Bypass                             "$OUT_ON_BYPASS
>> $OUT.tmp
            if [ $OUT_OVERLOAD -eq 1 ]
            then
               OUT_OVERLOAD=Yes
               COLOUR=red
               echo "UPS output overload" >> $OUT.warn
            else
               OUT_OVERLOAD=No
            fi
            echo "Battery Overload                      "$OUT_OVERLOAD
>> $OUT.tmp
            if [ $OVERTEMP -eq 1 ]
            then
               OVERTEMP=Yes
               COLOUR=red
               echo "Unit overheating" >> $OUT.warn
            else
               OVERTEMP=No
            fi
            echo "Unit Overheating                      "$OVERTEMP >>
$OUT.tmp
            #if [ $COMMSOK -eq 2 ]
            #then
            #   COMMSOK=No
            #   COLOUR=red
            #   echo "No comms from device" >> $OUT.warn
            #else
            #   COMMSOK=Yes
            #fi
            #echo "Comms OK                              "$COMMSOK >>
$OUT.tmp
            echo >> $OUT.tmp
            echo "Input Phases                         "$INPHASES >>
$OUT.tmp
            INVOLT=$(echo "scale=1 ; $INVOLT/10" | bc)
            echo "Input Voltage                         "$INVOLT >>
$OUT.tmp
            INFREQ=$(echo "scale=1 ; $INFREQ/10" | bc)
            echo "Input Frequency                       "$INFREQ >>
$OUT.tmp
            INAMPS=$(echo "scale=1 ; $INAMPS/10" | bc)
            echo "Input Current                         "$INAMPS >>
$OUT.tmp
            if [ $INOK -eq 1 ]
            then
               # A silly case of reverse logic applies here
               INOK=No
               COLOUR=red
               echo "Power input outside tollerance" >> $OUT.warn
            else
               INOK=Yes
            fi
            echo "Input OK                              "$INOK >>
$OUT.tmp
            [ $INFAILCAUSE -eq 1 ] && FAILCAUSE="No failures"
            [ $INFAILCAUSE -eq 2 ] && FAILCAUSE="Voltage out of
tollearance"
            [ $INFAILCAUSE -eq 3 ] && FAILCAUSE="Frequency out of
tollernace"
            [ $INFAILCAUSE -eq 4 ] && FAILCAUSE="No voltage - power
fail"
            echo "Cause of Failure                      "$FAILCAUSE >>
$OUT.tmp
            echo >> $OUT.tmp
            echo "Output Phases                        "$OUTPHASES >>
$OUT.tmp
            OUTVOLT=$(echo "scale=1 ; $OUTVOLT/10" | bc)
            echo "Output Voltage                        "$OUTVOLT >>
$OUT.tmp
            OUTFREQ=$(echo "scale=1 ; $OUTFREQ/10" | bc)
            echo "Output Frequency                      "$OUTFREQ >>
$OUT.tmp
            OUTAMPS=$(echo "scale=1 ; $OUTAMPS/10" | bc)
            echo "Output Current                        "$OUTAMPS >>
$OUT.tmp
            OUTLOAD=$(echo $OUTLOAD | sed 's/[ \t]*//')
            echo "Output Load                           "$OUTLOAD % >>
$OUT.tmp
            echo >> $OUT.final
            cat $OUT.warn >> $OUT.final
            cat $OUT.tmp >> $OUT.final
            echo '<FONT COLOR="Black">' >> $OUT.final
            echo "Load=$OUTLOAD" >> $OUT.final
            echo "Charge=$BATTERY_LEVEL" >> $OUT.final
            echo '</FONT>' >> $OUT.final
            rm $OUT.tmp
            rm $OUT.warn
       esac
    else
       echo "Device Unreachable!" >> $OUT.final
       COLOUR=red
    fi
    $BB $BBDISP "status $UPSNAME.ups $COLOUR $DATE $(cat $OUT.final)"
    rm $OUT.final
done
 
 

________________________________

From: Josh Luthman [mailto:josh (at) imaginenetworksllc.com] 
Sent: Thursday, 18 September 2008 7:27 AM
To: hobbit (at) hswn.dk
Subject: Re: [hobbit] UPS units


Thanks in advance for your input.  Much appreciated.  I look forward to
reading your scripts!

I will not be wanting to shut my servers down, but instead switch them
over to generators rather then the AC power.  The generators we have at
each site are not good/smart enough to take in AC power and kick on when
it drops, unfortunately.

Josh Luthman
Office: 937-552-2340
Direct: 937-552-2343
1100 Wayne St
Suite 1337
Troy, OH 45373

Those who don't understand UNIX are condemned to reinvent it, poorly.
--- Henry Spencer



On Wed, Sep 17, 2008 at 12:13 PM, Bill Arlofski
<waa-hobbitml (at) revpol.com> wrote:



	Josh Luthman wrote:
	> I haven't looked into the mailing list very closely in the
past.  From what
	> I know, we're still using "Hobbit", right?
	>
	> I'm looking at getting a full suit of new UPS units and I
would like to see
	> what everyone is using out there.  I would really like to find
something
	> that works well with Hobbit so I can monitor them as easy as
possible.  I
	> will need to have Hobbit go red when power is down (batteries
discharging)
	> is really my main concern here.  More details would be
prettier, though =)
	>
	> Thanks in advance!
	
	
	Hi Josh...
	
	I have been using NUT (Network Ups Tools -
http://eu1.networkupstools.org/ )
	to monitor some APC UPSes. NUT is an excellent client/server UPS
monitoring
	tool that allows you to automate the shutdown of multiple
servers using AC
	power from one UPS when the battery is getting low. It can
monitor many types
	of UPSes, and its client-server construction makes it
well-suited to be
	monitored by other tools like hobbit, for instance.
	
	I have created several hobbit client scripts to pull information
from the NUT
	server. These scripts are monitoring and graphing the following
stats from
	(currently) two UPSes at one of my client's sites:
	
	bat-charge %
	ups-load %
	in-voltage
	out-voltage
	bat-voltage
	
	
	I have been planning (for quite some time now) to get these
things cleaned up
	and get them on the shire so everyone can make use of them. I
have been far
	too busy though... I have a few projects coming to a close and
may have time
	in the coming weeks to get these up there.
	
	Let me take a quick look at my scripts in their current state.
Perhaps if they
	look reasonable enough, and some people are interested, I may
just post them
	here with minimal instructions before I get a completed package
ready for the
	shire.
	
	The only pre-requisite to deploying my scripts is that NUT is
currently
	installed, running properly and monitoring at least one of your
UPSes.
	
	Let me know if this is of interest.   I am looking to give back
to the hobbit
	community and this might be a perfect chance. :)
	
	
	--
	Bill Arlofski
	Reverse Polarity, LLC
	860-965-5110 Cell
	http://www.revpol.com/
	* Stop the NSA from illegally eavesdropping on your personal
email *
	Learn about PGP and start encrypting your email today
	http://gnupg.org or http://www.pgp.com
	

	To unsubscribe from the hobbit list, send an e-mail to
	hobbit-unsubscribe (at) hswn.dk
	
	
	



NOTICE: This email and any attachments are confidential. 
They may contain legally privileged information or 
copyright material. You must not read, copy, use or 
disclose them without authorisation. If you are not an 
intended recipient, please contact us at once by return 
email and then delete both messages and all attachments.