From 731512bc23631a0f5434ce7f7d8be36d0c4fe332 Mon Sep 17 00:00:00 2001 From: Nick Kotov Date: Mon, 12 Aug 2024 10:06:12 +0000 Subject: [PATCH] =?UTF-8?q?=D0=94=D0=BE=D0=B1=D0=B0=D0=B2=D0=B8=D1=82?= =?UTF-8?q?=D1=8C=20zabbix=5Fmdraid.sh?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- zabbix_mdraid.sh | 49 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 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