Date created: Monday, January 14, 2013 9:46:00 AM. Last modified: Tuesday, September 19, 2017 12:03:26 PM

Feed from BASH, wget/HTTP

This script pulls per port power usage statis from a PDU that has only a HTML interface, and passes them to an RRD for use with Cacti or similar NMS;

 #!/bin/bash

if [ $# -eq 0 ]
then
 exit 1
else 
 host="$1"
fi

rnd=$RANDOM
wget -O /tmp/$rnd.xml http://$host/data.xml > /dev/null 2>&1

output=""

# Get the 24 IEC port values
for i in {1..24}
do
  length=`grep key=\"CT$i\" /tmp/$rnd.xml | awk '{print $3}' | wc -m`
  valend=$(($length-2))
  val=`grep key=\"CT$i\" /tmp/$rnd.xml | awk '{print $3}' | cut -c8-$valend`
  if [ $i -eq 1 ]
  then
    output="Socket$i:$val"
  else
    output="$output Socket$i:$val"
  fi
done

# Get the total
length=`grep "Amps Total" /tmp/$rnd.xml | awk '{print $3}' | wc -m`
valend=$(($length-2))
val=`grep "Amps Total" /tmp/$rnd.xml | awk '{print $3}' | cut -c8-$valend`
output="$output Total:$val"

echo -n "$output"
rm -f /tmp/$rnd.xml > /dev/null 2>&1 

These values come from an XML file with the following output (where the value field is the port usage in AMPs)

 <devices>
<device id="ABC123" name="PDU17" type="em40_dps25" available="1" index="0">
<field key="TOTAL" value="5.38" niceName="Amps Total" min="0" max="30" type="2"/>
<field key="CT1" value="0.36" niceName="Outlet 1, bottom of rack" min="0" max="20" type="2"/>
<field key="CT2" value="0.29" niceName="Outlet 2" min="0" max="20" type="2"/>
<field key="CT3" value="0.02" niceName="Outlet 3" min="0" max="20" type="2"/>
<field key="CT4" value="0.57" niceName="Outlet 4" min="0" max="20" type="2"/>
<field key="CT5" value="0.34" niceName="Outlet 5" min="0" max="20" type="2"/>
<field key="CT6" value="0.02" niceName="Outlet 6" min="0" max="20" type="2"/>
<field key="CT7" value="0.50" niceName="Outlet 7" min="0" max="20" type="2"/>
<field key="CT8" value="0.02" niceName="Outlet 8" min="0" max="20" type="2"/>
<field key="CT9" value="0.02" niceName="Outlet 9" min="0" max="20" type="2"/>
<field key="CT10" value="0.02" niceName="Outlet 10" min="0" max="20" type="2"/>
<field key="CT11" value="0.02" niceName="Outlet 11" min="0" max="20" type="2"/>
<field key="CT12" value="0.02" niceName="Outlet 12" min="0" max="20" type="2"/>
<field key="CT13" value="0.02" niceName="Outlet 13" min="0" max="20" type="2"/>
<field key="CT14" value="0.02" niceName="Outlet 14" min="0" max="20" type="2"/>
<field key="CT15" value="0.02" niceName="Outlet 15" min="0" max="20" type="2"/>
<field key="CT16" value="0.02" niceName="Outlet 16" min="0" max="20" type="2"/>
<field key="CT17" value="0.70" niceName="Outlet 17" min="0" max="20" type="2"/>
<field key="CT18" value="0.50" niceName="Outlet 18" min="0" max="20" type="2"/>
<field key="CT19" value="0.53" niceName="Outlet 19" min="0" max="20" type="2"/>
<field key="CT20" value="0.37" niceName="Outlet 20" min="0" max="20" type="2"/>
<field key="CT21" value="0.93" niceName="Outlet 21" min="0" max="20" type="2"/>
<field key="CT22" value="0.21" niceName="Outlet 22" min="0" max="20" type="2"/>
<field key="CT23" value="0.20" niceName="Outlet 23" min="0" max="20" type="2"/>
<field key="CT24" value="0.15" niceName="Outlet 24, top of rack" min="0" max="20" type="2"/>
</device>
</devices>