forked from linuxsquad/zabbix_mdraid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathzabbix_mdraid.sh
executable file
·58 lines (54 loc) · 1.25 KB
/
zabbix_mdraid.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/bin/bash
#
#
#
#
#
#
item=""
#echo "OPTIND is now $OPTIND"
while getopts ":Dm:e:s:d:" optname
do
case "$optname" in
"e")
# Extract string values
item=$(/sbin/mdadm --detail ${MD_dev} | grep "${OPTARG}" | awk -F":" '{print $2}')
echo ${item// /}
;;
"s")
# echo "Size of the array"
item=$(/sbin/mdadm --detail ${MD_dev} | grep "${OPTARG}" | awk -F":" '{print $2}')
echo ${item%%\ \(*}
;;
"d")
# echo "Devices in the array"
item=$(/sbin/mdadm --detail ${MD_dev} | tail -n+2 | grep "/dev/" | awk -v x=${OPTARG} '$4 == x {print $5,$6,$7}' )
echo ${item}
;;
"m")
# echo "Setting MD RAID"
MD_dev="${OPTARG}"
;;
"D")
# echo "Discovery"
echo -e "{\n\t\"data\":["
cat /proc/mdstat | grep ^md | while read line
do
MDdev=`echo $line | awk '{print $1}'`
echo -e "\t{ \"{#MD_DEVICE}\":\t\"/dev/${MDdev}\" },"
done
echo -e "\t]\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