123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148 |
- #!/bin/sh
- # {{{ Variables
- DEVICE=
- SCAN=0
- ATTRIBUTE=
- ZBX_DISCOVERY_OUTPUT=0
- # }}}
- # {{{ usage()
- usage() {
- cat <<EOH
- USAGE: $(basename "$0") -d DEVICE
- Get RAID Battery status value for a device
- Options:
- -d Battery device path
- -a Attribute (status, temperature, etc.)
- -S Scan devices and display list
- -s Scan devices and display list (Zabbix discovery output)
- EOH
- }
- # }}}
- # {{{ scan_megaraid_batteries()
- scan_megaraid_batteries() {
- if which storcli >/dev/null 2>&1 ; then
- ctrlcount=$(storcli show ctrlcount| sed -n 's/^Controller Count = //p')
- if [ "${ctrlcount}" -gt 0 ]; then
- ctrlcount=$(( ${ctrlcount} - 1))
- for i in $(seq 0 ${ctrlcount}) ; do
- printf "megaraid /c%s\n" "${i}"
- done
- fi
- fi
- }
- # }}}
- # {{{ scan_batteries()
- scan_batteries() {
- scan_megaraid_batteries
- }
- # }}}
- # {{{ list_batteries()
- list_batteries() {
- ZBX="${1}"
- if [ "${ZBX}" = 1 ]; then
- printf '{"data":['
- fi
- scan_batteries | \
- while read type device ; do
- if [ "${ZBX}" = 1 ]; then
- printf '{'
- printf '"{#DEVICE}":"%s",' "${device}"
- printf '"{#TYPE}":"%s"' "${type}"
- printf '},'
- else
- printf "${device}|${type}\n"
- fi
- done | sed 's/},$/}/'
- if [ "${ZBX}" = 1 ]; then
- printf ']}'
- fi
- }
- # }}}
- # {{{ main()
- while getopts "d:a:Ss" OPT ; do
- case "$OPT" in
- \?|h)
- usage
- exit 0
- ;;
- d)
- DEVICE="$OPTARG"
- ;;
- a)
- ATTRIBUTE="$OPTARG"
- ;;
- S)
- SCAN=1
- ;;
- s)
- SCAN=1
- ZBX_DISCOVERY_OUTPUT=1
- ;;
- esac
- done
- if [ "${SCAN}" = 1 ]; then
- list_batteries "${ZBX_DISCOVERY_OUTPUT}"
- exit 0
- fi
- if [ -z "${DEVICE}" ] ; then
- printf "[ERR] device is not defined\n"
- usage
- exit 1
- fi
- if [ -z "${ATTRIBUTE}" ] ; then
- printf "[ERR] attribute is not defined\n"
- usage
- exit 1
- fi
- result=0
- case "${ATTRIBUTE}" in
- status)
- status=
- for d in ${DEVICE}/cv ${DEVICE}/bbu ; do
- status=$(storcli "${d}" show all | sed -r -n 's/^(Battery |)State\s+([a-z]+)\s*$/\2/pi')
- if [ -n "${status}" ]; then
- break
- fi
- done
- if [ "${status}" != "Optimal" ]; then
- result=1
- fi
- ;;
- temperature)
- for d in ${DEVICE}/cv ${DEVICE}/bbu ; do
- status=$(storcli "${d}" show all | sed -r -n 's/^Temperature\s+([0-9]+)\s+C\s*$/\1/pi')
- if [ -n "${status}" ]; then
- break
- fi
- done
- if [ -z "${status}" ]; then
- result=1
- else
- result="${status}"
- fi
- ;;
- *)
- printf "[ERR] unsupported attribute '%s'\n" "${ATTRIBUTE}"
- usage
- exit 1
- esac
- printf "${result}\n"
- exit 0
- # }}}
- # vim: foldmethod=marker foldlevel=0 foldenable
|