commit 731512bc23631a0f5434ce7f7d8be36d0c4fe332 Author: Nick Kotov Date: Mon Aug 12 10:06:12 2024 +0000 Добавить zabbix_mdraid.sh diff --git a/zabbix_mdraid.sh b/zabbix_mdraid.sh new file mode 100644 index 0000000..fff0fa0 --- /dev/null +++ b/zabbix_mdraid.sh @@ -0,0 +1,49 @@ +#!/bin/bash + +typeset JSONFILE="/tmp/zabbix_mdraid_discovery.json" + +#echo "OPTIND is now $OPTIND" +while getopts ":Dm:e:s:d:" optname +do + case "$optname" in + "e") + # Extract string values + /sbin/mdadm --detail ${MD_dev} | grep "${OPTARG}" | awk -F":" '{print $2}' | tr -d [[:space:]] + ;; + "s") + # echo "Size of the array" + /sbin/mdadm --detail ${MD_dev} | grep "${OPTARG}" | awk -F":" '{print $2}' | sed -e "s/(.*//" | tr -d [[:space:]] + ;; + "d") + # echo "Devices in the array" + /sbin/mdadm --detail ${MD_dev} | tail -n+2 | grep "/dev/" | awk -v x=${OPTARG} '$4 == x {print $5,$6,$7}' + ;; + "m") + # echo "Setting MD RAID" + MD_dev="${OPTARG}" + ;; + "D") + # echo "Discovery" + echo -en "{\n \"data\":[" > ${JSONFILE} + cat /proc/mdstat | grep ^md | while read line + do + MDdev=`echo $line | awk '{print $1}'` + echo -en "\n { \"{#MD_DEVICE}\":\"/dev/${MDdev}\" }," >> ${JSONFILE} + done + echo -e " ]\n}" >> ${JSONFILE} + # this awkward way to handle removal of coma from the last line" + cat ${JSONFILE} | sed -e 's/}, ]/}\n ]/' + ;; + "?") + echo "Unknown option $OPTARG" + ;; + ":") + echo "No argument value for option $OPTARG" + ;; + *) + # Should not occur + echo "Unknown error while processing options" + ;; + esac + # echo "OPTIND is now $OPTIND" +done \ No newline at end of file