Adding support to show and purge data from the log4x table

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2515 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
eric_ross_c 2010-03-19 14:03:40 +00:00
parent 4a0121ed6b
commit 594018f2d9
4 changed files with 107 additions and 42 deletions

View File

@ -1,3 +1,10 @@
2010-03-19 Eric Ross <eric.ross.c@gmail.com>
Adding support to show and purge data from the log4x table
* include/fgraph.php
* godmode/db/db_main.php
* godmode/db/db_purge.php
2010-03-18 Eric Ross <eric.ross.c@gmail.com> 2010-03-18 Eric Ross <eric.ross.c@gmail.com>
* operation/agentes/estado_monitores.php: Now the monitors list display the last data * operation/agentes/estado_monitores.php: Now the monitors list display the last data

View File

@ -35,6 +35,7 @@ if (! give_acl ($config['id_user'], 0, "DM")) {
$stat_access = get_db_sql ("SELECT COUNT(*) FROM tagent_access WHERE id_agent != 0"); $stat_access = get_db_sql ("SELECT COUNT(*) FROM tagent_access WHERE id_agent != 0");
$stat_data = get_db_sql ("SELECT COUNT(*) FROM tagente_datos WHERE id_agente_modulo != 0"); $stat_data = get_db_sql ("SELECT COUNT(*) FROM tagente_datos WHERE id_agente_modulo != 0");
$stat_data_log4x = get_db_sql ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE id_agente_modulo != 0");
$stat_data_string = get_db_sql ("SELECT COUNT(*) FROM tagente_datos_string WHERE id_agente_modulo != 0"); $stat_data_string = get_db_sql ("SELECT COUNT(*) FROM tagente_datos_string WHERE id_agente_modulo != 0");
$stat_modules = get_db_sql ("SELECT COUNT(*) FROM tagente_estado WHERE id_agente_modulo != 0"); $stat_modules = get_db_sql ("SELECT COUNT(*) FROM tagente_estado WHERE id_agente_modulo != 0");
$stat_event = get_db_sql (" SELECT COUNT(*) FROM tevento"); $stat_event = get_db_sql (" SELECT COUNT(*) FROM tevento");
@ -99,6 +100,19 @@ else
echo '</b></td></tr>'; echo '</b></td></tr>';
echo '<tr class="rowPair"><td>';
echo __('Total log4x items (tagente_datos_log4x)');
echo '<td><b>';
if ($stat_data > $max_data)
echo "<font color='#ff0000'>$stat_data_log4x</font>";
else
echo $stat_data_log4x;
echo '</b></td></tr>';
echo '<tr class="rowOdd"><td>'; echo '<tr class="rowOdd"><td>';
echo __('Total data string items (tagente_datos_string)'); echo __('Total data string items (tagente_datos_string)');
echo '<td><b>'; echo '<td><b>';

View File

@ -91,28 +91,52 @@ if (isset($_POST["purgedb"])) {
process_sql_begin (); process_sql_begin ();
$errors = 0; $errors = 0;
$affected = 0;
foreach ($result as $row) { foreach ($result as $row) {
echo __('Deleting records for module')." ".get_agentmodule_name ($row["id_agente_modulo"]); echo __('Deleting records for module')." ".get_agentmodule_name ($row["id_agente_modulo"]);
echo "<br />"; echo "<br />";
flush (); //Flush here in case there are errors and the script dies, at least we know where we ended 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 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); $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) $result = process_sql ($sql);
if ($result === false)
$errors++; $errors++;
else
$affected += $result;
if ($errors == 0) {
$sql = sprintf ("DELETE FROM `tagente_datos_inc` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date); $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) $result = process_sql ($sql);
if ($result === false)
$errors++; $errors++;
else
$affected += $result;
}
if ($errors == 0) {
$sql = sprintf ("DELETE FROM `tagente_datos_string` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date); $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) $result = process_sql ($sql);
if ($result === false)
$errors++; $errors++;
else
$affected += $result;
}
if ($errors == 0) {
$sql = sprintf ("DELETE FROM `tagente_datos_log4x` WHERE `id_agente_modulo` = %d AND `utimestamp` < %d",$row["id_agente_modulo"],$from_date);
$result = process_sql ($sql);
if ($result === false)
$errors++;
else
$affected += $result;
}
} }
if ($errors > 0) { if ($errors > 0) {
process_sql_rollback (); process_sql_rollback ();
} else { } else {
process_sql_commit (); process_sql_commit ();
}
echo __('Total records deleted: ') . $affected;
}
} else { } else {
//All agents //All agents
echo __('Deleting records for all agents'); echo __('Deleting records for all agents');
@ -123,6 +147,8 @@ if (isset($_POST["purgedb"])) {
process_sql ($query); process_sql ($query);
$query = sprintf ("DELETE FROM `tagente_datos_string` WHERE `utimestamp` < %d",$from_date); $query = sprintf ("DELETE FROM `tagente_datos_string` WHERE `utimestamp` < %d",$from_date);
process_sql ($query); process_sql ($query);
$query = sprintf ("DELETE FROM `tagente_datos_log4x` WHERE `utimestamp` < %d",$from_date);
process_sql ($query);
} }
echo "<br /><br />"; echo "<br /><br />";
} }
@ -182,24 +208,32 @@ $data["1month"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_stri
$data["3month"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["3month"], $query)); $data["3month"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["3month"], $query));
$data["total"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE 1=1 %s", $query)); $data["total"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE 1=1 %s", $query));
$data["1day"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE utimestamp > %d %s", $time["1day"], $query));
$data["3day"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE utimestamp > %d %s", $time["3day"], $query));
$data["1week"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE utimestamp > %d %s", $time["1week"], $query));
$data["2week"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE utimestamp > %d %s", $time["2week"], $query));
$data["1month"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE utimestamp > %d %s", $time["1month"], $query));
$data["3month"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE utimestamp > %d %s", $time["3month"], $query));
$data["total"] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE 1=1 %s", $query));
$table->width = '50%'; $table->width = '50%';
$table->border = 0; $table->border = 0;
$table->class = "databox"; $table->class = "databox";
$table->data[0][0] = __('Packets less than three months old'); $table->data[0][0] = __('Packets less than three months old');
$table->data[0][1] = $data["3month"]; $table->data[0][1] = format_numeric($data["3month"]);
$table->data[1][0] = __('Packets less than one month old'); $table->data[1][0] = __('Packets less than one month old');
$table->data[1][1] = $data["1month"]; $table->data[1][1] = format_numeric($data["1month"]);
$table->data[2][0] = __('Packets less than two weeks old'); $table->data[2][0] = __('Packets less than two weeks old');
$table->data[2][1] = $data["2week"]; $table->data[2][1] = format_numeric($data["2week"]);
$table->data[3][0] = __('Packets less than one week old'); $table->data[3][0] = __('Packets less than one week old');
$table->data[3][1] = $data["1week"]; $table->data[3][1] = format_numeric($data["1week"]);
$table->data[4][0] = __('Packets less than three days old'); $table->data[4][0] = __('Packets less than three days old');
$table->data[4][1] = $data["3day"]; $table->data[4][1] = format_numeric($data["3day"]);
$table->data[5][0] = __('Packets less than one day old'); $table->data[5][0] = __('Packets less than one day old');
$table->data[5][1] = $data["1day"]; $table->data[5][1] = format_numeric($data["1day"]);
$table->data[6][0] = '<strong>'.__('Total number of packets').'</strong>'; $table->data[6][0] = '<strong>'.__('Total number of packets').'</strong>';
$table->data[6][1] = '<strong>'.$data["total"].'</strong>'; $table->data[6][1] = '<strong>'.format_numeric($data["total"]).'</strong>';
print_table ($table); print_table ($table);

View File

@ -1177,6 +1177,12 @@ function grafico_db_agentes_purge ($id_agent, $width, $height) {
$data["3 ".__("Months")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["3month"], $query), 0, true); $data["3 ".__("Months")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE utimestamp > %d %s", $time["3month"], $query), 0, true);
$data[__("Older")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE 1=1 %s", $query), 0, true); $data[__("Older")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_string WHERE 1=1 %s", $query), 0, true);
$data[__("Today")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE utimestamp > %d %s", $time["1day"], $query), 0, true);
$data["1 ".__("Week")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE utimestamp > %d %s", $time["1week"], $query), 0, true);
$data["1 ".__("Month")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE utimestamp > %d %s", $time["1month"], $query), 0, true);
$data["3 ".__("Months")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE utimestamp > %d %s", $time["3month"], $query), 0, true);
$data[__("Older")] += get_db_sql (sprintf ("SELECT COUNT(*) FROM tagente_datos_log4x WHERE 1=1 %s", $query), 0, true);
$data[__("Older")] = $data[__("Older")] - $data["3 ".__("Months")]; $data[__("Older")] = $data[__("Older")] - $data["3 ".__("Months")];
if (! $graphic_type) { if (! $graphic_type) {
@ -1678,7 +1684,11 @@ function grafico_modulo_log4x ($id_agente_modulo, $periodo, $show_event,
grafico_modulo_log4x_trace("<pre style='text-align:left;'>"); grafico_modulo_log4x_trace("<pre style='text-align:left;'>");
$now = time(); if ($date == "")
$now = time ();
else
$now = $date;
$fechatope = $now - $periodo; // limit date $fechatope = $now - $periodo; // limit date
$nombre_agente = get_agentmodule_agent_name ($id_agente_modulo); $nombre_agente = get_agentmodule_agent_name ($id_agente_modulo);