#!/bin/sh # {{{ Variables DEVICE= SCAN=0 TYPE= ZBX_DISCOVERY_OUTPUT=0 # }}} # {{{ usage() usage() { cat </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 storcli /c${i}/vall show|sed -r -n 's/^[0-9]+\/([0-9+]+)\s+RAID[0-9]+\s+[a-z]+\s+.*$/\1/pi' | \ while read vd ; do printf "megaraid /c%s/v%s\n" "${i}" "${vd}" done done fi fi } # }}} # {{{ scan_mdraid_devices() scan_mdraid_devices() { if which mdadm >/dev/null 2>&1 ; then mdadm --detail --scan | sed -r -n 's/^ARRAY\s+(.*)\s+metadata=.*$/mdraid \1/p' fi } # }}} # {{{ scan_devices() scan_devices() { scan_megaraid_devices scan_mdraid_devices } # }}} # {{{ list_raid_devices() list_raid_devices() { ZBX="${1}" if [ "${ZBX}" = 1 ]; then printf '{"data":[' fi scan_devices | \ 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:t:Ss" OPT ; do case "$OPT" in \?|h) usage exit 0 ;; d) DEVICE="$OPTARG" ;; t) TYPE="$OPTARG" ;; S) SCAN=1 ;; s) SCAN=1 ZBX_DISCOVERY_OUTPUT=1 ;; esac done if [ "${SCAN}" = 1 ]; then list_raid_devices "${ZBX_DISCOVERY_OUTPUT}" exit 0 fi if [ -z "${DEVICE}" ] ; then printf "[ERR] device is not defined\n" usage exit 1 fi if [ -z "${TYPE}" ] ; then printf "[ERR] raid type is not defined\n" usage exit 1 fi result=0 case "${TYPE}" in mdraid) status="$(mdadm --detail "${DEVICE}" 2>/dev/null | sed -r -n 's/^\s+State\s*:\s*([^ ]+)\s*$/\1/p')" if [ "${status}" != 'clean' ]; then result=1 fi ;; megaraid) status="$(storcli "${DEVICE}" show 2>/dev/null | sed -r -n 's/^.*RAID[0-9]+\s+([a-z]+)\s+.*$/\1/pi')" if [ "${status}" != 'Optl' ]; then result=1 fi ;; *) printf "[ERR] unsupported raid type '%s'\n" "${TYPE}" usage exit 1 esac printf "${result}\n" exit 0 # }}} # vim: foldmethod=marker foldlevel=0 foldenable