-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathadaptec-raid.sh
206 lines (171 loc) · 5.77 KB
/
adaptec-raid.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
#!/bin/bash
#
# .VERSION
# 0.5
#
# .DESCRIPTION
# Author: Nikitin Maksim
# Github: https://github.com/nikimaxim/zbx-raid-controller.git
# Note: Zabbix lld for Controller RAID
#
# .TESTING
# OS: CentOS 7 x64
# Controller RAID: ASR8405, ASR-8405E, Adaptec 6805, Adaptec 6405E, ASR8805, Adaptec 5805
#
CLI='/opt/StorMan/arcconf'
PATH_CTRL_COUNT='/tmp/ctrl_count'
action=$1
part=$2
if [ ! -f ${CLI} ]; then
echo "Could not find path: ${CLI}"
exit
fi
GetCtrlCount() {
ctrl_count=$($CLI LIST | grep -i "Controllers found:" | cut -f2 -d":" | sed -e 's/^\s*//')
echo ${ctrl_count} > ${PATH_CTRL_COUNT}
echo ${ctrl_count}
}
CheckCtrlCount() {
if [ -f ${PATH_CTRL_COUNT} ]; then
ctrl_count=$(cat ${PATH_CTRL_COUNT})
if [ -z ${ctrl_count} ]; then
ctrl_count=$(GetCtrlCount)
fi
else
ctrl_count=$(GetCtrlCount)
fi
echo ${ctrl_count}
}
LLDControllers() {
ctrl_count=$(GetCtrlCount)
ctrl_json=""
for ctrl_id in $(seq 1 ${ctrl_count}); do
response=$($CLI LIST | grep "Controller ${ctrl_id}" | cut -f3 -d":")
ctrl_model="-" #$(/bin/echo $response | awk -F "," '{print $4}' | sed -e 's/^\s*//')
ctrl_sn=$(/bin/echo $response | awk -F "," '{print $5}' | sed -e 's/^\s*//')
ctrl_json=${ctrl_json}"{\"{#CTRL.ID}\":\"${ctrl_id}\",\"{#CTRL.MODEL}\":\"${ctrl_model}\",\"{#CTRL.SN}\":\"$ctrl_sn\"},"
done
echo "{\"data\":[$(echo ${ctrl_json} | sed -e 's/,$//')]}"
}
LLDBattery() {
ctrl_count=$(CheckCtrlCount)
bt_json=""
for ctrl_id in $(seq 1 ${ctrl_count}); do
ctrl_bt=$($CLI GETCONFIG ${ctrl_id} AD | grep -i -A 2 "^\s*Controller Battery Information" | grep -iE "^\s+Status\s+[:]" | cut -f2 -d":" | sed -e 's/^ //' | grep -iEv "\w*\s*[Not]+\s*installed")
if [ -n "${ctrt_bt}" ]; then
bt_json=${bt_json}"{\"{#CTRL.ID}\":\"${ctrl_id}\"},"
fi
done
echo "{\"data\":[$(echo ${bt_json} | sed -e 's/,$//')]}"
}
LLDPhysicalDrives() {
ctrl_count=$(CheckCtrlCount)
pd_json=""
for ctrl_id in $(seq 1 ${ctrl_count}); do
IFS=$'\n'
response=($($CLI GETCONFIG ${ctrl_id} PD | grep -e "Device #" -e "Device is" -e "Reported Channel,Device(T:L)" -e "Serial number"))
i=0
while [ $i -lt ${#response[@]} ]; do
pd_type=$(echo ${response[$((${i}+1))]} | cut -f2 -d":" | sed -e 's/^\s*//' -e 's/ /_/g')
if [[ ! ${pd_type} =~ "Enclosure_Services_Device" ]]; then
pd_id=$(echo ${response[$((${i}+2))]} | awk '{print $4}' | sed -e 's/.*,\(.*\)(.*/\1/')
pd_sn=$(echo ${response[$((${i}+3))]} | cut -f2 -d":" | sed -e 's/^\s*//')
if [ ${#pd_sn} -gt 0 ]; then
pd_json=${pd_json}"{\"{#CTRL.ID}\":\"${ctrl_id}\",\"{#PD.ID}\":\"${pd_id}\",\"{#PD.SN}\":\"${pd_sn}\"},"
fi
i=$(($i+4))
else
if [[ $(echo ${response[$((${i}+3))]}) =~ "Serial number" ]]; then
i=$(($i+4))
else
i=$(($i+3))
fi
fi
done
done
echo "{\"data\":[$(echo ${pd_json} | sed -e 's/,$//')]}"
}
LLDLogicalDrives() {
ctrl_count=$(CheckCtrlCount)
ld_json=""
for ctrl_id in $(seq 1 ${ctrl_count}); do
ld_ids=$($CLI GETCONFIG ${ctrl_id} LD | grep -i "Logical device number " | cut -f4 -d" " | sed -e 's/^\s*//')
for ld_id in ${ld_ids}; do
ld_name=$($CLI GETCONFIG ${ctrl_id} LD ${ld_id} | grep -i "Logical device name" | cut -f2 -d":" | sed -e 's/^\s*//')
ld_raid=$($CLI GETCONFIG ${ctrl_id} LD ${ld_id} | grep -i "RAID level" | cut -f2 -d":" | sed -e 's/^\s*//')
if [ -z "${ld_name}" ]; then
ld_name=${ld_id}
fi
ld_json=$ld_json"{\"{#CTRL.ID}\":\"${ctrl_id}\",\"{#LD.ID}\":\"${ld_id}\",\"{#LD.NAME}\":\"${ld_name}\",\"{#LD.RAID}\":\"${ld_raid}\"},"
done
done
echo "{\"data\":[$(echo ${ld_json} | sed -e 's/,$//')]}"
}
GetControllerStatus() {
ctrl_id=$1
ctrl_part=$2
value=""
case ${ctrl_part} in
"main")
value=$($CLI LIST | grep "Controller ${ctrl_id}" | cut -f3 -d":" | awk -F "," '{print $1}' | sed -e 's/^\s*//')
;;
"temperature")
value=$($CLI GETCONFIG ${ctrl_id} AD | grep -iE "^\s+Temperature\s+[:]" | cut -f2 -d":" | awk '{print $1}')
;;
"battery")
value=$($CLI GETCONFIG ${ctrl_id} AD | grep -i -A 2 "^\s*Controller Battery Information" | grep -iE "^\s+Status\s+[:]" | cut -f2 -d":" | sed -e 's/^\s*//')
;;
esac
echo ${value}
}
GetPhysicalDriveStatus() {
ctrl_id=$1
pd_id=$2
response=$($CLI GETCONFIG ${ctrl_id} PD 0 ${pd_id} | grep -ioP "^\s+State.*$" | cut -f2 -d":" | sed -E 's/[ ]//g')
if [ -n ${response} ]; then
echo ${response}
else
echo "Data not found"
fi
}
GetLogicalDriveStatus() {
ctrl_id=$1
ld_id=$2
response=$($CLI GETCONFIG ${ctrl_id} LD $ld_id | grep -i "Status of logical device" | cut -f2 -d":" | sed -e 's/^\s*//')
if [ -n ${response} ]; then
echo ${response}
else
echo "Data not found"
fi
}
case ${action} in
"lld")
case ${part} in
"ad")
LLDControllers
;;
"bt")
LLDBattery
;;
"pd")
LLDPhysicalDrives
;;
"ld")
LLDLogicalDrives
;;
esac
;;
"health")
case ${part} in
"ad")
GetControllerStatus $3 $4
;;
"pd")
GetPhysicalDriveStatus $3 $4
;;
"ld")
GetLogicalDriveStatus $3 $4
;;
esac
;;
esac