commit | author | age
|
5de2af
|
1 |
<?php |
M |
2 |
|
|
3 |
/* |
|
4 |
Copyright (c) 2013, Marius Cramer, pixcept KG |
|
5 |
All rights reserved. |
|
6 |
|
|
7 |
Redistribution and use in source and binary forms, with or without modification, |
|
8 |
are permitted provided that the following conditions are met: |
|
9 |
|
|
10 |
* Redistributions of source code must retain the above copyright notice, |
|
11 |
this list of conditions and the following disclaimer. |
|
12 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
13 |
this list of conditions and the following disclaimer in the documentation |
|
14 |
and/or other materials provided with the distribution. |
|
15 |
* Neither the name of ISPConfig nor the names of its contributors |
|
16 |
may be used to endorse or promote products derived from this software without |
|
17 |
specific prior written permission. |
|
18 |
|
|
19 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
20 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
21 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
22 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
23 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
24 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
25 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
26 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
27 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
28 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
29 |
*/ |
|
30 |
|
|
31 |
class cronjob_monitor_raid extends cronjob { |
b1a6a5
|
32 |
|
MC |
33 |
// job schedule |
|
34 |
protected $_schedule = '*/5 * * * *'; |
|
35 |
protected $_run_at_new = true; |
|
36 |
|
|
37 |
private $_tools = null; |
|
38 |
|
|
39 |
/* this function is optional if it contains no custom code */ |
|
40 |
public function onPrepare() { |
|
41 |
global $app; |
|
42 |
|
|
43 |
parent::onPrepare(); |
|
44 |
} |
|
45 |
|
|
46 |
/* this function is optional if it contains no custom code */ |
|
47 |
public function onBeforeRun() { |
|
48 |
global $app; |
|
49 |
|
|
50 |
return parent::onBeforeRun(); |
|
51 |
} |
|
52 |
|
|
53 |
public function onRunJob() { |
|
54 |
global $app, $conf; |
|
55 |
|
|
56 |
/* used for all monitor cronjobs */ |
|
57 |
$app->load('monitor_tools'); |
|
58 |
$this->_tools = new monitor_tools(); |
|
59 |
/* end global section for monitor cronjobs */ |
|
60 |
|
5de2af
|
61 |
/* the id of the server as int */ |
M |
62 |
$server_id = intval($conf['server_id']); |
|
63 |
|
|
64 |
/** The type of the data */ |
b1a6a5
|
65 |
|
MC |
66 |
|
5de2af
|
67 |
$type = 'raid_state'; |
M |
68 |
|
|
69 |
/* |
|
70 |
* We support several RAID types, but if we can't find any of them, we have no data |
|
71 |
*/ |
|
72 |
$state = 'no_state'; |
|
73 |
$data['output'] = ''; |
|
74 |
|
|
75 |
/* |
|
76 |
* Check, if Software-RAID is enabled |
|
77 |
*/ |
|
78 |
if (file_exists('/proc/mdstat')) { |
|
79 |
/* |
|
80 |
* Fetch the output |
|
81 |
*/ |
|
82 |
$data['output'] = shell_exec('cat /proc/mdstat'); |
|
83 |
|
|
84 |
/* |
|
85 |
* Then calc the state. |
|
86 |
*/ |
|
87 |
$tmp = explode("\n", $data['output']); |
|
88 |
$state = 'ok'; |
|
89 |
for ($i = 0; $i < sizeof($tmp); $i++) { |
|
90 |
/* fetch the next line */ |
|
91 |
$line = $tmp[$i]; |
|
92 |
|
558bf7
|
93 |
if ((strpos($line, 'U_]') !== false) || (strpos($line, '[_U') !== false) || (strpos($line, 'U_U') !== false)) { |
5de2af
|
94 |
/* One Disk is not working. |
M |
95 |
* if the next line starts with "[>" or "[=" then |
|
96 |
* recovery (resync) is in state and the state is |
|
97 |
* information instead of critical |
|
98 |
*/ |
|
99 |
$nextLine = $tmp[$i + 1]; |
|
100 |
if ((strpos($nextLine, '[>') === false) && (strpos($nextLine, '[=') === false)) { |
|
101 |
$state = $this->_tools->_setState($state, 'critical'); |
|
102 |
} else { |
|
103 |
$state = $this->_tools->_setState($state, 'info'); |
|
104 |
} |
|
105 |
} |
|
106 |
if (strpos($line, '[__]') !== false) { |
|
107 |
/* both Disk are not working */ |
|
108 |
$state = $this->_tools->_setState($state, 'error'); |
|
109 |
} |
|
110 |
if (strpos($line, '[UU]') !== false) { |
|
111 |
/* The disks are OK. |
|
112 |
* if the next line starts with "[>" or "[=" then |
|
113 |
* recovery (resync) is in state and the state is |
|
114 |
* information instead of ok |
|
115 |
*/ |
|
116 |
$nextLine = $tmp[$i + 1]; |
|
117 |
if ((strpos($nextLine, '[>') === false) && (strpos($nextLine, '[=') === false)) { |
|
118 |
$state = $this->_tools->_setState($state, 'ok'); |
|
119 |
} else { |
|
120 |
$state = $this->_tools->_setState($state, 'info'); |
|
121 |
} |
|
122 |
} |
|
123 |
} |
|
124 |
} |
|
125 |
/* |
|
126 |
* Check, if we have mpt-status installed (LSIsoftware-raid) |
|
127 |
*/ |
|
128 |
if (file_exists('/proc/mpt/summary')) { |
|
129 |
system('which mpt-status', $retval); |
|
130 |
if ($retval === 0) { |
|
131 |
/* |
|
132 |
* Fetch the output |
|
133 |
*/ |
|
134 |
$data['output'] = shell_exec('mpt-status --autoload'); |
|
135 |
|
|
136 |
/* |
|
137 |
* Then calc the state. |
|
138 |
*/ |
|
139 |
$state = 'ok'; |
|
140 |
if(is_array($data['output'])) { |
|
141 |
foreach ($data['output'] as $item) { |
|
142 |
/* |
|
143 |
* The output contains information for every RAID and every HDD. |
|
144 |
* We only need the state of the RAID |
|
145 |
*/ |
|
146 |
if (strpos($item, 'state ') !== false) { |
|
147 |
/* |
|
148 |
* We found a raid, process the state of it |
|
149 |
*/ |
|
150 |
if (strpos($item, ' ONLINE ') !== false) { |
|
151 |
$this->_tools->_setState($state, 'ok'); |
|
152 |
} elseif (strpos($item, ' OPTIMAL ') !== false) { |
|
153 |
$this->_tools->_setState($state, 'ok'); |
|
154 |
} elseif (strpos($item, ' INITIAL ') !== false) { |
|
155 |
$this->_tools->_setState($state, 'info'); |
|
156 |
} elseif (strpos($item, ' INACTIVE ') !== false) { |
|
157 |
$this->_tools->_setState($state, 'critical'); |
|
158 |
} elseif (strpos($item, ' RESYNC ') !== false) { |
|
159 |
$this->_tools->_setState($state, 'info'); |
|
160 |
} elseif (strpos($item, ' DEGRADED ') !== false) { |
|
161 |
$this->_tools->_setState($state, 'critical'); |
|
162 |
} else { |
|
163 |
/* we don't know the state. so we set the state to critical, that the |
|
164 |
* admin is warned, that something is wrong |
|
165 |
*/ |
|
166 |
$this->_tools->_setState($state, 'critical'); |
|
167 |
} |
|
168 |
} |
|
169 |
} |
|
170 |
} |
|
171 |
} |
|
172 |
} |
|
173 |
|
|
174 |
/* |
|
175 |
* 3ware Controller |
|
176 |
*/ |
|
177 |
system('which tw_cli', $retval); |
|
178 |
if($retval === 0) { |
|
179 |
|
ebbe63
|
180 |
// TYPOWORX FIX | Determine Controler-ID |
MC |
181 |
$availableControlers = shell_exec('tw_cli info | grep -Eo "c[0-9]+'); |
|
182 |
$data['output'] = shell_exec('tw_cli info ' . $availableControlers); |
5de2af
|
183 |
|
M |
184 |
$state = 'ok'; |
|
185 |
if(is_array($data['output'])) { |
b1a6a5
|
186 |
foreach ($data['output'] as $item) { |
MC |
187 |
if (strpos($item, 'RAID') !== false) { |
|
188 |
if (strpos($item, ' VERIFYING ') !== false) { |
|
189 |
$this->_tools->_setState($state, 'info'); |
|
190 |
} |
|
191 |
else if (strpos($item, ' MIGRATE-PAUSED ') !== false) { |
|
192 |
$this->_tools->_setState($state, 'info'); |
|
193 |
} |
|
194 |
else if (strpos($item, ' MIGRATING ') !== false) { |
|
195 |
$this->_tools->_setState($state, 'ok'); |
|
196 |
} |
|
197 |
else if (strpos($item, ' INITIALIZING ') !== false) { |
|
198 |
$this->_tools->_setState($state, 'info'); |
|
199 |
} |
|
200 |
else if (strpos($item, ' INIT-PAUSED ') !== false) { |
|
201 |
$this->_tools->_setState($state, 'info'); |
|
202 |
} |
|
203 |
else if (strpos($item, ' REBUILDING ') !== false) { |
|
204 |
$this->_tools->_setState($state, 'info'); |
|
205 |
} |
|
206 |
else if (strpos($item, ' REBUILD-PAUSED ') !== false) { |
|
207 |
$this->_tools->_setState($state, 'warning'); |
|
208 |
} |
|
209 |
else if (strpos($item, ' RECOVERY ') !== false) { |
|
210 |
$this->_tools->_setState($state, 'warning'); |
|
211 |
} |
|
212 |
else if (strpos($item, ' DEGRADED ') !== false) { |
|
213 |
$this->_tools->_setState($state, 'critical'); |
|
214 |
} |
|
215 |
else if (strpos($item, ' UNKNOWN ') !== false) { |
|
216 |
$this->_tools->_setState($state, 'critical'); |
|
217 |
} |
|
218 |
else if (strpos($item, ' OK ') !== false) { |
|
219 |
$this->_tools->_setState($state, 'ok'); |
|
220 |
} |
|
221 |
else if (strpos($item, ' OPTIMAL ') !== false) { |
|
222 |
$this->_tools->_setState($state, 'ok'); |
|
223 |
} |
|
224 |
else { |
|
225 |
$this->_tools->_setState($state, 'critical'); |
|
226 |
} |
5de2af
|
227 |
} |
M |
228 |
} |
|
229 |
} |
|
230 |
} |
|
231 |
|
248d0e
|
232 |
/* |
FS |
233 |
* HP Proliant |
|
234 |
*/ |
|
235 |
system('which hpacucli', $retval); |
|
236 |
if($retval === 0) { |
|
237 |
$state = 'ok'; |
|
238 |
$data['output'] = shell_exec('/usr/sbin/hpacucli ctrl all show config'); |
|
239 |
$tmp = explode("\n", $data['output']); |
|
240 |
if(is_array($tmp)) { |
|
241 |
foreach ($tmp as $item) { |
|
242 |
if (strpos($item, 'logicaldrive') !== false) { |
|
243 |
if (strpos($item, 'OK') !== false) { |
|
244 |
$this->_tools->_setState($state = 'ok'); |
|
245 |
} elseif (strpos($item, 'Recovery Mode') !== false) { |
|
246 |
$this->_tools->_setState($state = 'critical'); |
|
247 |
break; |
|
248 |
} elseif (strpos($item, 'Failed') !== false) { |
|
249 |
$this->_tools->_setState($state = 'error'); |
|
250 |
break; |
|
251 |
} elseif (strpos($item, 'Recovering') !== false) { |
|
252 |
$this->_tools->_setState($state = 'info'); |
|
253 |
break; |
|
254 |
} else { |
|
255 |
$this->_tools->_setState($state = 'critical'); |
|
256 |
} |
|
257 |
} |
|
258 |
if (strpos($item, 'physicaldrive') !== false) { |
|
259 |
if (strpos($item, 'physicaldrive') !== false) { |
|
260 |
if (strpos($item, 'OK') !== false) { |
|
261 |
$this->_tools->_setState($state = 'ok'); |
|
262 |
} elseif (strpos($item, 'Failed') !== false) { |
|
263 |
$this->_tools->_setState($state = 'critical'); |
|
264 |
break; |
|
265 |
} elseif (strpos($item, 'Rebuilding') !== false) { |
|
266 |
$this->_tools->_setState($state = 'info'); |
|
267 |
break; |
|
268 |
} else { |
|
269 |
$this->_tools->_setState($state = 'critical'); |
|
270 |
break; |
|
271 |
} |
|
272 |
} |
|
273 |
} |
|
274 |
} |
|
275 |
} |
|
276 |
} |
5de2af
|
277 |
|
d7f1c8
|
278 |
/* |
FS |
279 |
* LSI MegaRaid |
|
280 |
*/ |
|
281 |
system('which megacli', $retval); |
|
282 |
system('which megacli64', $retval64); |
|
283 |
if($retval === 0 || $retval64 === 0) { |
|
284 |
$binary=@($retval === 0)?'megacli':'megacli64'; |
|
285 |
$state = 'ok'; |
|
286 |
$data['output'] = shell_exec($binary.' -LDInfo -Lall -aAll'); |
|
287 |
if (strpos($data['output'], 'Optimal') !== false) { |
|
288 |
$this->_tools->_setState($state, 'ok'); |
|
289 |
} else if (strpos($data['output'], 'Degraded') !== false) { |
|
290 |
$this->_tools->_setState($state, 'critical'); |
|
291 |
} else if (strpos($data['output'], 'Offline') !== false) { |
|
292 |
$this->_tools->_setState($state, 'critical'); |
|
293 |
} else { |
|
294 |
$this->_tools->_setState($state, 'critical'); |
|
295 |
} |
|
296 |
} |
|
297 |
|
5e205c
|
298 |
/* |
FS |
299 |
* Adaptec-RAID |
|
300 |
*/ |
|
301 |
system('which arcconf', $retval); |
|
302 |
if($retval === 0) { |
|
303 |
$state = 'ok'; |
|
304 |
$data['output'] = shell_exec('arcconf GETCONFIG 1 LD'); |
|
305 |
if(is_array($data['output'])) { |
|
306 |
foreach ($data['output'] as $item) { |
|
307 |
if (strpos($item, 'Logical device name : RAID') !== false) { |
|
308 |
if (strpos($item, 'Optimal') !== false) { |
|
309 |
$this->_tools->_setState($state, 'ok'); |
|
310 |
} else { |
|
311 |
$this->_tools->_setState($state, 'critical'); |
|
312 |
} |
|
313 |
} |
|
314 |
} |
|
315 |
} |
|
316 |
} |
d7f1c8
|
317 |
|
5de2af
|
318 |
$res = array(); |
M |
319 |
$res['server_id'] = $server_id; |
|
320 |
$res['type'] = $type; |
|
321 |
$res['data'] = $data; |
|
322 |
$res['state'] = $state; |
|
323 |
|
|
324 |
/* |
|
325 |
* Insert the data into the database |
|
326 |
*/ |
|
327 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
cc7a82
|
328 |
'VALUES (?, ?, UNIX_TIMESTAMP(), ?, ?)'; |
MC |
329 |
$app->dbmaster->query($sql, $res['server_id'], $res['type'], serialize($res['data']), $res['state']); |
5de2af
|
330 |
|
M |
331 |
/* The new data is written, now we can delete the old one */ |
|
332 |
$this->_tools->delOldRecords($res['type'], $res['server_id']); |
b1a6a5
|
333 |
|
MC |
334 |
parent::onRunJob(); |
|
335 |
} |
|
336 |
|
|
337 |
/* this function is optional if it contains no custom code */ |
|
338 |
public function onAfterRun() { |
|
339 |
global $app; |
|
340 |
|
|
341 |
parent::onAfterRun(); |
|
342 |
} |
5de2af
|
343 |
|
M |
344 |
} |
|
345 |
|
|
346 |
?> |