Browse Source

Add raid plugin

Emmanuel Bouthenot 7 years ago
parent
commit
a6f88e4f68

+ 3 - 0
plugins/client/raid/conf/raid-battery.conf

@@ -0,0 +1,3 @@
+UserParameter=sys.raid-battery.list,sudo /etc/zabbix/scripts/raid-battery -s
+UserParameter=sys.raid-battery.status[*],sudo /etc/zabbix/scripts/raid-battery -d '$1' -a 'status'
+UserParameter=sys.raid-battery.temperature[*],sudo /etc/zabbix/scripts/raid-battery -d '$1' -a 'temperature'

+ 2 - 0
plugins/client/raid/conf/raid.conf

@@ -0,0 +1,2 @@
+UserParameter=sys.raid.list,sudo /etc/zabbix/scripts/raid -s
+UserParameter=sys.raid.info[*],sudo /etc/zabbix/scripts/raid -d '$1' -t '$2'

+ 147 - 0
plugins/client/raid/scripts/raid

@@ -0,0 +1,147 @@
+#!/bin/sh
+
+# {{{ Variables
+DEVICE=
+SCAN=0
+TYPE=
+ZBX_DISCOVERY_OUTPUT=0
+# }}}
+
+# {{{ usage()
+usage() {
+cat <<EOH
+USAGE: $(basename "$0") -d DEVICE
+
+Get RAID status value for a device
+
+Options:
+    -d  Device path
+    -t  Raid type (mdraid, megaraid, etc.)
+    -S  Scan devices and display list
+    -s  Scan devices and display list (Zabbix discovery output)
+EOH
+}
+# }}}
+
+# {{{ scan_megaraid_devices()
+scan_megaraid_devices() {
+    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
+                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

+ 148 - 0
plugins/client/raid/scripts/raid-battery

@@ -0,0 +1,148 @@
+#!/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

+ 4 - 0
plugins/client/raid/sudo/zabbix_plugins_raid

@@ -0,0 +1,4 @@
+#
+# Permit to zabbix user to execute 'raid' plugin
+#
+zabbix ALL=NOPASSWD: /etc/zabbix/scripts/raid

+ 4 - 0
plugins/client/raid/sudo/zabbix_plugins_raid-battery

@@ -0,0 +1,4 @@
+#
+# Permit to zabbix user to execute 'raid-battery' plugin
+#
+zabbix ALL=NOPASSWD: /etc/zabbix/scripts/raid-battery