Marius Cramer
2015-08-06 37b29231e47a0c4458dc1c15d98588f16f07e1e2
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     */
6faf14 226     //$html_ve  = '<div class="systemmonitor-ve state-' . $serverState . '-ve os-' . $osData['name'] . '">';
TB 227     $html_ve  = '<div class="systemmonitor state-' . $serverState . ' os-' . $osData['name'] . '">';
7fe908 228     if ($osData != null) {
MC 229         $html_ve .= '<div class="icoDevice"><p class="status"></p></div>';
230     }
231     else {
232         $html_ve .= '<div class="icoDevice"><p class="status"></p></div>';
233     }
d311c5 234     $html_ve .= '<div class="statusDevice"><p>' . $serverName;
c9d97b 235     if ($osData != null) {
d311c5 236         $html_ve .= ' (' . $osData['name'] . ' ' . $osData['version'] . ') ';
c9d97b 237     }
82927e 238     if ($ispcData != null) {
d311c5 239         $html_ve .= $ispcData['name'] . ' ' . $ispcData['version'] . '</p>';
82927e 240     }
7fe908 241     else {
MC 242         $html_ve .= '</p>';
243     }
d311c5 244     $html_ve .= '<p>' . $app->lng("monitor_serverstate_state_txt") . ': ' . $serverState . '</p>';
8793b3 245
c9d97b 246     /*
V 247      * Info of a "normal" Server or a OpenVz-Host
248     */
5ed2f0 249     $html_server = '<div class="systemmonitor-server state-' . $serverState . ' os-' . $osData['name'] . '">';
c9d97b 250     if ($osData != null) {
7fe908 251         $html_server .= '<div class="icoDevice"><p class="status"></p></div>';
MC 252     }
253     else {
254         $html_server .= '<div class="icoDevice"><p class="status"></p></div>';
255     }
d311c5 256     $html_server .= '<div class="statusDevice"><p>' . $app->lng("monitor_serverstate_server_txt") . ': ' . $serverName;
C 257     if ($osData != null) {
7fe908 258         $html_server .= ' (' . $osData['name'] . ' ' . $osData['version'] . ') ';
c9d97b 259     }
82927e 260     if ($ispcData != null) {
7fe908 261         $html_server .= $ispcData['name'] . ' ' . $ispcData['version'] . '</p>';
82927e 262     }
7fe908 263     else {
MC 264         $html_server .= '</p>';
265     }
8793b3 266
d311c5 267     $html_server .= '<p>' . $app->lng("monitor_serverstate_state_txt") . ': ' . $serverState . ' (';
a8b07f 268     $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 269     $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") . ', ';
270     $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") . ', ';
271     $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") . ', ';
272     $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 273     $html_server .= ')</p>';
8793b3 274
c9d97b 275     /*
7fe908 276      * Verbose - Info
c9d97b 277     */
V 278     $html_verbose = $html_server;
d1d9bc 279     foreach($messages as $key => $state) {
e4efe7 280         $html_verbose .= $key . ':<br />';
V 281         foreach ($state as $msg) {
282             $html_verbose .= $msg . '<br />';
c9d97b 283         }
e4efe7 284         $html_verbose .= '<br />';
c9d97b 285     }
V 286
287     /*
288      * The normal info also needs a link to the verbose info
289     */
9021d7 290     $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 291     $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 292
V 293     /*
294      * Finish all html's
295     */
ebc41d 296     $html_ve      .= '</div></div>';
C 297     $html_server  .= '<div>##VE_INFO##</div></div></div>';
298     $html_verbose .= '</div></div>';
c9d97b 299
V 300     /*
301      * create and return the result
302     */
303     $res['state'] = $serverState;
304     $res['server_name'] = $serverName;
305     $res['html_server'] = $html_server;
306     $res['html_ve'] = $html_ve;
307     $res['html_verbose'] = $html_verbose;
308     $res['ve_info'] = $veInfo;
309     return $res;
8793b3 310 }
V 311
312 /*
e4efe7 313 * gets the state from the db and process it
c9d97b 314 */
e94a9f 315 function _processDbState($type, $serverId, $serverState, $messages) {
T 316     global $app;
8793b3 317
c9d97b 318     /*
8793b3 319     * Always the NEWEST record of each monitoring is responsible for the
V 320     * state
c9d97b 321     */
e4efe7 322     // get the State from the DB
cc7a82 323     $record = $app->db->queryOneRecord("SELECT state FROM monitor_data WHERE type = ? and server_id = ? order by created desc", $type, $serverId);
e4efe7 324
V 325     // change the new state to the highest state
326     /*
327     * Monitoring the user_beancounter of a VE is not as easy as i thought, so for now ignore
328     * this state (if we have a better solution)
329     */
330     if ($type != 'openvz_beancounter') {
331         $serverState = _setState($serverState, $record['state']);
332     }
8793b3 333
c9d97b 334     /*
8793b3 335      * The message depands on the type and the state
c9d97b 336     */
V 337     if ($type == 'cpu_info') {
338         /* this type has no state */
339     }
340     if ($type == 'disk_usage') {
341         switch ($record['state']) {
7fe908 342         case 'ok':
MC 343             $messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_hdok_txt") . ' ' .
9021d7 344                 "<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 345             break;
MC 346         case 'info':
347             $messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_hdgoingfull_txt") . ' ' .
9021d7 348                 "<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 349             break;
MC 350         case 'warning':
351             $messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_hdnearlyfull_txt") . ' ' .
9021d7 352                 "<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 353             break;
MC 354         case 'critical':
355             $messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_hdveryfull_txt") . ' ' .
9021d7 356                 "<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 357             break;
MC 358         case 'error':
359             $messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_hdfull_txt") . ' ' .
9021d7 360                 "<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 361             break;
8793b3 362
7fe908 363         default:
MC 364             $messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_hdunknown_txt") . ' ' .
9021d7 365                 "<a href='#' data-load-content='monitor/show_data.php?type=disk_usage'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 366             break;
c9d97b 367         }
V 368     }
369     if ($type == 'mem_usage') {
370         /* this type has no state */
371     }
372     if ($type == 'server_load') {
373         switch ($record['state']) {
7fe908 374         case 'ok':
MC 375             $messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_loadok_txt") . ' ' .
9021d7 376                 "<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 377             break;
MC 378         case 'info':
379             $messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_loadheavy_txt") . ' ' .
9021d7 380                 "<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 381             break;
MC 382         case 'warning':
383             $messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_loadhigh_txt") . ' ' .
9021d7 384                 "<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 385             break;
MC 386         case 'critical':
387             $messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_loadhigher_txt") . ' ' .
9021d7 388                 "<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 389             break;
MC 390         case 'error':
391             $messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_loadhighest_txt") . ' ' .
9021d7 392                 "<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 393             break;
MC 394         default:
395             $messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_loadunknown_txt") . ' ' .
9021d7 396                 "<a href='#' data-load-content='monitor/show_data.php?type=server_load'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 397             break;
c9d97b 398         }
V 399     }
400     if ($type == 'services') {
401         switch ($record['state']) {
7fe908 402         case 'ok':
MC 403             $messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_servicesonline_txt") . ' ' .
9021d7 404                 "<a href='#' data-load-content='monitor/show_data.php?type=services'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
8793b3 405
7fe908 406             break;
MC 407         case 'error':
408             $messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_servicesoffline_txt") . ' ' .
9021d7 409                 "<a href='#' data-load-content='monitor/show_data.php?type=services'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 410             break;
MC 411         default:
412             $messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_servicesunknown_txt") . ' ' .
9021d7 413                 "<a href='#' data-load-content='monitor/show_data.php?type=services'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 414             break;
c9d97b 415         }
V 416     }
417     if ($type == 'system_update') {
418         switch ($record['state']) {
7fe908 419         case 'ok':
MC 420             $messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_updatesok_txt") . ' ' .
9021d7 421                 "<a href='#' data-load-content='monitor/show_data.php?type=system_update'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
716255 422
7fe908 423             break;
MC 424         case 'info':
425             $messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_updatesneeded_txt") . ' ' .
9021d7 426                 "<a href='#' data-load-content='monitor/show_data.php?type=system_update'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 427             break;
MC 428         case 'no_state':
c9d97b 429             /*
36d307 430                  *  not debian and not Ubuntu, so the state could not be monitored...
c9d97b 431             */
7fe908 432             break;
MC 433         default:
434             $messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_updatesunknown_txt") . ' ' .
9021d7 435                 "<a href='#' data-load-content='monitor/show_data.php?type=system_update'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 436             break;
c9d97b 437         }
V 438     }
716255 439
c9d97b 440     if ($type == 'raid_state') {
V 441         switch ($record['state']) {
7fe908 442         case 'ok':
MC 443             $messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_raidok_txt") . ' ' .
9021d7 444                 "<a href='#' data-load-content='monitor/show_data.php?type=raid_state'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 445             break;
MC 446         case 'info':
447             $messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_raidresync_txt") . ' ' .
9021d7 448                 "<a href='#' data-load-content='monitor/show_data.php?type=raid_state'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 449             break;
MC 450         case 'critical':
451             $messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_raidfault_txt") . ' ' .
9021d7 452                 "<a href='#' data-load-content='monitor/show_data.php?type=raid_state'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 453             break;
MC 454         case 'error':
455             $messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_raiderror_txt") . ' ' .
9021d7 456                 "<a href='#' data-load-content='monitor/show_data.php?type=raid_state'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 457             break;
MC 458         case 'no_state':
c9d97b 459             /*
36d307 460                  *  mdadm is not installed or the RAID is not supported...
c9d97b 461             */
7fe908 462             break;
MC 463         default:
464             $messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_raidunknown_txt") . ' ' .
9021d7 465                 "<a href='#' data-load-content='monitor/show_data.php?type=raid_state'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 466             break;
c9d97b 467         }
V 468     }
469
e4efe7 470     /*
V 471      * ignore, until we find a better solution
472      */
7fe908 473     // if ($type == 'openvz_beancounter') {
MC 474     //  switch ($record['state']) {
475     //   case 'ok':
476     //    $messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_beancounterok_txt") . ' ' .
9021d7 477     //      "<a href='#' data-load-content='monitor/show_data.php?type=openvz_beancounter'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 478     //    break;
MC 479     //   case 'info':
480     //    $messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_beancounterinfo_txt") . ' ' .
9021d7 481     //      "<a href='#' data-load-content='monitor/show_data.php?type=openvz_beancounter'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 482     //    break;
MC 483     //   case 'warning':
484     //    $messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_beancounterwarning_txt") . ' ' .
9021d7 485     //      "<a href='#' data-load-content='monitor/show_data.php?type=openvz_beancounter'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 486     //    break;
MC 487     //   case 'critical':
488     //    $messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_beancountercritical_txt") . ' ' .
9021d7 489     //      "<a href='#' data-load-content='monitor/show_data.php?type=openvz_beancounter'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 490     //    break;
MC 491     //   case 'error':
492     //    $messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_beancountererror_txt") . ' ' .
9021d7 493     //      "<a href='#' data-load-content='monitor/show_data.php?type=openvz_beancounter'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 494     //    break;
MC 495     //   default:
496     //    break;
497     //  }
498     // }
36d307 499
V 500
c9d97b 501     if ($type == 'mailq') {
V 502         switch ($record['state']) {
7fe908 503         case 'ok':
MC 504             $messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_mailqok_txt") . ' ' .
9021d7 505                 "<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 506             break;
MC 507         case 'info':
508             $messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_mailqheavy_txt") . ' ' .
9021d7 509                 "<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 510             break;
MC 511         case 'warning':
512             $messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_mailqhigh_txt") . ' ' .
9021d7 513                 "<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 514             break;
MC 515         case 'critical':
516             $messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_mailqhigher_txt") . ' ' .
9021d7 517                 "<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 518             break;
MC 519         case 'error':
520             $messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_mailqhighest_txt") . ' ' .
9021d7 521                 "<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 522             break;
MC 523         default:
524             $messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_mailqunknown_txt") . ' ' .
9021d7 525                 "<a href='#' data-load-content='monitor/show_data.php?type=mailq'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 526             break;
c9d97b 527         }
V 528     }
671a41 529
c9d97b 530     if ($type == 'sys_log') {
V 531         switch ($record['state']) {
7fe908 532         case 'ok':
MC 533             $messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_syslogok_txt") . ' ' .
9021d7 534                 "<a href='#' data-load-content='monitor/log_list.php'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 535             break;
MC 536         case 'warning':
537             $messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_syslogwarning_txt") . ' ' .
9021d7 538                 "<a href='#' data-load-content='monitor/log_list.php'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 539             break;
MC 540         case 'error':
541             $messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_syslogerror_txt") . ' ' .
9021d7 542                 "<a href='#' data-load-content='monitor/log_list.php'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 543             break;
MC 544         default:
545             $messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_syslogunknown_txt") . ' ' .
9021d7 546                 "<a href='#' data-load-content='monitor/log_list.php'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 547             break;
c9d97b 548         }
V 549     }
671a41 550
c9d97b 551     if ($type == 'log_clamav') {
V 552         /* this type has no state */
553     }
671a41 554
c9d97b 555     if ($type == 'log_freshclam') {
V 556         switch ($record['state']) {
7fe908 557         case 'ok':
MC 558             $messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_fclamok_txt") . ' ' .
9021d7 559                 "<a href='#' data-load-content='monitor/show_log.php?log=log_freshclam'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 560             break;
MC 561         case 'info':
562             $messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_fclamoutdated_txt") . ' ' .
9021d7 563                 "<a href='#' data-load-content='monitor/show_log.php?log=log_freshclam'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 564             break;
MC 565         default:
566             $messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_fclamunknown_txt") . ' ' .
9021d7 567                 "<a href='#' data-load-content='monitor/show_log.php?log=log_freshclam'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
7fe908 568             break;
c9d97b 569         }
V 570     }
671a41 571
c9d97b 572     if ($type == 'log_ispconfig') {
V 573         /* this type has no state */
574     }
575     if ($type == 'log_mail') {
576         /* this type has no state */
577     }
578     if ($type == 'log_mail_err') {
579         /* this type has no state */
580     }
581     if ($type == 'log_mail_warn') {
582         /* this type has no state */
583     }
584     if ($type == 'log_messages') {
585         /* this type has no state */
586     }
587     if ($type == 'rkhunter') {
588         /* this type has no state */
589     }
7fe908 590
MC 591     return array('serverState' => $serverState, 'messages' => $messages);
8793b3 592 }
V 593
c9d97b 594 /*
8793b3 595   * Set the state to the given level (or higher, but not lesser).
V 596   * * If the actual state is critical and you call the method with ok,
597   *   then the state is critical.
598   *
599   * * If the actual state is critical and you call the method with error,
600   *   then the state is error.
c9d97b 601 */
V 602 function _setState($oldState, $newState) {
603     /*
716255 604     * Calculate the weight of the old state
c9d97b 605     */
V 606     switch ($oldState) {
7fe908 607     case 'no_state': $oldInt = 0;
MC 608         break;
609     case 'ok': $oldInt = 1;
610         break;
611     case 'unknown': $oldInt = 2;
612         break;
613     case 'info': $oldInt = 3;
614         break;
615     case 'warning': $oldInt = 4;
616         break;
617     case 'critical': $oldInt = 5;
618         break;
619     case 'error': $oldInt = 6;
620         break;
c9d97b 621     }
V 622     /*
8793b3 623          * Calculate the weight of the new state
c9d97b 624     */
V 625     switch ($newState) {
7fe908 626     case 'no_state': $newInt = 0 ;
MC 627         break;
628     case 'ok': $newInt = 1 ;
629         break;
630     case 'unknown': $newInt = 2 ;
631         break;
632     case 'info': $newInt = 3 ;
633         break;
634     case 'warning': $newInt = 4 ;
635         break;
636     case 'critical': $newInt = 5 ;
637         break;
638     case 'error': $newInt = 6 ;
639         break;
c9d97b 640     }
8793b3 641
c9d97b 642     /*
716255 643     * Set to the higher level
c9d97b 644     */
V 645     if ($newInt > $oldInt) {
646         return $newState;
647     }
648     else {
649         return $oldState;
650     }
8793b3 651 }
V 652
7e3524 653 ?>