Ben Stienstra

Linux, Unix, network, radio and more...

User Tools

Site Tools


check_mk_apc_ups

Check_MK - local check APCUSPd

This simple script, using the apcaccess command, checks for:

  • APC-check (if apcaccess runs OK)
  • APC-status (on battery or not)
  • APC-load
  • APC-batt-temp
#!/bin/bash

apcaccess="/sbin/apcaccess"
tempout="/dev/shm/apcaccess.out"

# remove old output
rm "$tempout"

# generate new status
$apcaccess > $tempout
ecode="$?"
if [[ $ecode -eq "0" ]]; then
  echo "0 APC-check - apcaccess run OK"
else
  echo "3 APC-check - apcaccess run, exit code: $ecode"
fi

# read through output, generate statistics
seperator=":"

cat $tempout | while read line
do
  
  before=`echo ${line%%"$seperator"*} | xargs` # xargs will strip whitespace
  after=`echo ${line#*"$seperator"} | xargs`
  
  case $before in

    STATUS)
     if [[ "$after" -eq "ONLINE" ]]; then
       echo "0 APC-status - APC UPS Online"
     else
       echo "2  APC-status - APC UPS not online, status: $after"
     fi
    ;;
    
    LOADPCT)
     pct=`echo $after | cut -d " " -f1`
     if [[ `bc <<< "$pct<70"` -eq "1" ]]; then
       echo "0 APC-load loadpct=$pct APC UPS Load: $pct%"
     else
       echo "2 APC-load loadpct=$pct APC UPS Load: $pct%"
     fi
    ;;
    
    ITEMP)
     deg=`echo $after | cut -d " " -f1`
     if [[ `bc <<< "$deg<24"` -eq "1" ]]; then
       echo "0 APC-batt-temp btemp=$deg APC UPS battery temperature: $deg deg. C."
     else
       echo "1 APC-batt-temp btemp=$deg APC UPS battery temperature: $deg deg. C."
     fi
    ;;
  
  esac
done
check_mk_apc_ups.txt · Last modified: 2015/03/19 15:33 by admin