Commit c9d97bfb authored by vogelor's avatar vogelor
Browse files

The monitor now supports OpenVZ-Hosts and OpenVZ-VE's

parent b31e8a82
......@@ -40,6 +40,7 @@ $wb['Show Clamav-Log'] = 'Clamav-Protokoll anzeigen';
$wb['Show ISPConfig-Log'] = 'ISPConfig-Protokoll anzeigen';
$wb['Show RKHunter-Log'] = 'RKHunter-Protokoll anzeigen';
$wb['Show Jobqueue'] = 'Jobwarteschlange anzeigen';
$wb['Show OpenVz VE BeanCounter'] = 'OpenVz VE Beancounter anzeigen';
$wb['Show ISPC Cron-Log'] = 'ISPC Cron-Protokoll anzeigen';
$wb['no_data_updates_txt'] = 'Derzeit stehen keine Daten über Updates zur Verfügung. Bitte später erneut überprüfen.';
$wb['no_data_raid_txt'] = 'Derzeit stehen keine Daten über RAID zur Verfügung. Bitte später erneut überprüfen.';
......@@ -66,10 +67,10 @@ $wb['monitor_nomdadm_txt'] = 'mdadm ist auf ihrem Server nicht installiert oder
$wb['monitor_norkhunter_txt'] = 'RKHunter ist nicht installiert, deshalb gibt es keine Protokolldatei';
$wb['monitor_serverstate_server_txt'] = 'Server';
$wb['monitor_serverstate_state_txt'] = 'Status';
$wb['monitor_serverstate_unknown_txt'] = 'unbekannt';
$wb['monitor_serverstate_unknown_txt'] = 'Unbekannt';
$wb['monitor_serverstate_info_txt'] = 'Info';
$wb['monitor_serverstate_warning_txt'] = 'Warnung';
$wb['monitor_serverstate_critical_txt'] = 'kritisch';
$wb['monitor_serverstate_critical_txt'] = 'Kritisch';
$wb['monitor_serverstate_error_txt'] = 'Fehler';
$wb['monitor_serverstate_moreinfo_txt'] = 'Mehr Informationen...';
$wb['monitor_serverstate_more_txt'] = 'mehr...';
......@@ -115,6 +116,11 @@ $wb['monitor_serverstate_syslogunknown_txt'] = 'System-Protokoll: ???';
$wb['monitor_serverstate_updatesok_txt'] = 'Ihr System ist aktuell';
$wb['monitor_serverstate_updatesneeded_txt'] = 'Eine oder mehrere Komponenten benötigen ein Update';
$wb['monitor_serverstate_updatesunknown_txt'] = 'System-Update: ???';
$wb['monitor_serverstate_beancounterok_txt'] = 'Die Datei Beancounter beinhaltet keine Fehler';
$wb['monitor_serverstate_beancounterinfo_txt'] = 'Die Datei Beancounter beinhaltet wenige Fehler';
$wb['monitor_serverstate_beancounterwarning_txt'] = 'Die Datei Beancounter beinhaltet einige Fehler';
$wb['monitor_serverstate_beancountercritical_txt'] = 'Die Datei Beancounter beinhaltet viele Fehler';
$wb['monitor_serverstate_beancountererror_txt'] = 'Die Datei Beancounter beinhaltet zu viele Fehler';
$wb['monitor_services_online_txt'] = 'Online';
$wb['monitor_services_offline_txt'] = 'Offline';
$wb['monitor_services_web_txt'] = 'Web-Server:';
......@@ -135,4 +141,6 @@ $wb['monitor_title_raidstate_txt'] = 'RAID-Status';
$wb['monitor_title_rkhunterlog_txt'] = 'RKHunter-Protokoll';
$wb['monitor_updates_nosupport_txt'] = 'Ihre Distribution wird für die Überwachung nicht unterstützt';
$wb['monitor_title_fail2ban_txt'] = 'Fail2Ban Log';
$wb['monitor_title_beancounter_txt'] = 'OpenVz VE BeanCounter';
$wb['monitor_beancounter_nosupport_txt'] = 'Dieser Server ist kein OpenVz-VE und besitzt deshalb auch keine Beancounter Informationen.';
?>
......@@ -115,6 +115,11 @@ $wb['monitor_serverstate_syslogunknown_txt'] = 'System log: ???';
$wb['monitor_serverstate_updatesok_txt'] = 'Your system is up to date.';
$wb['monitor_serverstate_updatesneeded_txt'] = 'One or more components needs an update';
$wb['monitor_serverstate_updatesunknown_txt'] = 'System Update: ???';
$wb['monitor_serverstate_beancounterok_txt'] = 'The beancounter is ok';
$wb['monitor_serverstate_beancounterinfo_txt'] = 'There are vew failure in the beancounter';
$wb['monitor_serverstate_beancounterwarning_txt'] = 'There are some failure in the beancounter';
$wb['monitor_serverstate_beancountercritical_txt'] = 'There are many failure in the beancounter';
$wb['monitor_serverstate_beancountererror_txt'] = 'There are too much failure in the beancounter';
$wb['monitor_services_online_txt'] = 'Online';
$wb['monitor_services_offline_txt'] = 'Offline';
$wb['monitor_services_web_txt'] = 'Web-Server:';
......@@ -134,5 +139,7 @@ $wb['monitor_title_mailq_txt'] = 'Mail Queue';
$wb['monitor_title_raidstate_txt'] = 'RAID Status';
$wb['monitor_title_rkhunterlog_txt'] = 'RKHunter Log';
$wb['monitor_title_fail2ban_txt'] = 'Fail2Ban Log';
$wb['monitor_title_beancounter_txt'] = 'OpenVz VE BeanCounter';
$wb['monitor_updates_nosupport_txt'] = 'Your distribution is not supported for this monitoring';
$wb['monitor_beancounter_nosupport_txt'] = 'This server is not a OpenVz VE and has no beancounter information';
?>
......@@ -104,6 +104,9 @@ $items[] = array( 'title' => "Show Services",
'target' => 'content',
'link' => 'monitor/show_data.php?type=services');
$items[] = array( 'title' => "Show OpenVz VE BeanCounter",
'target' => 'content',
'link' => 'monitor/show_data.php?type=openvz_beancounter');
$module["nav"][] = array( 'title' => 'Server State',
'open' => 1,
......
......@@ -82,6 +82,13 @@ switch($dataType) {
$title = $app->lng("Status of services").' ('. $monTransSrv .' : ' . $_SESSION['monitor']['server_name'] . ')';
$description = '';
break;
case 'openvz_beancounter':
$template = 'templates/show_data.htm';
$output .= showOpenVzBeanCounter();
$time = getDataTime('openvz_beancounter');
$title = $app->lng("monitor_title_beancounter_txt") . ' (' . $monTransSrv . ' : ' . $_SESSION['monitor']['server_name'] . ')';
$description = '';
break;
case 'system_update':
$template = 'templates/show_data.htm';
$output .= showSystemUpdate();
......
This diff is collapsed.
This diff is collapsed.
......@@ -105,9 +105,11 @@
/* Systemmonitor */
.systemmonitor-state {
margin: 10px 0;
margin: 10px 5px;
font-family: Consolas, "Lucida Console", "Courier New", monospace;
font-size: 0.9em;
float: left;
width: 100%;
}
.systemmonitor-state.state-no_state {
border-top: 4px solid #95A19F;
......@@ -122,8 +124,8 @@
background-color: #adffa2;
}
.systemmonitor-state.state-info {
border-top: 4px solid #fdff00;
background-color: #fdffa2;
border-top: 4px solid #183e99;
background-color: #d4e2ff;
}
.systemmonitor-state.state-warning {
border-top: 4px solid #ffa800;
......@@ -137,17 +139,68 @@
border-top: 4px solid #ff0000;
background-color: #ff7f7f;
}
.systemmonitor-state.state-no_state-ve {
float: left;
width: 213px;
border-top: 4px solid #95A19F;
background-color: #f8f8ff;
}
.systemmonitor-state.state-unknown-ve {
float: left;
width: 213px;
border-top: 4px solid #30302e;
background-color: #cecfc5;
}
.systemmonitor-state.state-ok-ve {
float: left;
width: 213px;
border-top: 4px solid #23fb00;
background-color: #adffa2;
}
.systemmonitor-state.state-info-ve {
float: left;
width: 213px;
border-top: 4px solid #183e99;
background-color: #d4e2ff;
}
.systemmonitor-state.state-warning-ve {
float: left;
width: 213px;
border-top: 4px solid #ffa800;
background-color: #ffda93;
}
.systemmonitor-state.state-critical-ve {
float: left;
width: 213px;
border-top: 4px solid #ff0000;
background-color: #ffb9b9;
}
.systemmonitor-state.state-error-ve {
float: left;
width: 213px;
border-top: 4px solid #ff0000;
background-color: #ff7f7f;
}
.systemmonitor-device {
background-position: -6px 4px;
background-repeat: no-repeat;
background-position: 12px 4px;
min-height: 80px;
}
.systemmonitor-device.device-system { background-image: url("../../icons/x64/network.png"); }
.systemmonitor-device.device-server { background-image: url("../../icons/x64/server.png"); }
.systemmonitor-device.device-server {
background-image: url("../../icons/x64/server.png");
}
.systemmonitor-device.device-ve {
background-image: url("../../icons/x64/server.png");
width: 213px;
float: left;
border: 1px dashed #aaaaaa;
border-top: none;
}
.systemmonitor-content.icons32 {
padding:2px 10px 2px 80px;
padding:2px 10px 2px 56px;
background-repeat: no-repeat;
background-position: 12px 4px;
}
......
<?php
/*
Copyright (c) 2010, Till Brehm, projektfarm Gmbh and Oliver Vogel www.muv.com
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.
*/
class openvz_tools {
/**
* Checks, if the server ist a OpenVZ - Host
*/
public function isOpenVzHost() {
/*
* if there is a "/proc/user_beanconters" we have OpenVz "in use"
*/
if (file_exists('/proc/user_beancounters')) {
/*
* if "vzctl" exists, it is a host
*/
system('which vzctl', $retval);
if($retval === 0) {
return true;
}
else {
return false;
}
}
else {
return false;
}
}
/**
* Checks, if the server ist a OpenVZ - VE
*/
public function isOpenVzVe() {
/*
* if there is a "/proc/user_beanconters" we have OpenVz "in use"
*/
if (file_exists('/proc/user_beancounters')) {
/*
* if "vzctl" does not exists, it is a VE
*/
system('which vzctl', $retval);
if($retval === 0) {
return false;
}
else {
return true;
}
}
else {
return false;
}
}
/**
* Return information about all created VE's at this Host
*/
public function getOpenVzVeInfo() {
/*
* If it is not a OpenVz - Host, we have NO VE's
*/
if (!$this->isOpenVzHost()) {
return array();
}
/*
* if it is a OpenVz-Host, we first have to get the VE - List and then parse it to a array
*/
$output = shell_exec('vzlist -a');
/* transfer this output-string into a array */
$outputArray = explode("\n", $output);
/* the first list of the output is not needed */
array_shift($outputArray);
/* now process all items of the rest */
$res = array();
foreach ($outputArray as $item) {
/*
* eliminate all doubled spaces and spaces at the beginning and end
*/
while (strpos($item, ' ') !== false) {
$item = str_replace(' ', ' ', $item);
}
$item = trim($item);
/*
* Now get every token and insert it to the array
*/
if ($item != '') {
$tmp = explode(' ', $item);
$tmpRes['veid'] = $tmp[0];
$tmpRes['nproc'] = $tmp[1];
$tmpRes['status'] = $tmp[2];
$tmpRes['ip_addr'] = $tmp[3];
$tmpRes['hostname'] = $tmp[4];
$res[] = $tmpRes;
}
}
/* ready */
return $res;
}
/**
* Return information about the user_beancounters of this VE
*/
public function getOpenVzVeBeanCounter() {
/*
* If it is not a OpenVz - VE, we need no beancounter, because we use the beancounter
* "inside" of each VE
*/
if (!$this->isOpenVzVe()) {
return "";
}
/*
* if it is a OpenVz-VE, we get the output to a string
*/
$res = file_get_contents('/proc/user_beancounters');
/* ready */
return $res;
}
}
?>
\ No newline at end of file
......@@ -51,26 +51,7 @@ class monitor_core_module {
global $app;
/*
Annonce the actions that where provided by this module, so plugins
can register on them.
*/
/* none at them moment */
//$app->plugins->announceEvents($this->module_name,$this->actions_available);
/*
As we want to get notified of any changes on several database tables,
we register for them.
The following function registers the function "functionname"
to be executed when a record for the table "dbtable" is
processed in the sys_datalog. "classname" is the name of the
class that contains the function functionname.
*/
/* none at them moment */
//$app->modules->registerTableHook('mail_access','mail_module','process');
/*
Do the monitor every n minutes and write the result in the db
* Do the monitor every n minutes and write the result to the db
*/
$min = date('i');
if (($min % $this->interval) == 0) {
......@@ -83,15 +64,7 @@ class monitor_core_module {
The function then raises the events for the plugins.
*/
function process($tablename, $action, $data) {
// global $app;
//
// switch ($tablename) {
// case 'mail_access':
// if($action == 'i') $app->plugins->raiseEvent('mail_access_insert',$data);
// if($action == 'u') $app->plugins->raiseEvent('mail_access_update',$data);
// if($action == 'd') $app->plugins->raiseEvent('mail_access_delete',$data);
// break;
// } // end switch
// not needed
} // end function
//** Get distribution identifier
......@@ -228,6 +201,8 @@ class monitor_core_module {
$this->monitorMemUsage();
$this->monitorCpu();
$this->monitorServices();
$this->monitorOpenVzHost();
$this->monitorOpenVzUserBeancounter();
$this->monitorMailLog();
$this->monitorMailWarnLog();
$this->monitorMailErrLog();
......@@ -296,7 +271,7 @@ class monitor_core_module {
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 10);
$this->_delOldRecords($type, 4);
}
function monitorOsVer() {
......@@ -334,10 +309,10 @@ class monitor_core_module {
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 10);
$this->_delOldRecords($type, 4);
}
function monitorDiskUsage() {
global $app;
global $conf;
......@@ -403,7 +378,7 @@ class monitor_core_module {
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 10);
$this->_delOldRecords($type, 4);
}
......@@ -453,7 +428,7 @@ class monitor_core_module {
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 10);
$this->_delOldRecords($type, 4);
}
......@@ -500,7 +475,7 @@ class monitor_core_module {
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 10);
$this->_delOldRecords($type, 4);
}
......@@ -616,7 +591,116 @@ class monitor_core_module {
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 10);
$this->_delOldRecords($type, 4);
}
function monitorOpenVzHost() {
global $app;
global $conf;
/* the id of the server as int */
$server_id = intval($conf["server_id"]);
/** The type of the data */
$type = 'openvz_veinfo';
/*
Fetch the data into a array
*/
$app->load(openvz_tools);
$openVzTools = new openvz_tools();
$data = $openVzTools->getOpenVzVeInfo();
/* the VE-Info has no state. It is, what it is */
$state = 'no_state';
/*
Insert the data into the database
*/
$sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " .
"VALUES (".
$server_id . ", " .
"'" . $app->dbmaster->quote($type) . "', " .
time() . ", " .
"'" . $app->dbmaster->quote(serialize($data)) . "', " .
"'" . $state . "'" .
")";
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 4);
}
function monitorOpenVzUserBeancounter() {
global $app;
global $conf;
/* the id of the server as int */
$server_id = intval($conf["server_id"]);
/** The type of the data */
$type = 'openvz_beancounter';
/*
Fetch the data into a array
*/
$app->load(openvz_tools);
$openVzTools = new openvz_tools();
$data = $openVzTools->getOpenVzVeBeanCounter();
/* calculate the state of the beancounter */
if ($data == '') {
$state = 'no_state';
}
else {
$state = 'ok';
/* transfer this output-string into a array */
$test = explode("\n", $data);
/* the first list of the output is not needed */
array_shift($test);
/* now process all items of the rest */
foreach ($test as $item) {
/*
* eliminate all doubled spaces and spaces at the beginning and end
*/
while (strpos($item, ' ') !== false) {
$item = str_replace(' ', ' ', $item);
}
$item = trim($item);
/*
* The failcounter is the LAST
*/
if ($item != '') {
$tmp = explode(' ', $item);
$failCounter = $tmp[sizeof($tmp)-1];
if ($failCounter > 0 ) $state = 'info';
if ($failCounter > 50 ) $state = 'warning';
if ($failCounter > 200 ) $state = 'critical';
if ($failCounter > 10000 ) $state = 'error';
}
}
}
/*
Insert the data into the database
*/
$sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " .
"VALUES (".
$server_id . ", " .
"'" . $app->dbmaster->quote($type) . "', " .
time() . ", " .
"'" . $app->dbmaster->quote(serialize($data)) . "', " .
"'" . $state . "'" .
")";
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 4);
}
......@@ -657,8 +741,11 @@ class monitor_core_module {
$state = 'ok';
}
else {
/* There is something to update! */
$state = 'warning';
/*
* There is something to update! this is in most cases not critical, so we can
* do a system-update once a month or so...
*/
$state = 'info';
}
/*
......@@ -738,7 +825,7 @@ class monitor_core_module {
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 0, 2);
$this->_delOldRecords($type, 4);
}
function monitorMailQueue() {
......@@ -784,7 +871,7 @@ class monitor_core_module {
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 10);
$this->_delOldRecords($type, 4);
}
......@@ -799,7 +886,7 @@ class monitor_core_module {
$type = 'raid_state';
/* This monitoring is only available if mdadm is installed */
$location = system('which mdadm', $retval);
system('which mdadm', $retval);
if($retval === 0) {
/*
* Fetch the output
......@@ -878,7 +965,7 @@ class monitor_core_module {
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 10);
$this->_delOldRecords($type, 4);
}
function monitorRkHunter() {
......@@ -899,7 +986,7 @@ class monitor_core_module {
$type = 'rkhunter';
/* This monitoring is only available if rkhunter is installed */
$location = system('which rkhunter', $retval);
system('which rkhunter', $retval);
if($retval === 0) {
/*
* Fetch the output
......@@ -939,7 +1026,7 @@ class monitor_core_module {
$app->dbmaster->query($sql);
/* The new data is written, now we can delete the old one */
$this->_delOldRecords($type, 0, 2);
$this->_delOldRecords($type, 4);