2008-09-08 Evi Vanoost <vanooste@rcbi.rochester.edu>

* reporting/fgraph.php: Further updating of the queries for the
        godmode/db directories. Mainly making sure all data outputs (graph or
        text) have the same order for simple overview. Also fixed some minor
        issues like the one Sancho fixed (array_multisort). Made some strings 
        translatable

        * godmode/db/times_incl.php: This file is actually only relied on by
        db_info.php so I removed it and included the contents in db_info

        * godmode/db/db_purge.php: Since we went over the threshhold of 1,5M
        data entries on a P4, the page would timeout from the browser out. So
        I reworked the page to clarify the variables and adhere to style. Put
        the delete query in a transaction (since it might be that either
        timeouts or other errors don't clean the whole database up and then
        you have to do it manually. Code is also prettier now.

        * godmode/db/db_main.php: Made it display the actual numbers instead of
        repeating the string.

        * godmode/db/db_info_data.php: Moved into db_info.php

        * godmode/db/db_info.php: Introduced db_info_data.php as a hidden Div.
        This will allow quicker access without adding another menu. The query
        will come from cache anyway (SQL cache) so it's faster too

        * godmode/db/db_event.php: Removed reference to times_incl.php

        * godmode/db/db_audit.php: Removed reference to times_incl.php

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1089 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
guruevi 2008-09-08 20:32:23 +00:00
parent 663170fb5b
commit d6a4c2bee9
9 changed files with 306 additions and 398 deletions

View File

@ -1,3 +1,34 @@
2008-09-08 Evi Vanoost <vanooste@rcbi.rochester.edu>
* reporting/fgraph.php: Further updating of the queries for the
godmode/db directories. Mainly making sure all data outputs (graph or
text) have the same order for simple overview. Also fixed some minor
issues like the one Sancho fixed (array_multisort). Made some strings
translatable
* godmode/db/times_incl.php: This file is actually only relied on by
db_info.php so I removed it and included the contents in db_info
* godmode/db/db_purge.php: Since we went over the threshhold of 1,5M
data entries on a P4, the page would timeout from the browser out. So
I reworked the page to clarify the variables and adhere to style. Put
the delete query in a transaction (since it might be that either
timeouts or other errors don't clean the whole database up and then
you have to do it manually. Code is also prettier now.
* godmode/db/db_main.php: Made it display the actual numbers instead of
repeating the string.
* godmode/db/db_info_data.php: Moved into db_info.php
* godmode/db/db_info.php: Introduced db_info_data.php as a hidden Div.
This will allow quicker access without adding another menu. The query
will come from cache anyway (SQL cache) so it's faster too
* godmode/db/db_event.php: Removed reference to times_incl.php
* godmode/db/db_audit.php: Removed reference to times_incl.php
2008-09-04 Esteban Sanchez <estebans@artica.es>
* extensions/update_manager/lib/libupdatemanager_client.php: Updated

View File

@ -37,17 +37,10 @@ if (! give_acl ($config['id_user'], 0, "DM")) {
- A more powerful selection (by Agent, by Module, etc).
*/
require("godmode/db/times_incl.php");
$datos_rango3=0;
$datos_rango2=0;
$datos_rango1=0;
# ADQUIRE DATA PASSED AS FORM PARAMETERS
# ======================================
# Purge data using dates
# Purge data using dates
if (isset($_POST["purgedb"])){ # Fixed 2005-1-13, nil
$from_date = get_parameter_post("date_purge");
$query = sprintf("DELETE FROM `tsesion` WHERE `fecha` < '%s';",$from_date);

View File

@ -27,17 +27,9 @@ if (! give_acl ($config['id_user'], 0, "DM")) {
return;
}
require ("godmode/db/times_incl.php");
$datos_rango3 = 0;
$datos_rango2 = 0;
$datos_rango1 = 0;
# ADQUIRE DATA PASSED AS FORM PARAMETERS
# ======================================
# Purge data using dates
# Purge data using dates
if (isset ($_POST["date_purge"])){
$from_date = get_parameter_post ("date_purge");
$query = sprintf ("DELETE FROM `tevento` WHERE `timestamp` < '%s'",$from_date);

View File

@ -41,14 +41,50 @@ if (! give_acl ($config['id_user'], 0, "DM")) {
echo "<h2>".__('Database Maintenance')." &gt; ";
echo __('Database Information')."</h2>";
echo "<table border=0>";
echo "<tr><td>";
echo '<div id="db_info_graph">';
echo '<table border=0>';
echo '<tr><td>';
echo '<h3>'.__('Modules per agent').'</h3>';
echo "<img src='reporting/fgraph.php?tipo=db_agente_modulo&width=600&height=200'><br>";
echo "<tr><td><br>";
echo "<tr><td>";
echo '<img src="reporting/fgraph.php?tipo=db_agente_modulo&width=600&height=200"><br />';
echo '</td></tr><tr><td><br /></tr></td>';
echo '<tr><td>';
echo '<h3>'.__('Packets per agent').'</h3>';
echo "<img src='reporting/fgraph.php?tipo=db_agente_paquetes&width=600&height=200'><br>";
echo "<br><br><a href='index.php?sec=gdbman&sec2=godmode/db/db_info_data'>".__('Press here to get DB Info as text')."</a>";
echo "</table>";
echo '<img src="reporting/fgraph.php?tipo=db_agente_paquetes&width=600&height=200"><br />';
echo '</table>';
echo '<a href="#" onClick="toggleDiv(\'db_info_data\'); toggleDiv(\'db_info_graph\'); return false;">'.__('Press here to get database information as text').'</a></div>';
echo '<div id="db_info_data" style="display:none">';
//Merged from db_info_data.php because the queries are the same, so the cache
//will kick in.
$table->data = array ();
$table->head = array ();
$table->head[0] = __('Agent name');
$table->head[1] = __('Assigned modules');
$table->head[2] = __('Total data');
$sql = "SELECT DISTINCT(id_agente), COUNT(id_agente_datos) AS count FROM tagente_datos GROUP BY id_agente ORDER BY count ASC";
//This query takes 1s on a 1 million entry database. Merging it with tagente
//costs 7 seconds so we rely on the functions to return information on
//id_agente.
$result = get_db_all_rows_sql ($sql);
if ($result === false) {
$result = array();
}
foreach ($result as $row) {
$data = array ();
//First row is a link to the agent
$data[0] = '<strong><a href="index.php?sec=gagente&sec2=operation/agentes/ver_agente&id_agente='.
$row["id_agente"].'">'.dame_nombre_agente ($row["id_agente"]).'</a></strong>';
//Second row is a number of modules for the agent
$data[1] = count (get_modules_in_agent ($row["id_agente"]));
//Then the number of data packets for the agent
$data[2] = $row["count"];
array_unshift ($table->data, $data);
}
print_table ($table);
echo '<a href="#" onClick="toggleDiv(\'db_info_graph\'); toggleDiv(\'db_info_data\'); return false;">'.__('Press here to get database information as a graph').'</a></div>';
?>

View File

@ -1,74 +0,0 @@
<?php
// Pandora FMS - the Flexible Monitoring System
// ============================================
// Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es
// Please see http://pandora.sourceforge.net for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
// Load global vars
require_once ("include/config.php");
check_login ();
if (! give_acl ($config['id_user'], 0, "DM")) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation",
"Trying to access Database Management Info data");
require ("general/noaccess.php");
return;
}
// Todo for a good DB maintenance
/*
- Delete too on datos_string and and datos_inc tables
- A function to "compress" data, and interpolate big chunks of data (1 month - 60000 registers)
onto a small chunk of interpolated data (1 month - 600 registers)
- A more powerful selection (by Agent, by Module, etc).
*/
echo "<h2>".__('Database Maintenance')." &gt; ";
echo __('Database Statistics per Agent')."</h2>";
$table->data = array ();
$table->head = array ();
$table->head[0] = __('Agent name');
$table->head[1] = __('Assigned module');
$table->head[2] = __('Total data');
$sql = "SELECT `id_agente`, `nombre` FROM `tagente`";
$result = get_db_all_rows_sql ($sql);
foreach ($result as $agent) {
$data = array ();
$sql = sprintf("SELECT COUNT(`id_agente_modulo`)
FROM `tagente_modulo` WHERE `id_agente` = '%d'",
$agent["id_agente"]);
$assigned = get_db_sql ($sql);
// for all data_modules belongs to an agent -- simplified, made
// faster
$sql = sprintf ("SELECT COUNT(`id_agente_datos`)
FROM `tagente_datos` WHERE `id_agente` = '%d'",
$agent["id_agente"]);
$total_agente = get_db_sql ($sql);
$data[0] = '<strong><a href="index.php?sec=gagente&sec2=operation/agentes/ver_agente&id_agente='.
$agent["id_agente"].'">'.$agent["nombre"].'</a></strong>';
$data[1] = $assigned;
$data[2] = $total_agente;
array_push ($table->data, $data);
}
print_table ($table);
?>

View File

@ -36,16 +36,18 @@ if (! give_acl ($config['id_user'], 0, "DM")) {
- A more powerful selection (by Agent, by Module, etc).
*/
?>
<h2><?php echo __('Database Maintenance') ?> &gt;
<?php echo __('Current database maintenance setup') ?></h2>
<table width=550 cellspacing=3 cellpadding=3 border=0>
echo '<h2>'.__('Database Maintenance').' &gt; '.__('Current database maintenance setup').'</h2>
<table width="550" cellspacing="3" cellpadding="3" border="0">
<tr><td>
<i><?php echo __('Max. days before compact data'); ?>:</i>&nbsp;<b><?php echo __('Max. days before compact data'); ?></b><br><br>
<i><?php echo __('Max. days before purge'); ?>:</i>&nbsp;<b><?php echo __('Max. days before purge'); ?></b><br><br>
<i>'.__('Max. time before compact data').':</i>&nbsp;<b>'.$config['days_compact'].' '.__('days').'</b><br /><br />
<i>'.__('Max. time before purge').':</i>&nbsp;<b>'.$config['days_purge'].' '.__('days').'</b><br /><br />
</td></tr>
<tr><td>
<div align='justify'>
<?php echo __('Please check your Pandora Server setup and be sure that database maintenance daemon is running. It\'s very important to keep up-to-date database to get the best performance and results in Pandora'); ?>
</div><br>
<div align="justify">
'.__('Please check your Pandora Server setup and be sure that database maintenance daemon is running. It\'s very important to keep up-to-date database to get the best performance and results in Pandora').'
</div><br />
<img src="reporting/fgraph.php?tipo=db_agente_purge&id=-1">
</table>
</td></tr>
</table>';
?>

View File

@ -24,194 +24,190 @@ check_login ();
if (! give_acl ($config['id_user'], 0, "DM")) {
audit_db($config['id_user'], $REMOTE_ADDR, "ACL Violation",
"Trying to access to Database Purge Section");
"Trying to access Database Purge Section");
include ("general/noaccess.php");
return;
exit;
}
//id_agent = -1: None selected; id_agent = 0: All
if (isset ($_POST["agent"])){
$id_agent = (int) get_parameter_post ("agent",-1); //Default to none selected
} else {
$id_agent = -1;
}
if (isset ($_POST["agent"])){
$id_agent = get_parameter_post ("agent");
} else
$id_agent = -1;
echo '<h2>'.__('Database Maintenance').' &gt;'.__('Database purge')."</h2>";
echo "<img src='reporting/fgraph.php?tipo=db_agente_purge&id=$id_agent'>";
echo "<br><br>";
echo '<h3>'.__('Get data from agent').'</h3>';
echo '<h2>'.__('Database Maintenance').' &gt;'.__('Database purge').'</h2>
<img src="reporting/fgraph.php?tipo=db_agente_purge&id='.$id_agent.'" />
<br /><br />
<h3>'.__('Get data from agent').'</h3>';
// All data (now)
$purge_all = date ("Y-m-d H:i:s", time ());
require("godmode/db/times_incl.php");
$time["all"] = time ();
$datos_rango3=0;
$datos_rango2=0;
$datos_rango1=0;
$datos_rango0=0;
$datos_rango00=0;
$datos_rango11=0;
$datos_total=0;
// 1 day ago
$time["1day"] = $time["all"]-86400;
// 3 days ago
$time["3day"] = $time["all"]-(86400*3);
// 1 week ago
$time["1week"] = $time["all"]-(86400*7);
// 2 weeks ago
$time["2week"] = $time["all"]-(86400*14);
// 1 month ago
$time["1month"] = $time["all"]-(86400*30);
// Three months ago
$time["3month"] = $time["all"]-(86400*90);
//Init data
$data["1day"] = 0;
$data["3day"] = 0;
$data["1week"] = 0;
$data["2week"] = 0;
$data["1month"] = 0;
$data["3month"] = 0;
$data["total"] = 0;
# ADQUIRE DATA PASSED AS FORM PARAMETERS
# ======================================
# Purge data using dates
# Purge data using dates
if (isset($_POST["purgedb"])) {
$from_date = get_parameter_post ("date_purge");
if (isset($id_agent)){
if ($id_agent != -1) {
echo __('Purge task launched for agent id ').$id_agent." / ".$from_date;
echo "<h3>".__('Please be patient. This operation can be very long in time (5-10 minutes)')."<br>",__('while deleting data for ').__('Agent')."</h3>";
if ($id_agent == 0) {
$sql="SELECT * FROM tagente_modulo";
} else {
$sql=sprintf("SELECT * FROM tagente_modulo WHERE id_agente = %d",$id_agent);
}
$result=get_db_all_rows_sql($sql);
foreach ($result as $row) {
echo __('Deleting records for module ').dame_nombre_modulo_agentemodulo($row["id_agente_modulo"]);
flush();
//ob_flush();
echo "<br>";
$sql = sprintf("DELETE FROM `tagente_datos` WHERE `id_agente_modulo` = '%d' AND `timestamp` < '%s'",$row["id_agente_modulo"],$from_date);
process_sql ($sql);
$sql = sprintf("DELETE FROM `tagente_datos_inc` WHERE `id_agente_modulo` = '%d' AND `timestamp` < '%s'",$row["id_agente_modulo"],$from_date);
process_sql ($sql);
$sql = sprintf("DELETE FROM `tagente_datos_string` WHERE `id_agente_modulo` = '%d' AND `timestamp` < '%s'",$row["id_agente_modulo"],$from_date);
process_sql ($sql);
}
} else {
echo __('Deleting records for module ').__('All agents');
flush();
//ob_flush();
$query = sprintf("DELETE FROM `tagente_datos` WHERE `timestamp` < '%s'",$from_date);
process_sql ($query);
$query = sprintf("DELETE FROM `tagente_datos_inc` WHERE `timestamp` < '%s'",$from_date);
process_sql ($query);
$query = sprintf("DELETE FROM `tagente_datos_string` WHERE `timestamp` < '%s'",$from_date);
process_sql ($query);
$from_date = get_parameter_post ("date_purge",0); //0: No time selected
if ($id_agent != -1) {
echo __('Purge task launched for agent')." ".dame_nombre_agente ($id_agent)." :: ".__('Data older than')." ".human_time_description ($from_date);
echo "<h3>".__('Please be patient. This operation can take a long time depending on the amount of modules.')."</h3>";
$sql = sprintf ("SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = %d",$id_agent);
$result=get_db_all_rows_sql($sql);
//Made it in a transaction so it gets done all at once.
process_sql ("SET AUTOCOMMIT=0;");
process_sql ("START TRANSACTION;"); //We start a transaction for consistency
$errors = 0;
foreach ($result as $row) {
echo __('Deleting records for module')." ".dame_nombre_modulo_agentemodulo ($row["id_agente_modulo"]);
echo "<br />";
flush (); //Flush here in case there are errors and the script dies, at least we know where we ended
set_time_limit (); //Reset the time limit just in case
$sql = sprintf("DELETE FROM `tagente_datos` WHERE `id_agente_modulo` = '%d' AND `utimestamp` < '%d'",$row["id_agente_modulo"],$from_date);
if (process_sql ($sql) === false)
$errors++;
$sql = sprintf("DELETE FROM `tagente_datos_inc` WHERE `id_agente_modulo` = '%d' AND `utimestamp` < '%d'",$row["id_agente_modulo"],$from_date);
if (process_sql ($sql) === false)
$errors++;
$sql = sprintf("DELETE FROM `tagente_datos_string` WHERE `id_agente_modulo` = '%d' AND `utimestamp` < '%d'",$row["id_agente_modulo"],$from_date);
if (process_sql ($sql) === false)
$errors++;
}
echo "<br><br>";
if ($errors > 0) {
process_sql ("ROLLBACK;"); //If we have errors, rollback
} else {
process_sql ("COMMIT;"); //Otherwise commit
}
process_sql ("SET AUTOCOMMIT=1;"); //Set autocommit back to 1
} else {
//All agents
echo __('Deleting records for all agents');
flush();
//ob_flush();
$query = sprintf("DELETE FROM `tagente_datos` WHERE `utimestamp` < '%d'",$from_date);
process_sql ($query);
$query = sprintf("DELETE FROM `tagente_datos_inc` WHERE `utimestamp` < '%d'",$from_date);
process_sql ($query);
$query = sprintf("DELETE FROM `tagente_datos_string` WHERE `utimestamp` < '%d'",$from_date);
process_sql ($query);
}
echo "<br /><br />";
}
# Select Agent for further operations.
?>
<form action='index.php?sec=gdbman&sec2=godmode/db/db_purge' method='post'>
<table class='databox'>
<tr><td class='datos'>
<select name='agent' class='w130'>
echo '<form action="index.php?sec=gdbman&sec2=godmode/db/db_purge" method="post">
<table class="databox">
<tr><td class="datos">';
<?php
if (isset($_POST["agent"]) and ($id_agent > 0))
echo "<option value='".$_POST["agent"]."'>".dame_nombre_agente($_POST["agent"]);
if (isset($_POST["agent"]) and ($id_agent == 0)){
echo "<option value=0>".__('All agents');
echo "<option value=-1>".__('Choose agent');
$agents[-1] = __('Choose agent');
$agents[0] = __('All agents');
$result = get_agents_in_group (1);
if ($result === false)
$result = array();
foreach ($result as $row) {
$agents[$row["id_agente"]] = $row["nombre"];
}
print_select ($agents, "agent", $id_agent, "", "", "", false, false, false);
print_help_tip (__("Select the agent you want information about"));
echo '</td><td><input class="sub upd" type="submit" name="purgedb_ag" value="'.__('Get data').'">';
print_help_tip (__("Click here to get the data from the agent specified in the select box"));
echo '</td></tr></table><br />';
if ($id_agent > 0) {
$title = __('Information on agent').' '.dame_nombre_agente ($id_agent).' '.__('in the database');
} else {
echo "<option value=-1>".__('Choose agent');
echo "<option value=0>".__('All agents');
$title = __('Information on all agents').' '.__('in the database');
}
$result_t=mysql_query("SELECT * FROM tagente");
while ($row=mysql_fetch_array($result_t)){
echo "<option value='".$row["id_agente"]."'>".$row["nombre"];
echo "<h3>".$title."</h3>";
$query = "";
if ($id_agent > 0) { //If the agent is not All or Not selected
$query = sprintf (" AND id_agente_modulo = ANY(SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = '%d' ",$id_agent);
}
?>
</select>
<?php print_help_tip (__("This button refresh info about database usage among time")); ?>
<td><input class='sub upd' type='submit' name='purgedb_ag' value='<?php echo __('Get data') ?>'>
<?php print_help_tip (__("Use this combo to select agent for operation. You need to select an agent to purge data and to get info about database usage")); ?>
</table><br>
<?php
# End of get parameters block
if (isset($_POST["agent"]) and ($id_agent !=-1)){
echo "<h3>".__('Data from agent ').dame_nombre_agente ($id_agent).__(' in the Database')."</h3>";
$data["1day"] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["1day"], $query));
$data["3day"] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["3day"], $query));
$data["1week"] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["1week"], $query));
$data["2week"] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["2week"], $query));
$data["1month"] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["1month"], $query));
$data["3month"] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["3month"], $query));
$data["total"] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE 1=1 %s", $query));
$sql = "SELECT id_agente_modulo FROM tagente_modulo";
if ($id_agent != 0) {
$sql .= sprintf(" WHERE id_agente = '%d'",$id_agent);
}
$datos_rango00 += get_db_sql (sprintf("SELECT COUNT(*) FROM `tagente_datos` WHERE `id_agente_modulo` = ANY(%s) AND `timestamp` > '%s'",$sql,$d1));
$datos_rango0 += get_db_sql (sprintf("SELECT COUNT(*) FROM `tagente_datos` WHERE `id_agente_modulo` = ANY(%s) AND `timestamp` > '%s'",$sql,$d3));
$datos_rango1 += get_db_sql (sprintf("SELECT COUNT(*) FROM `tagente_datos` WHERE `id_agente_modulo` = ANY(%s) AND `timestamp` > '%s'",$sql,$week));
$datos_rango11 += get_db_sql (sprintf("SELECT COUNT(*) FROM `tagente_datos` WHERE `id_agente_modulo` = ANY(%s) AND `timestamp` > '%s'",$sql,$week2));
$datos_rango2 += get_db_sql (sprintf("SELECT COUNT(*) FROM `tagente_datos` WHERE `id_agente_modulo` = ANY(%s) AND `timestamp` > '%s'",$sql,$month));
$datos_rango3 += get_db_sql (sprintf("SELECT COUNT(*) FROM `tagente_datos` WHERE `id_agente_modulo` = ANY(%s) AND `timestamp` > '%s'",$sql,$month3));
$datos_total += get_db_sql (sprintf("SELECT COUNT(*) FROM `tagente_datos` WHERE `id_agente_modulo` = ANY(%s)",$sql));
if (isset ($table)) {
unset ($table); //since $table is an object, we make sure it's gone first
}
?>
<table width='300' border='0' class='databox' cellspacing='4' cellpadding='4'>
<tr><td class=datos>
<?php echo __('Packets three months old')?>
</td>
<td class=datos>
<?php echo $datos_rango3; ?>
</td>
$table->width = 300;
$table->border = 0;
$table->class = "databox";
$table->cellspacing = 4;
$table->cellpadding = 4;
<tr><td class=datos2>
<?php echo __('Packets one month old')?>
</td>
<td class=datos2>
<?php echo $datos_rango2; ?>
</td>
$table->data[0] = array (__('Packets less than three months old'), $data["3month"]);
$table->data[1] = array (__('Packets less than one month old'), $data["1month"]);
$table->data[2] = array (__('Packets less than two weeks old'), $data["2week"]);
$table->data[3] = array (__('Packets less than one week old'), $data["1week"]);
$table->data[4] = array (__('Packets less than three days old'), $data["3day"]);
$table->data[5] = array (__('Packets less than one day old'), $data["1day"]);
$table->data[6] = array ('<b>'.__('Total number of packets').'</b>', '<b>'.$data["total"].'</b>');
<tr><td class=datos>
<?php echo __('Packets two weeks old')?>
</td>
<td class=datos>
<?php echo $datos_rango11; ?>
</td>
print_table ($table);
<tr><td class=datos2>
<?php echo __('Packets one week old')?>
</td>
<td class=datos2>
<?php echo $datos_rango1; ?>
</td>
<tr><td class=datos>
<?php echo __('Packets three days old')?>
</td>
<td class=datos>
<?php echo $datos_rango0; ?>
</td>
<tr><td class=datos2>
<?php echo __('Packets one day old')?>
</td>
<td class=datos2>
<?php echo $datos_rango00; ?>
</td>
<tr><td class=datos>
<b><?php echo __('Total packets')?></b>
</td>
<td class=datos>
<b><?php echo $datos_total; ?></b>
</td>
</tr>
</table>
<br>
<h3><?php echo __('Purge data') ?></h3>
<table width='300' border='0' class='databox' cellspacing='4' cellpadding='4'>
echo '<br />';
echo '<h3>'.__('Purge data').'</h3>
<table width="300" border="0" class="databox" cellspacing="4" cellpadding="4">
<tr><td>
<select name="date_purge" width="255px">
<option value="<?php echo $month3 ?>"><?php echo __('Purge data over 90 days') ?>
<option value="<?php echo $month ?>"><?php echo __('Purge data over 30 days') ?>
<option value="<?php echo $week2 ?>"><?php echo __('Purge data over 14 days') ?>
<option value="<?php echo $week ?>"><?php echo __('Purge data over 7 days') ?>
<option value="<?php echo $d3 ?>"><?php echo __('Purge data over 3 days') ?>
<option value="<?php echo $d1 ?>"><?php echo __('Purge data over 1 day') ?>
<option value="'.$time["3month"].'">'.__('Purge data over 3 months').'</option>
<option value="'.$time["1month"].'">'.__('Purge data over 1 month').'</option>
<option value="'.$time["2week"].'">'.__('Purge data over 2 weeks').'</option>
<option value="'.$time["1week"].'">'.__('Purge data over 1 week').'</option>
<option value="'.$time["3day"].'">'.__('Purge data over 3 days').'</option>
<option value="'.$time["1day"].'">'.__('Purge data over 1 day').'</option>
<option value="'.$time["all"].'">'.__('All data until now').'</option>
</select>
<td><input class="sub wand" type="submit" name="purgedb" value="<?php echo __('Do it!') ?>" onClick="if (!confirm('<?php echo __('Are you sure?') ?>')) return false;">
</td><td>
<input class="sub wand" type="submit" name="purgedb" value="'.__('Do it!').'" onClick="if (!confirm(\''.__('Are you sure?').'\')) return false;" />
</td></tr>
</table>
</form>
</form>';
?>

View File

@ -1,38 +0,0 @@
<?php
// Pandora FMS - the Flexible Monitoring System
// ============================================
// Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es
// Please see http://pandora.sourceforge.net for full contribution list
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation for version 2.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
$now = time();
// 1 day
$d1 = date("Y-m-d H:00:00", $now-28800);
// today + 1 hour (to purge all possible data)
$all_data = date("Y-m-d H:00:00", $now+3600);
// 3 days ago
$d3 = date("Y-m-d H:00:00", $now-86400);
// 1 week ago
$week = date("Y-m-d H:00:00", $now-604800);
// 2 weeks ago
$week2 = date("Y-m-d H:00:00", $now-1209600);
// 1 month ago
$month = date("Y-m-d H:00:00", $now-2592000);
// Three months ago
$month3 = date("Y-m-d H:00:00", $now-7257600);
unset($now);
?>

View File

@ -22,6 +22,8 @@ require_once ($config["homedir"].'/include/functions.php');
require_once ($config["homedir"].'/include/functions_db.php');
require_once ('Image/Graph.php');
ini_set ('display_errors', 0); //This is to prevent notices from making the thing not graph
global $config;
if (!isset($_SESSION["id_user"])){
@ -54,13 +56,7 @@ function graphic_error () {
*/
function dame_fecha ($mh) {
$mh *= 60;
$m_year = date ("Y", time() - $mh);
$m_month = date ("m", time() - $mh);
$m_day = date ("d", time() - $mh);
$m_hour = date ("H", time() - $mh);
$m_min = date ("i", time() - $mh);
$m = $m_year."-".$m_month."-".$m_day." ".$m_hour.":".$m_min.":00";
return $m;
return date ("Y-m-d H:i:00", time() - $mh);
}
/**
@ -1199,28 +1195,21 @@ function graphic_incident_source ($width=320, $height=200) {
function grafico_db_agentes_modulos($width, $height) {
$data = array();
$legend = array();
$sql1="SELECT * FROM tagente";
$result=mysql_query($sql1);
while ($row=mysql_fetch_array($result)){
$sql1="SELECT COUNT(id_agente_modulo) FROM tagente_modulo WHERE id_agente = ".$row["id_agente"];;
$result2=mysql_query($sql1);
$row2=mysql_fetch_array($result2);
$data[] = $row2[0];
$legend[] = $row["nombre"];
}
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
// or much better, pay me to do a special version for you, highly optimized :-))))
for ($i = 0; $i < sizeof($data); $i++) {
for ($j = $i; $j <sizeof($data); $j++)
if ($data[$j] > $data[$i]) {
$temp = $data[$i];
$temp_label = $legend[$i];
$data[$i] = $data[$j];
$legend[$i] = $legend[$j];
$data[$j] = $temp;
$legend[$j] = $temp_label;
}
$sql = "SELECT DISTINCT(id_agente), COUNT(id_agente_datos) AS count FROM tagente_datos GROUP BY id_agente ORDER BY count ASC";
//This query is not the most efficient on itself. But other functions
//use this query so it will a) be fetched from cache and b) it will
//return the result in the same order as the other graph and data
$result = get_db_all_rows_sql ($sql);
if ($result === false)
$result = array();
foreach ($result as $row) {
$data[] = count (get_modules_in_agent ($row["id_agente"]));
$legend[] = dame_nombre_agente ($row["id_agente"]);
}
generic_bar_graph ($width, $height, $data, $legend);
}
@ -1325,7 +1314,7 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) {
$data = array();
$legend = array();
$sql = sprintf ("SELECT DISTINCT(id_agentmodule) AS id_agentmodule, id_grupo, COUNT(id_agentmodule) AS count FROM tevento WHERE id_agente = %d GROUP BY id_agentmodule",$id_agent);
$sql = sprintf ("SELECT DISTINCT(id_agentmodule) AS id_agentmodule, id_grupo, COUNT(id_agentmodule) AS count FROM tevento WHERE id_agente = %d GROUP BY id_agentmodule ORDER BY count DESC",$id_agent);
$result = get_db_all_rows_sql ($sql);
if ($result === false)
$result = array();
@ -1343,8 +1332,6 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) {
}
}
array_multisort ($legend, $data);
$max_items = 6; //Maximum items on the piegraph
while (count($data) > $max_items) {
//Pops an element off the array until the array is small enough
@ -1437,77 +1424,60 @@ function generic_bar_graph ( $width =380, $height = 200, $data, $legend) {
function grafico_db_agentes_paquetes ($width = 380, $height = 300) {
$data = array();
$legend = array();
$sql1="SELECT distinct (id_agente) FROM tagente_datos";
$result=mysql_query($sql1);
while ($row=mysql_fetch_array($result)){
if (! is_null($row["id_agente"])){
$sql1="SELECT COUNT(id_agente) FROM tagente_datos WHERE id_agente = ".$row["id_agente"];
$result3=mysql_query($sql1);
if ($row3=mysql_fetch_array($result3)){
$agent_name = dame_nombre_agente($row[0]);
if ($agent_name != ""){
$data[]= $row3[0];
$legend[] = str_pad($agent_name,15);
}
}
}
}
// Sort array by bubble method (yes, I study more methods in university, but if you want more speed, please, submit a patch :)
// or much better, pay me to do a special version for you, highly optimized :-))))
for ($i=0;$i < sizeof($data);$i++){
for ($j=$i; $j <sizeof($data); $j++)
if ($data[$j] > $data[$i]){
$temp = $data[$i];
$temp_label = $legend[$i];
$data[$i] = $data[$j];
$legend[$i] = $legend[$j];
$data[$j] = $temp;
$legend[$j] = $temp_label;
}
}
$sql = "SELECT DISTINCT(id_agente), COUNT(id_agente_datos) AS count FROM tagente_datos GROUP BY id_agente ORDER BY count ASC";
$result = get_db_all_rows_sql ($sql);
if ($result === false)
$result = array();
foreach ($result as $row) {
$data[] = $row["count"];
$legend[] = dame_nombre_agente ($row["id_agente"]);
}
generic_bar_graph ($width, $height, $data, $legend);
}
function grafico_db_agentes_purge ($id_agent, $width, $height) {
if ($id_agent == 0)
//If id_agent is -1 or 0 (depending on what passed it), it should be
//All. Positive id is a possible agent
if ($id_agent < 1) {
$id_agent = -1;
// All data (now)
$purge_all=date("Y-m-d H:i:s",time());
$data = array();
$legend = array();
$d90 = time()-(2592000*3);
$d30 = time()-2592000;
$d7 = time()-604800;
$d1 = time()-86400;
$fechas = array($d90, $d30, $d7, $d1);
$fechas_label = array("30-90 days","7-30 days","This week","Today");
// Calc. total packets
$sql1 = "SELECT COUNT(id_agente_datos) FROM tagente_datos";
$result2 = mysql_query ($sql1);
$row2 = mysql_fetch_array ($result2);
$total = $row2[0];
for ($i = 0; $i < sizeof ($fechas); $i++){
// 4 x intervals will be enought, increase if your database is very very fast :)
if ($i == 3) {
if ($id_agent == -1)
$sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp >= ".$fechas[$i];
else
$sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE id_agente = $id_agent AND utimestamp >= ".$fechas[$i];
} else {
if ($id_agent == -1)
$sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp >= ".$fechas[$i]." AND utimestamp < ".$fechas[$i+1];
else
$sql1="SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE id_agente = $id_agent AND utimestamp >= ".$fechas[$i]." AND utimestamp < ".$fechas[$i+1];
}
$result=mysql_query($sql1);
$row=mysql_fetch_array($result);
$data[] = $row[0];
$legend[]=$fechas_label[$i]." ( ".format_for_graph($row[0],0)." )";
$query = "";
} else {
$query = sprintf (" AND id_agente_modulo = ANY(SELECT id_agente_modulo FROM tagente_modulo WHERE id_agente = '%d' ",$id_agent);
}
// All data (now)
$time["all"] = time ();
// 1 day ago
$time["1day"] = $time["all"]-86400;
// 1 week ago
$time["1week"] = $time["all"]-(86400*7);
// 1 month ago
$time["1month"] = $time["all"]-(86400*30);
// Three months ago
$time["3month"] = $time["all"]-(86400*90);
//Init legend
$legend[0] = __("Today");
$legend[1] = "1 ".__("Week");
$legend[2] = "1 ".__("Month");
$legend[3] = "3 ".__("Months");
$legend[4] = __("Older");
$data[0] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["1day"], $query));
$data[1] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["1week"], $query));
$data[2] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["1month"], $query));
$data[3] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE utimestamp > %d %s", $time["3month"], $query));
$data[4] = get_db_sql (sprintf ("SELECT COUNT(id_agente_datos) FROM tagente_datos WHERE 1=1 %s", $query));
$data[4] = $data[4] - $data[3];
generic_pie_graph ($width, $height, $data, $legend);
}