forked from linuxsquad/zabbix_mdraid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
zabbix_mdraid.sh
executable file
·67 lines (66 loc) · 1.65 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
57
58
59
60
61
62
63
64
65
66
67
#!/bin/bash
#
# AUTHOR: <The Best Zabbix admin>
#
# DATE: 2013-12-31
#
# DESCRIPTION: LLD for SW RAID (MDRAID)
#
# PRE-REQUISIT:
#
# INPUT: see below
#
# OUTPUT: MD RAID parameters
#
# RELEASE NOTE:
#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 -e "{\n\t\"data\":["
typeset -i nbLines
typeset -i cntLines=0
nbLines=`cat /proc/mdstat | grep ^md | wc -l`
cat /proc/mdstat | grep ^md | while read line
do
cntLines=${cntLines}+1
MDdev=`echo $line | awk '{print $1}'`
if [ ${cntLines} -eq ${nbLines} ]; then
echo -e "\t{ \"{#MD_DEVICE}\":\t\"/dev/${MDdev}\" }"
else
echo -e "\t{ \"{#MD_DEVICE}\":\t\"/dev/${MDdev}\" },"
fi
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