Ben's notes

Linux, Unix, network, radio...

User Tools

Site Tools


check_mk_apc_ups

This is an old revision of the document!


~~TOC~~

Check_MK - local check APCUSPd

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

  • APC-check (if apcaccess runs OK)
  • APC-status
  • 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.1426779189.txt.gz · Last modified: 2015/03/19 15:33 by admin