-
Notifications
You must be signed in to change notification settings - Fork 20
/
zabbix_mdraid.sh
executable file
·63 lines (61 loc) · 1.71 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
#!/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:
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