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 |
|
|
232 |
|
|
233 |
$res = array(); |
|
234 |
$res['server_id'] = $server_id; |
|
235 |
$res['type'] = $type; |
|
236 |
$res['data'] = $data; |
|
237 |
$res['state'] = $state; |
|
238 |
|
|
239 |
/* |
|
240 |
* Insert the data into the database |
|
241 |
*/ |
|
242 |
$sql = 'REPLACE INTO monitor_data (server_id, type, created, data, state) ' . |
b1a6a5
|
243 |
'VALUES (' . |
MC |
244 |
$res['server_id'] . ', ' . |
|
245 |
"'" . $app->dbmaster->quote($res['type']) . "', " . |
|
246 |
'UNIX_TIMESTAMP(), ' . |
|
247 |
"'" . $app->dbmaster->quote(serialize($res['data'])) . "', " . |
|
248 |
"'" . $res['state'] . "'" . |
|
249 |
')'; |
5de2af
|
250 |
$app->dbmaster->query($sql); |
M |
251 |
|
|
252 |
/* The new data is written, now we can delete the old one */ |
|
253 |
$this->_tools->delOldRecords($res['type'], $res['server_id']); |
b1a6a5
|
254 |
|
MC |
255 |
parent::onRunJob(); |
|
256 |
} |
|
257 |
|
|
258 |
/* this function is optional if it contains no custom code */ |
|
259 |
public function onAfterRun() { |
|
260 |
global $app; |
|
261 |
|
|
262 |
parent::onAfterRun(); |
|
263 |
} |
5de2af
|
264 |
|
M |
265 |
} |
|
266 |
|
|
267 |
?> |