Skip to content
Snippets Groups Projects
Commit 71625533 authored by vogelor's avatar vogelor
Browse files

The monitor now monitors the mailq and (on debian/ubuntu) the update-status

parent e3170a15
No related branches found
No related tags found
No related merge requests found
...@@ -14,7 +14,7 @@ $items[] = array( 'title' => "Show System State", ...@@ -14,7 +14,7 @@ $items[] = array( 'title' => "Show System State",
'target' => 'content', 'target' => 'content',
'link' => 'monitor/show_sys_state.php?state=system'); 'link' => 'monitor/show_sys_state.php?state=system');
$module["nav"][] = array( 'title' => 'System State', $module["nav"][] = array( 'title' => 'System State (All Servers)',
'open' => 1, 'open' => 1,
'items' => $items); 'items' => $items);
...@@ -51,8 +51,17 @@ $_SESSION['monitor']['server_id'] = $servers[0]['server_id']; ...@@ -51,8 +51,17 @@ $_SESSION['monitor']['server_id'] = $servers[0]['server_id'];
$_SESSION['monitor']['server_name'] = $servers[0]['server_name']; $_SESSION['monitor']['server_name'] = $servers[0]['server_name'];
/* /*
* Logmonitoring module * Clear and set the Navigation-Items
*/ */
unset($items);
$items[] = array( 'title' => "Show CPU info",
'target' => 'content',
'link' => 'monitor/show_data.php?type=cpu_info');
$module["nav"][] = array( 'title' => 'System-Information',
'open' => 1,
'items' => $items);
/* /*
* Clear and set the Navigation-Items * Clear and set the Navigation-Items
...@@ -61,6 +70,14 @@ unset($items); ...@@ -61,6 +70,14 @@ unset($items);
$items[] = array( 'title' => "Show Server State", $items[] = array( 'title' => "Show Server State",
'target' => 'content', 'target' => 'content',
'link' => 'monitor/show_sys_state.php?state=server'); 'link' => 'monitor/show_sys_state.php?state=server');
/*
* The next menu is only available at debian or Ubuntu
*/
if(file_exists('/etc/debian_version')){
$items[] = array( 'title' => "Show Update State",
'target' => 'content',
'link' => 'monitor/show_data.php?type=system_update');
}
$items[] = array( 'title' => "Show Server Load", $items[] = array( 'title' => "Show Server Load",
'target' => 'content', 'target' => 'content',
...@@ -78,6 +95,9 @@ $items[] = array( 'title' => "Show Services", ...@@ -78,6 +95,9 @@ $items[] = array( 'title' => "Show Services",
'target' => 'content', 'target' => 'content',
'link' => 'monitor/show_data.php?type=services'); 'link' => 'monitor/show_data.php?type=services');
$items[] = array( 'title' => "Show Mailq",
'target' => 'content',
'link' => 'monitor/show_data.php?type=mailq');
$module["nav"][] = array( 'title' => 'Monitoring', $module["nav"][] = array( 'title' => 'Monitoring',
'open' => 1, 'open' => 1,
...@@ -88,23 +108,6 @@ $module["nav"][] = array( 'title' => 'Monitoring', ...@@ -88,23 +108,6 @@ $module["nav"][] = array( 'title' => 'Monitoring',
*/ */
unset($items); unset($items);
$items[] = array( 'title' => "Show CPU info",
'target' => 'content',
'link' => 'monitor/show_data.php?type=cpu_info');
$module["nav"][] = array( 'title' => 'System-Information',
'open' => 1,
'items' => $items);
/*
* Logmonitoring module
*/
/*
* Clear and set the Navigation-Items
*/
unset($items);
$items[] = array( 'title' => "Show Mail-Log", $items[] = array( 'title' => "Show Mail-Log",
'target' => 'content', 'target' => 'content',
'link' => 'monitor/show_log.php?log=log_mail'); 'link' => 'monitor/show_log.php?log=log_mail');
......
...@@ -72,6 +72,18 @@ switch($dataType) { ...@@ -72,6 +72,18 @@ switch($dataType) {
$title = $app->lng("Status of services").' (Server: ' . $_SESSION['monitor']['server_name'] . ')'; $title = $app->lng("Status of services").' (Server: ' . $_SESSION['monitor']['server_name'] . ')';
$description = ''; $description = '';
break; break;
case 'system_update':
$template = 'templates/show_data.htm';
$output .= showSystemUpdate();
$title = "Update State" . ' (Server: ' . $_SESSION['monitor']['server_name'] . ')';
$description = '';
break;
case 'mailq':
$template = 'templates/show_data.htm';
$output .= showMailq();
$title = "Mailq" . ' (Server: ' . $_SESSION['monitor']['server_name'] . ')';
$description = '';
break;
default: default:
$template = ''; $template = '';
break; break;
......
...@@ -142,7 +142,7 @@ function _getServerState($serverId, $serverName, $showAll) ...@@ -142,7 +142,7 @@ function _getServerState($serverId, $serverName, $showAll)
/* /*
* There is no need, to show the "ok" - messages * There is no need, to show the "ok" - messages
*/ */
if ($key != 'ok') // if ($key != 'ok')
{ {
$res .= $key . ':<br />'; $res .= $key . ':<br />';
foreach ($state as $msg) foreach ($state as $msg)
...@@ -278,6 +278,52 @@ function _processDbState($type, $serverId, &$serverState, &$messages) ...@@ -278,6 +278,52 @@ function _processDbState($type, $serverId, &$serverState, &$messages)
break; break;
} }
} }
if ($type == 'system_update'){
switch ($record['state']) {
case 'ok':
$messages['ok'][] = 'Your System is up to date. ' .
"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=system_update\");'>[more...]</a>";
break;
case 'warning':
$messages['warning'][] = 'One or more Components needs a update ' .
"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=system_update\");'>[more...]</a>";
break;
default:
$messages['unknown'][] = 'System-Updatese:??? ' .
"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=system_update\");'>[more...]</a>";
break;
}
}
if ($type == 'mailq'){
switch ($record['state']) {
case 'ok':
$messages['ok'][] = 'Your Mailq load is ok ' .
"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[more...]</a>";
break;
case 'info':
$messages['info'][] = 'Your Mailq in under heavy load ' .
"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[more...]</a>";
break;
case 'warning':
$messages['warning'][] = 'Your Mailq in under high load ' .
"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[more...]</a>";
break;
case 'critical':
$messages['critical'][] = 'Your Mailq in under higher load ' .
"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[more...]</a>";
break;
case 'error':
$messages['error'][] = 'Your Mailq in under highest load ' .
"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[more...]</a>";
break;
default:
$messages['unknown'][] = 'Mailq: ??? ' .
"<a href='#' onclick='loadContent(\"monitor/show_data.php?type=mailq\");'>[more...]</a>";
break;
}
}
if ($type == 'log_clamav'){ if ($type == 'log_clamav'){
/* this type has no state */ /* this type has no state */
} }
...@@ -311,9 +357,9 @@ function _processDbState($type, $serverId, &$serverState, &$messages) ...@@ -311,9 +357,9 @@ function _processDbState($type, $serverId, &$serverState, &$messages)
*/ */
function _setState($oldState, $newState) function _setState($oldState, $newState)
{ {
/* /*
* Calculate the weight of the old state * Calculate the weight of the old state
*/ */
switch ($oldState) { switch ($oldState) {
case 'no_state': $oldInt = 0; case 'no_state': $oldInt = 0;
break; break;
...@@ -350,9 +396,9 @@ function _setState($oldState, $newState) ...@@ -350,9 +396,9 @@ function _setState($oldState, $newState)
break; break;
} }
/* /*
* Set to the higher level * Set to the higher level
*/ */
if ($newInt > $oldInt){ if ($newInt > $oldInt){
return $newState; return $newState;
} }
......
...@@ -11,7 +11,7 @@ function showServerLoad(){ ...@@ -11,7 +11,7 @@ function showServerLoad(){
/* /*
Format the data Format the data
*/ */
$html .= $html =
'<table id="system_load"> '<table id="system_load">
<tr> <tr>
<td>' . $app->lng("Server online since").':</td> <td>' . $app->lng("Server online since").':</td>
...@@ -53,7 +53,7 @@ function showDiskUsage () { ...@@ -53,7 +53,7 @@ function showDiskUsage () {
/* /*
Format the data Format the data
*/ */
$html .= '<table id="system_disk">'; $html = '<table id="system_disk">';
foreach($data as $line) { foreach($data as $line) {
$html .= '<tr>'; $html .= '<tr>';
foreach ($line as $item) { foreach ($line as $item) {
...@@ -84,7 +84,7 @@ function showMemUsage () ...@@ -84,7 +84,7 @@ function showMemUsage ()
/* /*
Format the data Format the data
*/ */
$html .= '<table id="system_memusage">'; $html = '<table id="system_memusage">';
foreach($data as $key => $value){ foreach($data as $key => $value){
if ($key != '') { if ($key != '') {
...@@ -115,7 +115,7 @@ function showCpuInfo () ...@@ -115,7 +115,7 @@ function showCpuInfo ()
/* /*
Format the data Format the data
*/ */
$html .= '<table id="system_cpu">'; $html = '<table id="system_cpu">';
foreach($data as $key => $value){ foreach($data as $key => $value){
if ($key != '') { if ($key != '') {
$html .= '<tr> $html .= '<tr>
...@@ -145,7 +145,7 @@ function showServices () ...@@ -145,7 +145,7 @@ function showServices ()
/* /*
Format the data Format the data
*/ */
$html .= '<table id="system_services">'; $html = '<table id="system_services">';
if($data['webserver'] != -1) { if($data['webserver'] != -1) {
if($data['webserver'] == 1) { if($data['webserver'] == 1) {
...@@ -239,6 +239,41 @@ function showServices () ...@@ -239,6 +239,41 @@ function showServices ()
} }
return $html;
}
function showSystemUpdate()
{
global $app;
/* fetch the Data from the DB */
$record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'system_update' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
if(isset($record['data'])) {
$data = unserialize($record['data']);
$html = nl2br($data['output']);
} else {
$html = '<p>' . "No Update-Data available" . '</p>';
}
return $html;
}
function showMailq()
{
global $app;
/* fetch the Data from the DB */
$record = $app->db->queryOneRecord("SELECT data, state FROM monitor_data WHERE type = 'mailq' and server_id = " . $_SESSION['monitor']['server_id'] . " order by created desc");
if(isset($record['data'])) {
$data = unserialize($record['data']);
$html = nl2br($data['output']);
} else {
$html = '<p>' . "No Mailq-Data available" . '</p>';
}
return $html; return $html;
} }
?> ?>
...@@ -107,6 +107,8 @@ class monitor_core_module { ...@@ -107,6 +107,8 @@ class monitor_core_module {
$this->monitorFreshClamLog(); $this->monitorFreshClamLog();
$this->monitorClamAvLog(); $this->monitorClamAvLog();
$this->monitorIspConfigLog(); $this->monitorIspConfigLog();
$this->monitorSystemUpdate();
$this->monitorMailQueue();
} }
function monitorServer(){ function monitorServer(){
...@@ -448,6 +450,119 @@ class monitor_core_module { ...@@ -448,6 +450,119 @@ class monitor_core_module {
} }
function monitorSystemUpdate(){
/* This monitoring is only available at debian or Ubuntu */
if(!file_exists('/etc/debian_version')) return;
/*
* This monitoring is expensive, so do it only once a hour!
*/
$min = date('i');
if ($min != 0) return;
/*
* OK - here we go...
*/
global $app;
global $conf;
/* the id of the server as int */
$server_id = intval($conf["server_id"]);
/** The type of the data */
$type = 'system_update';
/* There is only ONE Update-Data, so delete the old one */
$this->_delOldRecords($type, 0);
/*
* first update the "update-database"
*/
shell_exec('apt-get update');
/*
* Then test the upgrade.
* if there is any output, then there is a needed update
*/
$aptData = shell_exec('apt-get -s -qq dist-upgrade');
if ($aptData == '')
{
/* There is nothing to update! */
$state = 'ok';
}
else
{
/* There is something to update! */
$state = 'warning';
}
/*
* Fetch the output
*/
$data['output'] = shell_exec('apt-get -s -q dist-upgrade');
/*
* Insert the data into the database
*/
$sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " .
"VALUES (".
$server_id . ", " .
"'" . $app->db->quote($type) . "', " .
time() . ", " .
"'" . $app->db->quote(serialize($data)) . "', " .
"'" . $state . "'" .
")";
$app->db->query($sql);
}
function monitorMailQueue(){
global $app;
global $conf;
/* the id of the server as int */
$server_id = intval($conf["server_id"]);
/** The type of the data */
$type = 'mailq';
/* There is only ONE Update-Data, so delete the old one */
$this->_delOldRecords($type, 0);
/* Get the data from the mailq */
$data['output'] = shell_exec('mailq');
/*
* The last line has more informations
*/
$tmp = explode("\n", $data['output']);
$more = $tmp[sizeof($tmp) - 1];
$this->_getIntArray($more);
$data['bytes'] = $res[0];
$data['requests'] = $res[1];
/** The state of the mailq. */
$state = 'ok';
if ($data['requests'] > 2000 ) $state = 'info';
if ($data['requests'] > 5000 ) $state = 'warning';
if ($data['requests'] > 8000 ) $state = 'critical';
if ($data['requests'] > 10000 ) $state = 'error';
/*
* Insert the data into the database
*/
$sql = "INSERT INTO monitor_data (server_id, type, created, data, state) " .
"VALUES (".
$server_id . ", " .
"'" . $app->db->quote($type) . "', " .
time() . ", " .
"'" . $app->db->quote(serialize($data)) . "', " .
"'" . $state . "'" .
")";
$app->db->query($sql);
}
function monitorMailLog() function monitorMailLog()
{ {
global $app; global $app;
...@@ -872,6 +987,20 @@ class monitor_core_module { ...@@ -872,6 +987,20 @@ class monitor_core_module {
} }
} }
function _getIntArray($line){
/** The array of float found */
$res = array();
/* First build a array from the line */
$data = explode(' ', $line);
/* then check if any item is a float */
foreach ($data as $item) {
if ($item . '' == (int)$item . ''){
$res[] = $item;
}
}
return $res;
}
} // end class } // end class
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment