Contents

  1. UPS

UPS

   1 #!/bin/sh
   2 ## Modified for Zabbix by Clayton Kramer (C) 2007
   3 ##
   4  
   5 ## Originally base on Nagios Plugin for apcupsd APC Smart-UPS
   6 ## janthony@negative1.org
   7 ## Copyright (C) 2004  Joe Anthony
   8 ##
   9  
  10 ## This program is free software; you can redistribute it and/or modify
  11 ## it under the terms of the GNU General Public License as published by
  12 ## the Free Software Foundation; either version 2 of the License, or
  13 ## (at your option) any later version.
  14 ##
  15 ## This program is distributed in the hope that it will be useful,
  16 ## but WITHOUT ANY WARRANTY; without even the implied warranty of
  17 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18 ## GNU General Public License for more details.
  19 ##
  20 ## You should have received a copy of the GNU General Public License
  21 ## along with this program; if not, write to the Free Software
  22 ## Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  23  
  24  
  25 APCA="/sbin/apcaccess"
  26 APCA_ARGS="status"
  27  
  28 if [ ! -x $APCA ]; then
  29         echo "$0: Error: $APCA not found!"
  30         exit 3
  31 fi
  32  
  33 dishelp() {
  34                 echo "Usage: $0 hostname $2 <load|bcharge|time>"
  35                 echo "       $0 status"
  36                 echo
  37                 echo "load (%): Returns the percentage of the UPS power load"
  38                 echo "bcharge (%): Returns the percentage of batter charge left"
  39                 echo "time (minutes): Amount of time in minutes the UPS can supply power based on current charge and load"
  40                 echo "staus: Returns a true value if status is critical"
  41                 echo
  42                 echo "UNKNOWN UPS State"
  43                 exit 3
  44 }
  45  
  46 case "$2" in 
  47         load) 
  48                 LOAD=`$APCA $APCA_ARGS | grep LOAD | awk '{print $3}' | sed -e 's/\.[0-9]* *$//g'`
  49                 echo "${LOAD}"
  50                 exit 0
  51                 ;;
  52         bcharge)
  53                 CHRG=`$APCA $APCA_ARGS | grep BCHARGE | awk '{print $3}' | sed -e 's/\.[0-9]* *$//g' | sed -e 's/0*//'`
  54                 echo "${CHRG}"
  55                 exit 0
  56                 ;;
  57         time)
  58                 TLEFT=`$APCA $APCA_ARGS | grep TIMELEFT | awk '{print $3}' | sed -e 's/\.[0-9]0* *$//g'`
  59                 echo "${TLEFT}"
  60                 exit 0
  61                 ;;
  62         status)
  63                 ONLINE=`$APCA $APCA_ARGS | grep STATUS | awk '{print $3}'`
  64                 if [ "$ONLINE" != ONLINE ]; then
  65                         echo "0"
  66                         exit 2
  67                 fi
  68                 echo "1"
  69                 exit 0
  70                 ;;
  71         *)
  72                 dishelp
  73 esac

MyWiki: Zabbix/ConfigurazioniVarie (last edited 2015-02-20 10:59:51 by risca)