commit | author | age
|
8793b3
|
1 |
<?php |
V |
2 |
/* |
220bb9
|
3 |
Copyright (c) 2007-2010, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com |
8793b3
|
4 |
All rights reserved. |
V |
5 |
|
|
6 |
Redistribution and use in source and binary forms, with or without modification, |
|
7 |
are permitted provided that the following conditions are met: |
|
8 |
|
|
9 |
* Redistributions of source code must retain the above copyright notice, |
|
10 |
this list of conditions and the following disclaimer. |
|
11 |
* Redistributions in binary form must reproduce the above copyright notice, |
|
12 |
this list of conditions and the following disclaimer in the documentation |
|
13 |
and/or other materials provided with the distribution. |
|
14 |
* Neither the name of ISPConfig nor the names of its contributors |
|
15 |
may be used to endorse or promote products derived from this software without |
|
16 |
specific prior written permission. |
|
17 |
|
|
18 |
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
|
19 |
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|
20 |
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
|
21 |
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, |
|
22 |
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |
|
23 |
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
|
24 |
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY |
|
25 |
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
26 |
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, |
|
27 |
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
28 |
*/ |
|
29 |
|
7fe908
|
30 |
require_once '../../lib/config.inc.php'; |
MC |
31 |
require_once '../../lib/app.inc.php'; |
8793b3
|
32 |
|
V |
33 |
/* Check permissions for module */ |
|
34 |
$app->auth->check_module_permissions('monitor'); |
|
35 |
|
|
36 |
/* Change the Server if needed */ |
c9d97b
|
37 |
if (isset($_GET['server'])) { |
V |
38 |
$server = explode('|', $_GET['server'], 2); |
|
39 |
$_SESSION['monitor']['server_id'] = $server[0]; |
|
40 |
$_SESSION['monitor']['server_name'] = $server[1]; |
8793b3
|
41 |
} |
V |
42 |
|
|
43 |
/* |
|
44 |
* Loading the template |
c9d97b
|
45 |
*/ |
8793b3
|
46 |
$app->uses('tpl'); |
V |
47 |
$app->tpl->newTemplate("form.tpl.htm"); |
7fe908
|
48 |
$app->tpl->setInclude('content_tpl', 'templates/show_sys_state.htm'); |
8793b3
|
49 |
|
55eb00
|
50 |
/* Get some translations */ |
A |
51 |
$monTransRefreshsq = $app->lng("monitor_settings_refreshsq_txt"); |
|
52 |
|
8793b3
|
53 |
/* |
V |
54 |
* setting the content |
c9d97b
|
55 |
*/ |
V |
56 |
if ($_GET['state'] == 'server') { |
|
57 |
$res = _getServerState($_SESSION['monitor']['server_id'], $_SESSION['monitor']['server_name'], true); |
|
58 |
$output = $res['html_verbose']; |
|
59 |
$title = $app->lng("monitor_general_serverstate_txt"); |
|
60 |
$stateType = 'server'; |
8793b3
|
61 |
} |
c9d97b
|
62 |
else { |
V |
63 |
$output = _getSysState(); |
|
64 |
$title = $app->lng("monitor_general_systemstate_txt"); |
|
65 |
$stateType = 'system'; |
8793b3
|
66 |
} |
V |
67 |
|
7fe908
|
68 |
$app->tpl->setVar("state_data", $output); |
MC |
69 |
$app->tpl->setVar("state_type", $stateType); |
|
70 |
$app->tpl->setVar("list_head_txt", $title); |
|
71 |
$app->tpl->setVar("list_desc_txt", (isset($description) ? $description : '')); |
55eb00
|
72 |
$app->tpl->setVar("monTransRefreshsq", $monTransRefreshsq); |
8793b3
|
73 |
|
V |
74 |
/* |
9cd0f6
|
75 |
Creating the array with the refresh intervals |
7e3524
|
76 |
Attention: the core-module ist triggered every 5 minutes, |
9cd0f6
|
77 |
so reload every 2 minutes is impossible! |
V |
78 |
*/ |
65ea2e
|
79 |
$refresh = (isset($_GET["refresh"]))?$app->functions->intval($_GET["refresh"]):0; |
9cd0f6
|
80 |
|
7fe908
|
81 |
$refresh_values = array('0' => '- '.$app->lng("No Refresh").' -', '5' => '5 '.$app->lng("minutes"), '10' => '10 '.$app->lng("minutes"), '15' => '15 '.$app->lng("minutes"), '30' => '30 '.$app->lng("minutes"), '60' => '60 '.$app->lng("minutes")); |
9cd0f6
|
82 |
$tmp = ''; |
V |
83 |
foreach($refresh_values as $key => $val) { |
|
84 |
if($key == $refresh) { |
|
85 |
$tmp .= "<option value='$key' SELECTED>$val</option>"; |
|
86 |
} else { |
|
87 |
$tmp .= "<option value='$key'>$val</option>"; |
|
88 |
} |
|
89 |
} |
c9d97b
|
90 |
$app->tpl->setVar("refresh", $tmp); |
9cd0f6
|
91 |
|
V |
92 |
/* |
8793b3
|
93 |
* doing the output |
c9d97b
|
94 |
*/ |
8793b3
|
95 |
$app->tpl_defaults(); |
V |
96 |
$app->tpl->pparse(); |
|
97 |
|
|
98 |
|
c9d97b
|
99 |
/* |
V |
100 |
* Creates HTML representing the state of the system (of all servers) |
|
101 |
*/ |
|
102 |
function _getSysState() { |
|
103 |
global $app; |
8793b3
|
104 |
|
c9d97b
|
105 |
/** The data of all Servers as (sorted by name) array */ |
7fe908
|
106 |
|
MC |
107 |
|
c9d97b
|
108 |
$serverData = array(); |
8793b3
|
109 |
|
c9d97b
|
110 |
/* |
V |
111 |
* Get all servers and calculate the state of them |
|
112 |
*/ |
|
113 |
$servers = $app->db->queryAllRecords("SELECT server_id, server_name FROM server order by server_name"); |
|
114 |
foreach ($servers as $server) { |
|
115 |
$serverData[] = _getServerState($server['server_id'], $server['server_name'], false); |
|
116 |
} |
8793b3
|
117 |
|
c9d97b
|
118 |
/* |
V |
119 |
* Now we have a array with all servers. Some of them are normal servers, some of them |
|
120 |
* are OpenVz-Hosts and some are OpenVz-VE's. Next we need to know which of them are |
|
121 |
* OpenVz-VE's inside a OpenVz-Host (managed by the Monitor). If there is a OpenVZ-VE |
|
122 |
* inside a OpenVz-Host which is NOT in the Server-Farm and so not handled by the monitor, |
|
123 |
* we handle it like a "normal" server (in the output of the system-state) |
|
124 |
*/ |
|
125 |
foreach ($serverData as $data) { |
|
126 |
/* get all VE's of this server */ |
|
127 |
$veInfo = $data['ve_info']; |
|
128 |
|
|
129 |
/* |
|
130 |
* if we found some, mark them all as VE's |
|
131 |
*/ |
|
132 |
if (is_array($veInfo)) { |
|
133 |
foreach ($veInfo as $info) { |
|
134 |
for ($i = 0; $i < sizeof($serverData); $i++) { |
|
135 |
if ($serverData[$i]['server_name'] == $info['hostname']) { |
|
136 |
$serverData[$i]['is_ve'] = true; |
|
137 |
} |
|
138 |
} |
|
139 |
} |
|
140 |
} |
|
141 |
} |
d1d9bc
|
142 |
|
c9d97b
|
143 |
/* |
V |
144 |
* Now we have to output all "normal" server or all OpenVZ-Hosts (or all OpenVZ-VE's without |
|
145 |
* a OpenVZ-Host managed by ISPConfig). The OpenVz-VE's are then included in them... |
|
146 |
*/ |
|
147 |
$html = ''; |
|
148 |
|
|
149 |
foreach ($serverData as $data) { |
|
150 |
if (!isset($data['is_ve'])) { |
|
151 |
/* |
|
152 |
* it is NOT a Ve, so do the output of this server and off all VE's included in them |
d1d9bc
|
153 |
*/ |
c9d97b
|
154 |
$html .= $data['html_server']; |
V |
155 |
/* get all VE's of this server */ |
|
156 |
$veInfo = $data['ve_info']; |
d4db60
|
157 |
if(is_array($veInfo)) { |
T |
158 |
foreach ($veInfo as $info) { |
|
159 |
for ($i = 0; $i < sizeof($serverData); $i++) { |
|
160 |
if ($serverData[$i]['server_name'] == $info['hostname']) { |
|
161 |
$html = str_replace('##VE_INFO##', $serverData[$i]['html_ve'] . '##VE_INFO##', $html); |
|
162 |
} |
c9d97b
|
163 |
} |
V |
164 |
} |
|
165 |
} |
|
166 |
$html = str_replace('##VE_INFO##', '', $html); |
|
167 |
} |
|
168 |
} |
|
169 |
return $html; |
8793b3
|
170 |
} |
V |
171 |
|
c9d97b
|
172 |
|
V |
173 |
/** |
|
174 |
* returns the state and html of ONE Server |
|
175 |
* @param integer $serverId the id of the server |
|
176 |
* @param string $serverName the hostname (like server1.yourdomain.com) |
|
177 |
* @return array the state and representing html of the server |
8793b3
|
178 |
*/ |
c9d97b
|
179 |
function _getServerState($serverId, $serverName) { |
V |
180 |
global $app; |
8793b3
|
181 |
|
c9d97b
|
182 |
/* The State of the server */ |
V |
183 |
$serverState = 'ok'; |
8793b3
|
184 |
|
c9d97b
|
185 |
/** The messages */ |
V |
186 |
$messages = array(); |
8793b3
|
187 |
|
c9d97b
|
188 |
/** The Result of the function */ |
V |
189 |
$res = ''; |
8793b3
|
190 |
|
c9d97b
|
191 |
/* |
V |
192 |
* Get all monitoring-data from the server and process then |
|
193 |
*/ |
cc7a82
|
194 |
$records = $app->db->queryAllRecords("SELECT DISTINCT type, data FROM monitor_data WHERE server_id = ?", $serverId); |
c9d97b
|
195 |
$osData = null; |
V |
196 |
$veInfo = null; |
82927e
|
197 |
$ispcData = null; |
c9d97b
|
198 |
foreach($records as $record) { |
V |
199 |
/* get the state from the db-data */ |
b67344
|
200 |
$tmp = _processDbState($record['type'], $serverId, $serverState, $messages); |
T |
201 |
$serverState = $tmp['serverState']; |
|
202 |
$messages = $tmp['messages']; |
7fe908
|
203 |
|
220bb9
|
204 |
/* if we have the os-info, get it */ |
c9d97b
|
205 |
if ($record['type'] == 'os_info') { |
V |
206 |
$osData = unserialize($record['data']); |
82927e
|
207 |
} |
V |
208 |
/* if we have the ISPConfig-info, get it */ |
|
209 |
if ($record['type'] == 'ispc_info') { |
|
210 |
$ispcData = unserialize($record['data']); |
c9d97b
|
211 |
} |
V |
212 |
/* if we have the ve-info, get it */ |
|
213 |
if ($record['type'] == 'openvz_veinfo') { |
|
214 |
$veInfo = unserialize($record['data']); |
|
215 |
} |
220bb9
|
216 |
} |
55eb00
|
217 |
|
c9d97b
|
218 |
/* |
V |
219 |
* We now have the state of the server. Lets now create the HTML representing this state. |
|
220 |
* If we actually don't know, which type of verbose we need, let's create all |
|
221 |
*/ |
8793b3
|
222 |
|
c9d97b
|
223 |
/* |
V |
224 |
* Info of a VE inside a OpenVz-Host |
|
225 |
*/ |
942a60
|
226 |
|
TB |
227 |
$alert_class = 'alert-info'; |
|
228 |
if($serverState == 'ok') $alert_class = 'alert-success'; |
|
229 |
if($serverState == 'warning') $alert_class = 'alert-warning'; |
|
230 |
if($serverState == 'critical' || $serverState == 'error') $alert_class = 'alert-danger'; |
|
231 |
|
6faf14
|
232 |
//$html_ve = '<div class="systemmonitor-ve state-' . $serverState . '-ve os-' . $osData['name'] . '">'; |
942a60
|
233 |
//$html_ve = '<div class="systemmonitor state-' . $serverState . ' os-' . $osData['name'] . '">'; |
TB |
234 |
$html_server = '<div class="alert '.$alert_class.'" role="alert">'; |
7fe908
|
235 |
if ($osData != null) { |
MC |
236 |
$html_ve .= '<div class="icoDevice"><p class="status"></p></div>'; |
|
237 |
} |
|
238 |
else { |
|
239 |
$html_ve .= '<div class="icoDevice"><p class="status"></p></div>'; |
|
240 |
} |
942a60
|
241 |
$html_ve .= '<div class="statusDevice"><h3>' . $serverName; |
c9d97b
|
242 |
if ($osData != null) { |
d311c5
|
243 |
$html_ve .= ' (' . $osData['name'] . ' ' . $osData['version'] . ') '; |
c9d97b
|
244 |
} |
82927e
|
245 |
if ($ispcData != null) { |
942a60
|
246 |
$html_ve .= $ispcData['name'] . ' ' . $ispcData['version'] . '</h3>'; |
82927e
|
247 |
} |
7fe908
|
248 |
else { |
942a60
|
249 |
$html_ve .= '</h3>'; |
7fe908
|
250 |
} |
d311c5
|
251 |
$html_ve .= '<p>' . $app->lng("monitor_serverstate_state_txt") . ': ' . $serverState . '</p>'; |
8793b3
|
252 |
|
c9d97b
|
253 |
/* |
V |
254 |
* Info of a "normal" Server or a OpenVz-Host |
|
255 |
*/ |
942a60
|
256 |
//$html_server = '<div class="systemmonitor-server state-' . $serverState . ' os-' . $osData['name'] . '">'; |
TB |
257 |
|
|
258 |
/* |
|
259 |
switch ($oldState) { |
|
260 |
case 'no_state': $oldInt = 0; |
|
261 |
break; |
|
262 |
case 'ok': $oldInt = 1; |
|
263 |
break; |
|
264 |
case 'unknown': $oldInt = 2; |
|
265 |
break; |
|
266 |
case 'info': $oldInt = 3; |
|
267 |
break; |
|
268 |
case 'warning': $oldInt = 4; |
|
269 |
break; |
|
270 |
case 'critical': $oldInt = 5; |
|
271 |
break; |
|
272 |
case 'error': $oldInt = 6; |
|
273 |
break; |
|
274 |
*/ |
|
275 |
$alert_class = 'alert-info'; |
|
276 |
if($serverState == 'ok') $alert_class = 'alert-success'; |
|
277 |
if($serverState == 'warning') $alert_class = 'alert-warning'; |
|
278 |
if($serverState == 'critical' || $serverState == 'error') $alert_class = 'alert-danger'; |
|
279 |
|
|
280 |
$html_server = '<div class="alert '.$alert_class.'" role="alert">'; |
c9d97b
|
281 |
if ($osData != null) { |
942a60
|
282 |
//$html_server .= '<div class="icoDevice"><p class="status"></p></div>'; |
7fe908
|
283 |
} |
MC |
284 |
else { |
|
285 |
$html_server .= '<div class="icoDevice"><p class="status"></p></div>'; |
|
286 |
} |
942a60
|
287 |
$html_server .= '<div class="statusDevice"><h3>' . $app->lng("monitor_serverstate_server_txt") . ': ' . $serverName; |
d311c5
|
288 |
if ($osData != null) { |
7fe908
|
289 |
$html_server .= ' (' . $osData['name'] . ' ' . $osData['version'] . ') '; |
c9d97b
|
290 |
} |
82927e
|
291 |
if ($ispcData != null) { |
942a60
|
292 |
$html_server .= $ispcData['name'] . ' ' . $ispcData['version'] . '</h3>'; |
82927e
|
293 |
} |
7fe908
|
294 |
else { |
942a60
|
295 |
$html_server .= '</h3>'; |
7fe908
|
296 |
} |
8793b3
|
297 |
|
d311c5
|
298 |
$html_server .= '<p>' . $app->lng("monitor_serverstate_state_txt") . ': ' . $serverState . ' ('; |
a8b07f
|
299 |
$html_server .= sizeof((isset($messages[$app->lng("monitor_serverstate_listunknown_txt")]) ? $messages[$app->lng("monitor_serverstate_listunknown_txt")] : array())) . ' ' . $app->lng("monitor_serverstate_unknown_txt") . ', '; |
X |
300 |
$html_server .= sizeof((isset($messages[$app->lng("monitor_serverstate_listinfo_txt")]) ? $messages[$app->lng("monitor_serverstate_listinfo_txt")] : array())) . ' ' . $app->lng("monitor_serverstate_info_txt") . ', '; |
|
301 |
$html_server .= sizeof((isset($messages[$app->lng("monitor_serverstate_listwarning_txt")]) ? $messages[$app->lng("monitor_serverstate_listwarning_txt")] : array())) . ' ' . $app->lng("monitor_serverstate_warning_txt") . ', '; |
|
302 |
$html_server .= sizeof((isset($messages[$app->lng("monitor_serverstate_listcritical_txt")]) ? $messages[$app->lng("monitor_serverstate_listcritical_txt")] : array())) . ' ' . $app->lng("monitor_serverstate_critical_txt") . ', '; |
|
303 |
$html_server .= sizeof((isset($messages[$app->lng("monitor_serverstate_listerror_txt")]) ? $messages[$app->lng("monitor_serverstate_listerror_txt")] : array())) . ' ' . $app->lng("monitor_serverstate_error_txt") . ''; |
d311c5
|
304 |
$html_server .= ')</p>'; |
8793b3
|
305 |
|
c9d97b
|
306 |
/* |
7fe908
|
307 |
* Verbose - Info |
c9d97b
|
308 |
*/ |
V |
309 |
$html_verbose = $html_server; |
d1d9bc
|
310 |
foreach($messages as $key => $state) { |
942a60
|
311 |
$html_verbose .= '<strong>'.ucfirst($key) . '</strong><br />'; |
e4efe7
|
312 |
foreach ($state as $msg) { |
V |
313 |
$html_verbose .= $msg . '<br />'; |
c9d97b
|
314 |
} |
e4efe7
|
315 |
$html_verbose .= '<br />'; |
c9d97b
|
316 |
} |
V |
317 |
|
|
318 |
/* |
|
319 |
* The normal info also needs a link to the verbose info |
|
320 |
*/ |
9021d7
|
321 |
$html_ve .= "<a href='#' data-load-content='monitor/show_sys_state.php?state=server&server=" . $serverId . '|' . $serverName . "'>" . $app->lng("monitor_serverstate_moreinfo_txt") . "</a>"; |
MC |
322 |
$html_server .= "<a href='#' data-load-content='monitor/show_sys_state.php?state=server&server=" . $serverId . '|' . $serverName . "'>" . $app->lng("monitor_serverstate_moreinfo_txt") . "</a>"; |
c9d97b
|
323 |
|
V |
324 |
/* |
|
325 |
* Finish all html's |
|
326 |
*/ |
ebc41d
|
327 |
$html_ve .= '</div></div>'; |
C |
328 |
$html_server .= '<div>##VE_INFO##</div></div></div>'; |
|
329 |
$html_verbose .= '</div></div>'; |
c9d97b
|
330 |
|
V |
331 |
/* |
|
332 |
* create and return the result |
|
333 |
*/ |
|
334 |
$res['state'] = $serverState; |
|
335 |
$res['server_name'] = $serverName; |
|
336 |
$res['html_server'] = $html_server; |
|
337 |
$res['html_ve'] = $html_ve; |
|
338 |
$res['html_verbose'] = $html_verbose; |
|
339 |
$res['ve_info'] = $veInfo; |
|
340 |
return $res; |
8793b3
|
341 |
} |
V |
342 |
|
|
343 |
/* |
e4efe7
|
344 |
* gets the state from the db and process it |
c9d97b
|
345 |
*/ |
e94a9f
|
346 |
function _processDbState($type, $serverId, $serverState, $messages) { |
T |
347 |
global $app; |
8793b3
|
348 |
|
c9d97b
|
349 |
/* |
8793b3
|
350 |
* Always the NEWEST record of each monitoring is responsible for the |
V |
351 |
* state |
c9d97b
|
352 |
*/ |
e4efe7
|
353 |
// get the State from the DB |
cc7a82
|
354 |
$record = $app->db->queryOneRecord("SELECT state FROM monitor_data WHERE type = ? and server_id = ? order by created desc", $type, $serverId); |
e4efe7
|
355 |
|
V |
356 |
// change the new state to the highest state |
|
357 |
/* |
|
358 |
* Monitoring the user_beancounter of a VE is not as easy as i thought, so for now ignore |
|
359 |
* this state (if we have a better solution) |
|
360 |
*/ |
|
361 |
if ($type != 'openvz_beancounter') { |
|
362 |
$serverState = _setState($serverState, $record['state']); |
|
363 |
} |
8793b3
|
364 |
|
c9d97b
|
365 |
/* |
8793b3
|
366 |
* The message depands on the type and the state |
c9d97b
|
367 |
*/ |
V |
368 |
if ($type == 'cpu_info') { |
|
369 |
/* this type has no state */ |
|
370 |
} |
|
371 |
if ($type == 'disk_usage') { |
|
372 |
switch ($record['state']) { |
7fe908
|
373 |
case 'ok': |
MC |
374 |
$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_hdok_txt") . ' ' . |
9021d7
|
375 |
"<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
376 |
break; |
MC |
377 |
case 'info': |
|
378 |
$messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_hdgoingfull_txt") . ' ' . |
9021d7
|
379 |
"<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
380 |
break; |
MC |
381 |
case 'warning': |
|
382 |
$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_hdnearlyfull_txt") . ' ' . |
9021d7
|
383 |
"<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
384 |
break; |
MC |
385 |
case 'critical': |
|
386 |
$messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_hdveryfull_txt") . ' ' . |
9021d7
|
387 |
"<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
388 |
break; |
MC |
389 |
case 'error': |
|
390 |
$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_hdfull_txt") . ' ' . |
9021d7
|
391 |
"<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
392 |
break; |
8793b3
|
393 |
|
7fe908
|
394 |
default: |
MC |
395 |
$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_hdunknown_txt") . ' ' . |
9021d7
|
396 |
"<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
397 |
break; |
c9d97b
|
398 |
} |
V |
399 |
} |
|
400 |
if ($type == 'mem_usage') { |
|
401 |
/* this type has no state */ |
|
402 |
} |
|
403 |
if ($type == 'server_load') { |
|
404 |
switch ($record['state']) { |
7fe908
|
405 |
case 'ok': |
MC |
406 |
$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_loadok_txt") . ' ' . |
9021d7
|
407 |
"<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
408 |
break; |
MC |
409 |
case 'info': |
|
410 |
$messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_loadheavy_txt") . ' ' . |
9021d7
|
411 |
"<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
412 |
break; |
MC |
413 |
case 'warning': |
|
414 |
$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_loadhigh_txt") . ' ' . |
9021d7
|
415 |
"<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
416 |
break; |
MC |
417 |
case 'critical': |
|
418 |
$messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_loadhigher_txt") . ' ' . |
9021d7
|
419 |
"<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
420 |
break; |
MC |
421 |
case 'error': |
|
422 |
$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_loadhighest_txt") . ' ' . |
9021d7
|
423 |
"<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
424 |
break; |
MC |
425 |
default: |
|
426 |
$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_loadunknown_txt") . ' ' . |
9021d7
|
427 |
"<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
428 |
break; |
c9d97b
|
429 |
} |
V |
430 |
} |
|
431 |
if ($type == 'services') { |
|
432 |
switch ($record['state']) { |
7fe908
|
433 |
case 'ok': |
MC |
434 |
$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_servicesonline_txt") . ' ' . |
9021d7
|
435 |
"<a href='#' data-load-content='monitor/show_data.php?type=services'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
8793b3
|
436 |
|
7fe908
|
437 |
break; |
MC |
438 |
case 'error': |
|
439 |
$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_servicesoffline_txt") . ' ' . |
9021d7
|
440 |
"<a href='#' data-load-content='monitor/show_data.php?type=services'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
441 |
break; |
MC |
442 |
default: |
|
443 |
$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_servicesunknown_txt") . ' ' . |
9021d7
|
444 |
"<a href='#' data-load-content='monitor/show_data.php?type=services'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
445 |
break; |
c9d97b
|
446 |
} |
V |
447 |
} |
|
448 |
if ($type == 'system_update') { |
|
449 |
switch ($record['state']) { |
7fe908
|
450 |
case 'ok': |
MC |
451 |
$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_updatesok_txt") . ' ' . |
9021d7
|
452 |
"<a href='#' data-load-content='monitor/show_data.php?type=system_update'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
716255
|
453 |
|
7fe908
|
454 |
break; |
MC |
455 |
case 'info': |
|
456 |
$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_updatesneeded_txt") . ' ' . |
9021d7
|
457 |
"<a href='#' data-load-content='monitor/show_data.php?type=system_update'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
458 |
break; |
MC |
459 |
case 'no_state': |
c9d97b
|
460 |
/* |
36d307
|
461 |
* not debian and not Ubuntu, so the state could not be monitored... |
c9d97b
|
462 |
*/ |
7fe908
|
463 |
break; |
MC |
464 |
default: |
|
465 |
$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_updatesunknown_txt") . ' ' . |
9021d7
|
466 |
"<a href='#' data-load-content='monitor/show_data.php?type=system_update'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
467 |
break; |
c9d97b
|
468 |
} |
V |
469 |
} |
716255
|
470 |
|
c9d97b
|
471 |
if ($type == 'raid_state') { |
V |
472 |
switch ($record['state']) { |
7fe908
|
473 |
case 'ok': |
MC |
474 |
$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_raidok_txt") . ' ' . |
9021d7
|
475 |
"<a href='#' data-load-content='monitor/show_data.php?type=raid_state'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
476 |
break; |
MC |
477 |
case 'info': |
|
478 |
$messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_raidresync_txt") . ' ' . |
9021d7
|
479 |
"<a href='#' data-load-content='monitor/show_data.php?type=raid_state'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
480 |
break; |
MC |
481 |
case 'critical': |
|
482 |
$messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_raidfault_txt") . ' ' . |
9021d7
|
483 |
"<a href='#' data-load-content='monitor/show_data.php?type=raid_state'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
484 |
break; |
MC |
485 |
case 'error': |
|
486 |
$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_raiderror_txt") . ' ' . |
9021d7
|
487 |
"<a href='#' data-load-content='monitor/show_data.php?type=raid_state'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
488 |
break; |
MC |
489 |
case 'no_state': |
c9d97b
|
490 |
/* |
36d307
|
491 |
* mdadm is not installed or the RAID is not supported... |
c9d97b
|
492 |
*/ |
7fe908
|
493 |
break; |
MC |
494 |
default: |
|
495 |
$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_raidunknown_txt") . ' ' . |
9021d7
|
496 |
"<a href='#' data-load-content='monitor/show_data.php?type=raid_state'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
497 |
break; |
c9d97b
|
498 |
} |
V |
499 |
} |
|
500 |
|
e4efe7
|
501 |
/* |
V |
502 |
* ignore, until we find a better solution |
|
503 |
*/ |
7fe908
|
504 |
// if ($type == 'openvz_beancounter') { |
MC |
505 |
// switch ($record['state']) { |
|
506 |
// case 'ok': |
|
507 |
// $messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_beancounterok_txt") . ' ' . |
9021d7
|
508 |
// "<a href='#' data-load-content='monitor/show_data.php?type=openvz_beancounter'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
509 |
// break; |
MC |
510 |
// case 'info': |
|
511 |
// $messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_beancounterinfo_txt") . ' ' . |
9021d7
|
512 |
// "<a href='#' data-load-content='monitor/show_data.php?type=openvz_beancounter'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
513 |
// break; |
MC |
514 |
// case 'warning': |
|
515 |
// $messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_beancounterwarning_txt") . ' ' . |
9021d7
|
516 |
// "<a href='#' data-load-content='monitor/show_data.php?type=openvz_beancounter'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
517 |
// break; |
MC |
518 |
// case 'critical': |
|
519 |
// $messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_beancountercritical_txt") . ' ' . |
9021d7
|
520 |
// "<a href='#' data-load-content='monitor/show_data.php?type=openvz_beancounter'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
521 |
// break; |
MC |
522 |
// case 'error': |
|
523 |
// $messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_beancountererror_txt") . ' ' . |
9021d7
|
524 |
// "<a href='#' data-load-content='monitor/show_data.php?type=openvz_beancounter'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
525 |
// break; |
MC |
526 |
// default: |
|
527 |
// break; |
|
528 |
// } |
|
529 |
// } |
36d307
|
530 |
|
V |
531 |
|
c9d97b
|
532 |
if ($type == 'mailq') { |
V |
533 |
switch ($record['state']) { |
7fe908
|
534 |
case 'ok': |
MC |
535 |
$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_mailqok_txt") . ' ' . |
9021d7
|
536 |
"<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
537 |
break; |
MC |
538 |
case 'info': |
|
539 |
$messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_mailqheavy_txt") . ' ' . |
9021d7
|
540 |
"<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
541 |
break; |
MC |
542 |
case 'warning': |
|
543 |
$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_mailqhigh_txt") . ' ' . |
9021d7
|
544 |
"<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
545 |
break; |
MC |
546 |
case 'critical': |
|
547 |
$messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_mailqhigher_txt") . ' ' . |
9021d7
|
548 |
"<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
549 |
break; |
MC |
550 |
case 'error': |
|
551 |
$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_mailqhighest_txt") . ' ' . |
9021d7
|
552 |
"<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
553 |
break; |
MC |
554 |
default: |
|
555 |
$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_mailqunknown_txt") . ' ' . |
9021d7
|
556 |
"<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
557 |
break; |
c9d97b
|
558 |
} |
V |
559 |
} |
671a41
|
560 |
|
c9d97b
|
561 |
if ($type == 'sys_log') { |
V |
562 |
switch ($record['state']) { |
7fe908
|
563 |
case 'ok': |
MC |
564 |
$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_syslogok_txt") . ' ' . |
9021d7
|
565 |
"<a href='#' data-load-content='monitor/log_list.php'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
566 |
break; |
MC |
567 |
case 'warning': |
|
568 |
$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_syslogwarning_txt") . ' ' . |
9021d7
|
569 |
"<a href='#' data-load-content='monitor/log_list.php'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
570 |
break; |
MC |
571 |
case 'error': |
|
572 |
$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_syslogerror_txt") . ' ' . |
9021d7
|
573 |
"<a href='#' data-load-content='monitor/log_list.php'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
574 |
break; |
MC |
575 |
default: |
|
576 |
$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_syslogunknown_txt") . ' ' . |
9021d7
|
577 |
"<a href='#' data-load-content='monitor/log_list.php'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
578 |
break; |
c9d97b
|
579 |
} |
V |
580 |
} |
671a41
|
581 |
|
c9d97b
|
582 |
if ($type == 'log_clamav') { |
V |
583 |
/* this type has no state */ |
|
584 |
} |
671a41
|
585 |
|
c9d97b
|
586 |
if ($type == 'log_freshclam') { |
V |
587 |
switch ($record['state']) { |
7fe908
|
588 |
case 'ok': |
MC |
589 |
$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_fclamok_txt") . ' ' . |
9021d7
|
590 |
"<a href='#' data-load-content='monitor/show_log.php?log=log_freshclam'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
591 |
break; |
MC |
592 |
case 'info': |
|
593 |
$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_fclamoutdated_txt") . ' ' . |
9021d7
|
594 |
"<a href='#' data-load-content='monitor/show_log.php?log=log_freshclam'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
595 |
break; |
MC |
596 |
default: |
|
597 |
$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_fclamunknown_txt") . ' ' . |
9021d7
|
598 |
"<a href='#' data-load-content='monitor/show_log.php?log=log_freshclam'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>"; |
7fe908
|
599 |
break; |
c9d97b
|
600 |
} |
V |
601 |
} |
671a41
|
602 |
|
c9d97b
|
603 |
if ($type == 'log_ispconfig') { |
V |
604 |
/* this type has no state */ |
|
605 |
} |
|
606 |
if ($type == 'log_mail') { |
|
607 |
/* this type has no state */ |
|
608 |
} |
|
609 |
if ($type == 'log_mail_err') { |
|
610 |
/* this type has no state */ |
|
611 |
} |
|
612 |
if ($type == 'log_mail_warn') { |
|
613 |
/* this type has no state */ |
|
614 |
} |
|
615 |
if ($type == 'log_messages') { |
|
616 |
/* this type has no state */ |
|
617 |
} |
|
618 |
if ($type == 'rkhunter') { |
|
619 |
/* this type has no state */ |
|
620 |
} |
7fe908
|
621 |
|
MC |
622 |
return array('serverState' => $serverState, 'messages' => $messages); |
8793b3
|
623 |
} |
V |
624 |
|
c9d97b
|
625 |
/* |
8793b3
|
626 |
* Set the state to the given level (or higher, but not lesser). |
V |
627 |
* * If the actual state is critical and you call the method with ok, |
|
628 |
* then the state is critical. |
|
629 |
* |
|
630 |
* * If the actual state is critical and you call the method with error, |
|
631 |
* then the state is error. |
c9d97b
|
632 |
*/ |
V |
633 |
function _setState($oldState, $newState) { |
|
634 |
/* |
716255
|
635 |
* Calculate the weight of the old state |
c9d97b
|
636 |
*/ |
V |
637 |
switch ($oldState) { |
7fe908
|
638 |
case 'no_state': $oldInt = 0; |
MC |
639 |
break; |
|
640 |
case 'ok': $oldInt = 1; |
|
641 |
break; |
|
642 |
case 'unknown': $oldInt = 2; |
|
643 |
break; |
|
644 |
case 'info': $oldInt = 3; |
|
645 |
break; |
|
646 |
case 'warning': $oldInt = 4; |
|
647 |
break; |
|
648 |
case 'critical': $oldInt = 5; |
|
649 |
break; |
|
650 |
case 'error': $oldInt = 6; |
|
651 |
break; |
c9d97b
|
652 |
} |
V |
653 |
/* |
8793b3
|
654 |
* Calculate the weight of the new state |
c9d97b
|
655 |
*/ |
V |
656 |
switch ($newState) { |
7fe908
|
657 |
case 'no_state': $newInt = 0 ; |
MC |
658 |
break; |
|
659 |
case 'ok': $newInt = 1 ; |
|
660 |
break; |
|
661 |
case 'unknown': $newInt = 2 ; |
|
662 |
break; |
|
663 |
case 'info': $newInt = 3 ; |
|
664 |
break; |
|
665 |
case 'warning': $newInt = 4 ; |
|
666 |
break; |
|
667 |
case 'critical': $newInt = 5 ; |
|
668 |
break; |
|
669 |
case 'error': $newInt = 6 ; |
|
670 |
break; |
c9d97b
|
671 |
} |
8793b3
|
672 |
|
c9d97b
|
673 |
/* |
716255
|
674 |
* Set to the higher level |
c9d97b
|
675 |
*/ |
V |
676 |
if ($newInt > $oldInt) { |
|
677 |
return $newState; |
|
678 |
} |
|
679 |
else { |
|
680 |
return $oldState; |
|
681 |
} |
8793b3
|
682 |
} |
V |
683 |
|
7e3524
|
684 |
?> |