show_sys_state.php 25.5 KB
Newer Older
1
2
<?php
/*
3
Copyright (c) 2007-2010, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com
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
All rights reserved.

Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:

    * Redistributions of source code must retain the above copyright notice,
      this list of conditions and the following disclaimer.
    * Redistributions in binary form must reproduce the above copyright notice,
      this list of conditions and the following disclaimer in the documentation
      and/or other materials provided with the distribution.
    * Neither the name of ISPConfig nor the names of its contributors
      may be used to endorse or promote products derived from this software without
      specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

require_once('../../lib/config.inc.php');
require_once('../../lib/app.inc.php');
require_once('tools.inc.php');

/* Check permissions for module */
$app->auth->check_module_permissions('monitor');

/* Change the Server if needed */
38
39
40
41
if (isset($_GET['server'])) {
	$server = explode('|', $_GET['server'], 2);
	$_SESSION['monitor']['server_id'] = $server[0];
	$_SESSION['monitor']['server_name'] = $server[1];
42
43
44
45
}

/*
 *  Loading the template
46
*/
47
48
49
50
$app->uses('tpl');
$app->tpl->newTemplate("form.tpl.htm");
$app->tpl->setInclude('content_tpl','templates/show_sys_state.htm');

51
52
53
/* Get some translations */
$monTransRefreshsq = $app->lng("monitor_settings_refreshsq_txt");

54
55
/*
 * setting the content
56
57
58
59
60
61
*/
if ($_GET['state'] == 'server') {
	$res = _getServerState($_SESSION['monitor']['server_id'], $_SESSION['monitor']['server_name'], true);
	$output = $res['html_verbose'];
	$title = $app->lng("monitor_general_serverstate_txt");
	$stateType = 'server';
62
}
63
64
65
66
else {
	$output = _getSysState();
	$title = $app->lng("monitor_general_systemstate_txt");
	$stateType = 'system';
67
68
69
}

$app->tpl->setVar("state_data",$output);
70
$app->tpl->setVar("state_type",$stateType);
71
72
$app->tpl->setVar("list_head_txt",$title);
$app->tpl->setVar("list_desc_txt",$description);
73
$app->tpl->setVar("monTransRefreshsq", $monTransRefreshsq);
74

75
76
/*
 Creating the array with the refresh intervals
77
 Attention: the core-module ist triggered every 5 minutes,
78
79
80
81
82
83
84
85
86
87
88
89
90
            so reload every 2 minutes is impossible!
*/
$refresh = (isset($_GET["refresh"]))?intval($_GET["refresh"]):0;

$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"));
$tmp = '';
foreach($refresh_values as $key => $val) {
	if($key == $refresh) {
		$tmp .= "<option value='$key' SELECTED>$val</option>";
	} else {
		$tmp .= "<option value='$key'>$val</option>";
	}
}
91
$app->tpl->setVar("refresh", $tmp);
92

93
94
/*
 * doing the output
95
*/
96
97
98
99
$app->tpl_defaults();
$app->tpl->pparse();


100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
 * Creates HTML representing the state of the system (of all servers)
*/
function _getSysState() {
	global $app;

	/** The data of all Servers as (sorted by name) array */
	$serverData = array();

	/*
     * Get all servers and calculate the state of them
	*/
	$servers = $app->db->queryAllRecords("SELECT server_id, server_name FROM server order by server_name");
	foreach ($servers as $server) {
		$serverData[] = _getServerState($server['server_id'], $server['server_name'], false);
	}
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
	/*
	 * Now we have a array with all servers. Some of them are normal servers, some of them
	 * are OpenVz-Hosts and some are OpenVz-VE's. Next we need to know which of them are
	 * OpenVz-VE's inside a OpenVz-Host (managed by the Monitor). If there is a OpenVZ-VE
	 * inside a OpenVz-Host which is NOT in the Server-Farm and so not handled by the monitor,
	 * we handle it like a "normal" server (in the output of the system-state)
	*/
	foreach ($serverData as $data) {
		/* get all VE's of this server */
		$veInfo = $data['ve_info'];

		/*
		 * if we found some, mark them all as VE's
		*/
		if (is_array($veInfo)) {
			foreach ($veInfo as $info) {
				for ($i = 0; $i < sizeof($serverData); $i++) {
					if ($serverData[$i]['server_name'] == $info['hostname']) {
						$serverData[$i]['is_ve'] = true;
					}
				}
			}
		}
	}
141

142
143
144
145
146
147
148
149
150
151
	/*
	 * Now we have to output all "normal" server or all OpenVZ-Hosts (or all OpenVZ-VE's without
	 * a OpenVZ-Host managed by ISPConfig). The OpenVz-VE's are then included in them...
	*/
	$html = '';

	foreach ($serverData as $data) {
		if (!isset($data['is_ve'])) {
			/*
			 * it is NOT a Ve, so do the output of this server and off all VE's included in them
152
			*/
153
154
155
			$html .= $data['html_server'];
			/* get all VE's of this server */
			$veInfo = $data['ve_info'];
156
157
158
159
160
161
			if(is_array($veInfo)) {
				foreach ($veInfo as $info) {
					for ($i = 0; $i < sizeof($serverData); $i++) {
						if ($serverData[$i]['server_name'] == $info['hostname']) {
							$html = str_replace('##VE_INFO##', $serverData[$i]['html_ve'] . '##VE_INFO##', $html);
						}
162
163
164
165
166
167
168
					}
				}
			}
			$html = str_replace('##VE_INFO##', '', $html);
		}
	}
	return $html;
169
170
}

171
172
173
174
175
176

/**
 * returns the state and html of ONE Server
 * @param integer $serverId the id of the server
 * @param string $serverName the hostname (like server1.yourdomain.com)
 * @return array the state and representing html of the server
177
 */
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
function _getServerState($serverId, $serverName) {
	global $app;

	/*  The State of the server */
	$serverState = 'ok';

	/** The messages */
	$messages = array();

	/** The Result of the function */
	$res = '';

	/*
     * Get all monitoring-data from the server and process then
	*/
	$records = $app->db->queryAllRecords("SELECT DISTINCT type, data FROM monitor_data WHERE server_id = " . $serverId);
	$osData = null;
	$veInfo = null;
196
	$ispcData = null;
197
198
	foreach($records as $record) {
		/* get the state from the db-data */
199
200
201
202
		$tmp = _processDbState($record['type'], $serverId, $serverState, $messages);
		$serverState = $tmp['serverState'];
		$messages = $tmp['messages'];
		
203
		/* if we have the os-info, get it */
204
205
206
		if ($record['type'] == 'os_info') {
			$osData = unserialize($record['data']);
		}
207
208
209
210
		/* if we have the ISPConfig-info, get it */
		if ($record['type'] == 'ispc_info') {
			$ispcData = unserialize($record['data']);
		}
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
		/* if we have the ve-info, get it */
		if ($record['type'] == 'openvz_veinfo') {
			$veInfo = unserialize($record['data']);
		}
	}

	/*
	 * We now have the state of the server. Lets now create the HTML representing this state.
	 * If we actually don't know, which type of verbose we need, let's create all
	*/

	/*
	 * Info of a VE inside a OpenVz-Host
	*/
	$html_ve  = '<div class="systemmonitor-state state-' . $serverState . '-ve">';
	$html_ve .= '<div class="systemmonitor-device device-ve">';
	$html_ve .= '<div class="systemmonitor-content icons32 ico-' . $serverState . '">';
	$html_ve .= $serverName . '<br>';
	if ($osData != null) {
		$html_ve .= $osData['name'] . ' ' . $osData['version'] . '<br>';
	}
232
233
234
	if ($ispcData != null) {
		$html_ve .= $ispcData['name'] . ' ' . $ispcData['version'] . '<br>';
	}
235
236
237
238
239
240
241
242
243
244
	$html_ve .= $app->lng("monitor_serverstate_state_txt") . ': ' . $serverState . '<br>';

	/*
	 * Info of a "normal" Server or a OpenVz-Host
	*/
	$html_server .= '<div class="systemmonitor-state state-' . $serverState . '">';
	$html_server .= '<div class="systemmonitor-device device-server">';
	$html_server .= '<div class="systemmonitor-content icons32 ico-' . $serverState . '">';
	$html_server .= $app->lng("monitor_serverstate_server_txt") . ': ' . $serverName;
	if ($osData != null) {
245
246
247
248
		$html_server .= ' (' . $osData['name'] . ' ' . $osData['version'] . ')<br>';
	}
	else {
		$html_server .= '<br />';
249
	}
250
251
252
	if ($ispcData != null) {
		$html_server .= $ispcData['name'] . ' ' . $ispcData['version'] . '<br>';
	}
253
254
255
	else {
		$html_server .= '<br />';
	}
256
257
258
259
260
261
262
263
264
265
266
267
268

	$html_server .= $app->lng("monitor_serverstate_state_txt") . ': ' . $serverState . ' (';
	$html_server .= sizeof($messages[$app->lng("monitor_serverstate_listunknown_txt")]) . ' ' . $app->lng("monitor_serverstate_unknown_txt") . ', ';
	$html_server .= sizeof($messages[$app->lng("monitor_serverstate_listinfo_txt")]) . ' ' . $app->lng("monitor_serverstate_info_txt") . ', ';
	$html_server .= sizeof($messages[$app->lng("monitor_serverstate_listwarning_txt")]) . ' ' . $app->lng("monitor_serverstate_warning_txt") . ', ';
	$html_server .= sizeof($messages[$app->lng("monitor_serverstate_listcritical_txt")]) . ' ' . $app->lng("monitor_serverstate_critical_txt") . ', ';
	$html_server .= sizeof($messages[$app->lng("monitor_serverstate_listerror_txt")]) . ' ' . $app->lng("monitor_serverstate_error_txt") . '';
	$html_server .= ')<br />';

	/*
	 * Verbose - Info 
	*/
	$html_verbose = $html_server;
269
	foreach($messages as $key => $state) {
270
271
272
		$html_verbose .= $key . ':<br />';
		foreach ($state as $msg) {
			$html_verbose .= $msg . '<br />';
273
		}
274
		$html_verbose .= '<br />';
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
	}

	/*
	 * The normal info also needs a link to the verbose info
	*/
	$html_ve .= "<a href='#' onclick='loadContent(\"monitor/show_sys_state.php?state=server&server=" . $serverId . '|' . $serverName . "\");'>" . $app->lng("monitor_serverstate_moreinfo_txt") . "</a>";
	$html_server .= "<a href='#' onclick='loadContent(\"monitor/show_sys_state.php?state=server&server=" . $serverId . '|' . $serverName . "\");'>" . $app->lng("monitor_serverstate_moreinfo_txt") . "</a>";

	/*
	 * Finish all html's
	*/
	$html_ve      .= '</div></div></div>';
	$html_server  .= '<div>##VE_INFO##</div></div></div></div>';
	$html_verbose .= '</div></div></div>';

	/*
	 * create and return the result
	*/
	$res['state'] = $serverState;
	$res['server_name'] = $serverName;
	$res['html_server'] = $html_server;
	$res['html_ve'] = $html_ve;
	$res['html_verbose'] = $html_verbose;
	$res['ve_info'] = $veInfo;
	return $res;
300
301
302
}

/*
303
* gets the state from the db and process it
304
*/
305
306
function _processDbState($type, $serverId, $serverState, $messages) {
	global $app;
307

308
	/*
309
310
    * Always the NEWEST record of each monitoring is responsible for the
    * state
311
	*/
312
	// get the State from the DB
313
	$record = $app->db->queryOneRecord("SELECT state FROM monitor_data WHERE type = '" . $type . "' and server_id = " . $serverId . " order by created desc");
314
315
316
317
318
319
320
321
322

	// change the new state to the highest state
	/*
	* Monitoring the user_beancounter of a VE is not as easy as i thought, so for now ignore
	* this state (if we have a better solution)
	*/
	if ($type != 'openvz_beancounter') {
		$serverState = _setState($serverState, $record['state']);
	}
323

324
	/*
325
     * The message depands on the type and the state
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
	*/
	if ($type == 'cpu_info') {
		/* this type has no state */
	}
	if ($type == 'disk_usage') {
		switch ($record['state']) {
			case 'ok':
				$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_hdok_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=disk_usage\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'info':
				$messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_hdgoingfull_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=disk_usage\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'warning':
				$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_hdnearlyfull_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=disk_usage\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'critical':
				$messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_hdveryfull_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=disk_usage\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'error':
				$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_hdfull_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=disk_usage\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;

			default:
				$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_hdunknown_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=disk_usage\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
		}
	}
	if ($type == 'mem_usage') {
		/* this type has no state */
	}
	if ($type == 'server_load') {
		switch ($record['state']) {
			case 'ok':
				$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_loadok_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=server_load\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'info':
				$messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_loadheavy_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=server_load\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'warning':
				$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_loadhigh_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=server_load\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'critical':
				$messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_loadhigher_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=server_load\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'error':
				$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_loadhighest_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=server_load\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			default:
				$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_loadunknown_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=server_load\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
		}
	}
	if ($type == 'services') {
		switch ($record['state']) {
			case 'ok':
				$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_servicesonline_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=services\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";

				break;
			case 'error':
				$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_servicesoffline_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=services\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			default:
				$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_servicesunknown_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=services\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
		}
	}
	if ($type == 'system_update') {
		switch ($record['state']) {
			case 'ok':
				$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_updatesok_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=system_update\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";

				break;
			case 'info':
				$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_updatesneeded_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=system_update\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'no_state':
			/*
vogelor's avatar
vogelor committed
420
                 *  not debian and not Ubuntu, so the state could not be monitored...
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
			*/
				break;
			default:
				$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_updatesunknown_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=system_update\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
		}
	}

	if ($type == 'raid_state') {
		switch ($record['state']) {
			case 'ok':
				$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_raidok_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=raid_state\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'info':
				$messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_raidresync_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=raid_state\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'critical':
				$messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_raidfault_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=raid_state\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'error':
				$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_raiderror_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=raid_state\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'no_state':
			/*
vogelor's avatar
vogelor committed
450
                 *  mdadm is not installed or the RAID is not supported...
451
452
453
454
455
456
457
458
459
			*/
				break;
			default:
				$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_raidunknown_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=raid_state\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
		}
	}

460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
	/*
	 * ignore, until we find a better solution
	 */
//	if ($type == 'openvz_beancounter') {
//		switch ($record['state']) {
//			case 'ok':
//				$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_beancounterok_txt") . ' ' .
//						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=openvz_beancounter\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
//				break;
//			case 'info':
//				$messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_beancounterinfo_txt") . ' ' .
//						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=openvz_beancounter\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
//				break;
//			case 'warning':
//				$messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_beancounterwarning_txt") . ' ' .
//						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=openvz_beancounter\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
//				break;
//			case 'critical':
//				$messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_beancountercritical_txt") . ' ' .
//						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=openvz_beancounter\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
//				break;
//			case 'error':
//				$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_beancountererror_txt") . ' ' .
//						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=openvz_beancounter\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
//				break;
//			default:
//				break;
//		}
//	}
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579


	if ($type == 'mailq') {
		switch ($record['state']) {
			case 'ok':
				$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_mailqok_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'info':
				$messages[$app->lng("monitor_serverstate_listinfo_txt")][] = $app->lng("monitor_serverstate_mailqheavy_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'warning':
				$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_mailqhigh_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'critical':
				$messages[$app->lng("monitor_serverstate_listcritical_txt")][] = $app->lng("monitor_serverstate_mailqhigher_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'error':
				$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_mailqhighest_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			default:
				$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_mailqunknown_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
		}
	}

	if ($type == 'sys_log') {
		switch ($record['state']) {
			case 'ok':
				$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_syslogok_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/log_list.php\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'warning':
				$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_syslogwarning_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/log_list.php\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'error':
				$messages[$app->lng("monitor_serverstate_listerror_txt")][] = $app->lng("monitor_serverstate_syslogerror_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/log_list.php\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			default:
				$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_syslogunknown_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/log_list.php\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
		}
	}

	if ($type == 'log_clamav') {
		/* this type has no state */
	}

	if ($type == 'log_freshclam') {
		switch ($record['state']) {
			case 'ok':
				$messages[$app->lng("monitor_serverstate_listok_txt")][] = $app->lng("monitor_serverstate_fclamok_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_log.php?log=log_freshclam\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			case 'info':
				$messages[$app->lng("monitor_serverstate_listwarning_txt")][] = $app->lng("monitor_serverstate_fclamoutdated_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_log.php?log=log_freshclam\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
			default:
				$messages[$app->lng("monitor_serverstate_listunknown_txt")][] = $app->lng("monitor_serverstate_fclamunknown_txt") . ' ' .
						"<a href='#' onclick='loadContent(\"monitor/show_log.php?log=log_freshclam\");'>[" . $app->lng("monitor_serverstate_more_txt") . "]</a>";
				break;
		}
	}

	if ($type == 'log_ispconfig') {
		/* this type has no state */
	}
	if ($type == 'log_mail') {
		/* this type has no state */
	}
	if ($type == 'log_mail_err') {
		/* this type has no state */
	}
	if ($type == 'log_mail_warn') {
		/* this type has no state */
	}
	if ($type == 'log_messages') {
		/* this type has no state */
	}
	if ($type == 'rkhunter') {
		/* this type has no state */
	}
580
581
	
	return array('serverState' => $serverState,'messages' => $messages);
582
583
}

584
/*
585
586
587
588
589
590
  * Set the state to the given level (or higher, but not lesser).
  * * If the actual state is critical and you call the method with ok,
  *   then the state is critical.
  *
  * * If the actual state is critical and you call the method with error,
  *   then the state is error.
591
592
593
*/
function _setState($oldState, $newState) {
	/*
594
    * Calculate the weight of the old state
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
	*/
	switch ($oldState) {
		case 'no_state': $oldInt = 0;
			break;
		case 'ok': $oldInt = 1;
			break;
		case 'unknown': $oldInt = 2;
			break;
		case 'info': $oldInt = 3;
			break;
		case 'warning': $oldInt = 4;
			break;
		case 'critical': $oldInt = 5;
			break;
		case 'error': $oldInt = 6;
			break;
	}
	/*
613
         * Calculate the weight of the new state
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
	*/
	switch ($newState) {
		case 'no_state': $newInt = 0 ;
			break;
		case 'ok': $newInt = 1 ;
			break;
		case 'unknown': $newInt = 2 ;
			break;
		case 'info': $newInt = 3 ;
			break;
		case 'warning': $newInt = 4 ;
			break;
		case 'critical': $newInt = 5 ;
			break;
		case 'error': $newInt = 6 ;
			break;
	}

	/*
633
    * Set to the higher level
634
635
636
637
638
639
640
	*/
	if ($newInt > $oldInt) {
		return $newState;
	}
	else {
		return $oldState;
	}
641
642
}

643
?>