auth->check_module_permissions('monitor');
/* Change the Server if needed */
if (isset($_GET['server'])) {
$server = explode('|', $_GET['server'], 2);
$_SESSION['monitor']['server_id'] = $server[0];
$_SESSION['monitor']['server_name'] = $server[1];
}
/*
* Loading the template
*/
$app->uses('tpl');
$app->tpl->newTemplate("form.tpl.htm");
$app->tpl->setInclude('content_tpl', 'templates/show_sys_state.htm');
/* Get some translations */
$monTransRefreshsq = $app->lng("monitor_settings_refreshsq_txt");
/*
* setting the content
*/
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';
}
else {
$output = _getSysState();
$title = $app->lng("monitor_general_systemstate_txt");
$stateType = 'system';
}
$app->tpl->setVar("state_data", $output);
$app->tpl->setVar("state_type", $stateType);
$app->tpl->setVar("list_head_txt", $title);
$app->tpl->setVar("list_desc_txt", (isset($description) ? $description : ''));
$app->tpl->setVar("monTransRefreshsq", $monTransRefreshsq);
/*
Creating the array with the refresh intervals
Attention: the core-module ist triggered every 5 minutes,
so reload every 2 minutes is impossible!
*/
$refresh = (isset($_GET["refresh"]))?$app->functions->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 .= "";
} else {
$tmp .= "";
}
}
$app->tpl->setVar("refresh", $tmp);
/*
* doing the output
*/
$app->tpl_defaults();
$app->tpl->pparse();
/*
* 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);
}
/*
* 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;
}
}
}
}
}
/*
* 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
*/
$html .= $data['html_server'];
/* get all VE's of this server */
$veInfo = $data['ve_info'];
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);
}
}
}
}
$html = str_replace('##VE_INFO##', '', $html);
}
}
return $html;
}
/**
* 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
*/
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;
$ispcData = null;
foreach($records as $record) {
/* get the state from the db-data */
$tmp = _processDbState($record['type'], $serverId, $serverState, $messages);
$serverState = $tmp['serverState'];
$messages = $tmp['messages'];
/* if we have the os-info, get it */
if ($record['type'] == 'os_info') {
$osData = unserialize($record['data']);
}
/* if we have the ISPConfig-info, get it */
if ($record['type'] == 'ispc_info') {
$ispcData = unserialize($record['data']);
}
/* 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
*/
$alert_class = 'alert-info';
if($serverState == 'ok') $alert_class = 'alert-success';
if($serverState == 'warning') $alert_class = 'alert-warning';
if($serverState == 'critical' || $serverState == 'error') $alert_class = 'alert-danger';
//$html_ve = '