2009-03-04 Evi Vanoost <vanooste@rcbi.rochester.edu>

* include/functions_reporting.php, 
	operation/reporting/reporting_viewer.php: Function renaming, small fixes
	in some code and documentation.
	
	* include/functions_db.php: Better checks on get_agent_events
	
	* operation/reporting/reporting_xml.php: Sancho sent me this solution
	since people apparently use this and run out of memory.

git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@1506 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
guruevi 2009-03-04 15:21:19 +00:00
parent 6dea8586df
commit 42e82b8ae5
5 changed files with 124 additions and 100 deletions

View File

@ -1,3 +1,14 @@
2009-03-04 Evi Vanoost <vanooste@rcbi.rochester.edu>
* include/functions_reporting.php,
operation/reporting/reporting_viewer.php: Function renaming, small fixes
in some code and documentation.
* include/functions_db.php: Better checks on get_agent_events
* operation/reporting/reporting_xml.php: Sancho sent me this solution
since people apparently use this and run out of memory.
2009-03-04 Esteban Sanchez <estebans@artica.es> 2009-03-04 Esteban Sanchez <estebans@artica.es>
* godmode/agentes/configurar_agente.php: Fixed module interval update. * godmode/agentes/configurar_agente.php: Fixed module interval update.

View File

@ -732,13 +732,19 @@ function get_group_events ($id_group, $period, $date) {
* *
* @return array An array with all the events happened. * @return array An array with all the events happened.
*/ */
function get_agent_events ($id_agent, $period, $date) { function get_agent_events ($id_agent, $period, $date = 0) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
$datelimit = $date - $period; $datelimit = $date - $period;
$sql = sprintf ('SELECT evento,event_type,criticity, count(*) as count_rep, max(timestamp) AS time2 $sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, max(timestamp) AS time2
FROM tevento WHERE id_agente = %d AND utimestamp > %d AND utimestamp <=%d FROM tevento WHERE id_agente = %d AND utimestamp > %d AND utimestamp <= %d
GROUP BY id_agentmodule, evento ORDER BY time2 DESC', $id_agent, GROUP BY id_agentmodule, evento ORDER BY time2 DESC', $id_agent, $datelimit, $date);
$datelimit, $date);
return get_db_all_rows_sql ($sql); return get_db_all_rows_sql ($sql);
} }

View File

@ -650,14 +650,14 @@ function get_agent_detailed_reporting ($id_agent, $period = 0, $date = 0, $retur
/** /**
* Get a detailed report of agents in a group. * Get a detailed report of agents in a group.
* *
* @param int Group to get the report * @param mixed Group(s) to get the report
* @param int Period * @param int Period
* @param int Timestamp to start from * @param int Timestamp to start from
* @param bool Flag to return or echo the report (by default). * @param bool Flag to return or echo the report (by default).
* *
* @return string * @return string
*/ */
function get_agents_detailed_reporting ($id_group, $period = 0, $date = 0, $return = false) { function get_group_agents_detailed_reporting ($id_group, $period = 0, $date = 0, $return = false) {
$agents = get_group_agents ($id_group, false, "none"); $agents = get_group_agents ($id_group, false, "none");
$output = ''; $output = '';
@ -678,18 +678,25 @@ function get_agents_detailed_reporting ($id_group, $period = 0, $date = 0, $retu
* It construct a table object with all the grouped events happened in an agent * It construct a table object with all the grouped events happened in an agent
* during a period of time. * during a period of time.
* *
* @param int Agent id to get the report. * @param mixed Agent id(s) to get the report from.
* @param int Period of time to get the report. * @param int Period of time (in seconds) to get the report.
* @param int Beginning date of the report * @param int Beginning date (unixtime) of the report
* @param int Flag to return or echo the report table (echo by default). * @param bool Flag to return or echo the report table (echo by default).
* *
* @return object A table object * @return A table object (XHTML)
*/ */
function get_agents_detailed_event_reporting ($id_agent, $period, $date = 0) { function get_agents_detailed_event_reporting ($id_agents, $period = 0, $date = 0, $return = false) {
$id_agents = safe_int ($id_agents, 1);
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) { if (empty ($date)) {
$date = get_system_time (); $date = get_system_time ();
} elseif (!is_numeric ($date)) { }
$date = strtotime ($date); if (empty ($period)) {
global $config;
$period = $config["sla_period"];
} }
$table->width = '99%'; $table->width = '99%';
@ -701,24 +708,25 @@ function get_agents_detailed_event_reporting ($id_agent, $period, $date = 0) {
$table->head[3] = __('Count'); $table->head[3] = __('Count');
$table->head[4] = __('Timestamp'); $table->head[4] = __('Timestamp');
$events = get_agent_events ($id_agent, $period, $date); $events = array ();
if (empty ($events)) { foreach ($id_agents as $id_agent) {
$events = array (); $event = get_agent_events ($id_agent, (int) $period, (int) $date);
if (!empty ($event)) {
array_push ($events, $event);
}
} }
foreach ($events as $event) { foreach ($events as $event) {
$data = array (); $data = array ();
$data[0] = $event['evento']; $data[0] = $event['evento'];
$data[1] = $event['event_type']; $data[1] = $event['event_type'];
$data[2] = get_priority_name($event['criticity']); $data[2] = get_priority_name ($event['criticity']);
$data[3] = $event['count_rep']; $data[3] = $event['count_rep'];
$data[4] = $event['time2']; $data[4] = $event['time2'];
array_push ($table->data, $data); array_push ($table->data, $data);
} }
$output = print_table ($table, true); return print_table ($table, $return);
return $output;
} }
?> ?>

View File

@ -487,7 +487,7 @@ foreach ($contents as $content) {
$table->colspan[0][0] = 2; $table->colspan[0][0] = 2;
$data = array (); $data = array ();
$table->colspan[1][0] = 3; $table->colspan[1][0] = 3;
$data[0] = get_agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true); $data[0] = get_group_agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true);
array_push ($table->data, $data); array_push ($table->data, $data);
break; break;

View File

@ -2,7 +2,7 @@
// Pandora FMS - the Flexible Monitoring System // Pandora FMS - the Flexible Monitoring System
// ============================================ // ============================================
// Copyright (c) 2008 Artica Soluciones Tecnologicas, http://www.artica.es // Copyright (c) 2008-2009 Artica Soluciones Tecnologicas, http://www.artica.es
// Please see http://pandora.sourceforge.net for full contribution list // Please see http://pandora.sourceforge.net for full contribution list
// This program is free software; you can redistribute it and/or // This program is free software; you can redistribute it and/or
@ -16,23 +16,42 @@
// along with this program; if not, write to the Free Software // along with this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
function xml_array ($array) {
foreach ($array as $name => $value) {
if (is_int ($name)) {
echo "<object id=\"".$name."\">";
$name = "object";
} else {
echo "<".$name.">";
}
if (is_array ($value)) {
xml_array ($value);
} else {
echo $value;
}
echo "</".$name.">";
}
}
// Login check // Login check
if (isset ($_GET["direct"])) { if (isset ($_GET["direct"])) {
/* /*
This is in case somebody wants to access the XML directly without This is in case somebody wants to access the XML directly without
having the possibility to login and handle sessions having the possibility to login and handle sessions
Use this URL: https://yourserver/pandora_console/operation/reporting/reporting_xml.php?id=<reportid>&direct=1 Use this URL: https://yourserver/pandora_console/operation/reporting/reporting_xml.php?id=<reportid>&direct=1
Although it's not recommended, you can put your login and password Although it's not recommended, you can put your login and password
in a GET request (append &nick=<yourlogin>&password=<password>). in a GET request (append &nick=<yourlogin>&password=<password>).
You SHOULD put it in a POST but some programs You SHOULD put it in a POST but some programs
might not be able to handle it without extensive re-programming. might not be able to handle it without extensive re-programming
Either way, you should have a read-only user for getting reports Either way, you should have a read-only user for getting reports
XMLHttpRequest can do it (example): XMLHttpRequest can do it (example):
var reportid = 3; var reportid = 3;
var login = "yourlogin"; var login = "yourlogin";
var password = "yourpassword"; var password = "yourpassword";
@ -55,9 +74,9 @@ if (isset ($_GET["direct"])) {
require_once ("../../include/functions_reporting.php"); require_once ("../../include/functions_reporting.php");
if (!isset ($config["auth"])) { if (!isset ($config["auth"])) {
require_once ("../../include/auth/mysql.php"); require_once ("include/auth/mysql.php");
} else { } else {
require_once ("../../include/auth/".$config["auth"]["scheme"].".php"); require_once ("include/auth/".$config["auth"]["scheme"].".php");
} }
$nick = get_parameter ("nick"); $nick = get_parameter ("nick");
@ -76,14 +95,14 @@ if (isset ($_GET["direct"])) {
} else { } else {
// User not known // User not known
$login_failed = true; $login_failed = true;
require_once ($config['homedir'].'/general/login_page.php'); require_once ('general/login_page.php');
audit_db ($nick, $REMOTE_ADDR, "Logon Failed", "Invalid login: ".$nick); audit_db ($nick, $REMOTE_ADDR, "Logon Failed", "Invalid login: ".$nick);
exit; exit;
} }
} else { } else {
@require_once ("include/config.php"); require_once ("include/config.php");
require_once ("include/functions_reporting.php"); require_once ("include/functions_reporting.php");
if (!isset ($config["auth"])) { if (!isset ($config["auth"])) {
require_once ("include/auth/mysql.php"); require_once ("include/auth/mysql.php");
} else { } else {
@ -97,9 +116,9 @@ $id_report = (int) get_parameter ('id');
if (! $id_report) { if (! $id_report) {
audit_db ($config['id_user'], $REMOTE_ADDR, "HACK Attempt", audit_db ($config['id_user'], $REMOTE_ADDR, "HACK Attempt",
"Trying to access graph viewer without valid ID"); "Trying to access graph viewer without valid ID");
require ("general/noaccess.php"); require ("general/noaccess.php");
return; exit;
} }
$report = get_db_row ('treport', 'id_report', $id_report); $report = get_db_row ('treport', 'id_report', $id_report);
@ -107,17 +126,17 @@ $report = get_db_row ('treport', 'id_report', $id_report);
if (! give_acl ($config['id_user'], $report['id_group'], "AR")) { if (! give_acl ($config['id_user'], $report['id_group'], "AR")) {
audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation","Trying to access graph reader"); audit_db ($config['id_user'], $REMOTE_ADDR, "ACL Violation","Trying to access graph reader");
include ("general/noaccess.php"); include ("general/noaccess.php");
return; exit;
} }
/* Check if the user can see the graph */ /* Check if the user can see the graph */
if ($report['private'] && ($report['id_user'] != $config['id_user'] && ! is_user_admin ($config['id_user']))) { if ($report['private'] && ($report['id_user'] != $config['id_user'] && ! dame_admin ($config['id_user']))) {
return; return;
} }
header ('Content-type: application/xml; charset="utf-8"', true); header ('Content-type: application/xml; charset="utf-8"', true);
echo '<?xml version="1.0" encoding="UTF-8" ?>'; echo '<?xml version="1.0" encoding="UTF-8" ?>'; //' - this is to mislead highlighters giving crap about the PHP closing tag
$date = (string) get_parameter ('date', date ('Y-m-j')); $date = (string) get_parameter ('date', date ('Y-m-j'));
$time = (string) get_parameter ('time', date ('h:iA')); $time = (string) get_parameter ('time', date ('h:iA'));
@ -128,15 +147,14 @@ if ($datetime === false || $datetime == -1) {
echo "<error>Invalid date selected</error>"; //Not translatable because this is an error message and might have to be used on the other end echo "<error>Invalid date selected</error>"; //Not translatable because this is an error message and might have to be used on the other end
exit; exit;
} }
/* Date must not be older than now */
if ($datetime > get_system_time ()) {
echo "<error>Date is larger than current time</error>"; //Not translatable because this is an error message
exit;
}
$group_name = get_group_name ($report['id_group']); $group_name = get_group_name ($report['id_group']);
$contents = get_db_all_rows_field_filter ('treport_content', 'id_report', $id_report, '`order`'); $contents = get_db_all_rows_field_filter ('treport_content', 'id_report', $id_report, '`order`');
$time = get_system_time ();
echo '<report>';
echo '<generated><unix>'.$time.'</unix>';
echo '<rfc2822>'.date ("r",$time).'</rfc2822></generated>';
$xml["id"] = $id_report; $xml["id"] = $id_report;
$xml["name"] = $report['name']; $xml["name"] = $report['name'];
@ -148,51 +166,57 @@ if ($contents === false) {
$contents = array (); $contents = array ();
}; };
$xml["reports"] = array (); xml_array ($xml);
echo '<reports>';
$counter = 0;
foreach ($contents as $content) { foreach ($contents as $content) {
echo '<object id="'.$counter.'">';
$data = array (); $data = array ();
$data["module"] = get_db_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); $data["module"] = get_db_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']);
$data["agent"] = get_agentmodule_agent_name ($content['id_agent_module']); $data["agent"] = get_agentmodule_agent_name ($content['id_agent_module']);
$data["period"] = human_time_description ($content['period']); $data["period"] = human_time_description ($content['period']);
$data["uperiod"] = $content['period']; $data["uperiod"] = $content['period'];
$data["type"] = $content["type"]; $data["type"] = $content["type"];
switch ($content["type"]) { switch ($content["type"]) {
case 1: case 1:
case 'simple_graph': case 'simple_graph':
$data["title"] = __('Simple graph'); $data["title"] = __('Simple graph');
$data["objdata"]["img"] = 'reporting/fgraph.php?tipo=sparse&amp;id='.$content['id_agent_module'].'&amp;height=230&amp;width=720&amp;period='.$content['period'].'&amp;date='.$datetime.'&amp;avg_only=1&amp;pure=1'; $data["objdata"]["img"] = 'reporting/fgraph.php?tipo=sparse&amp;id='.$content['id_agent_module'].'&amp;height=230&amp;width=720&amp;period='.$content['period'].'&amp;date='.$datetime.'&amp;avg_only=1&amp;pure=1';
break; break;
case 2: case 2:
case 'custom_graph': case 'custom_graph':
$graph = get_db_row ("tgraph", "id_graph", $content['id_gs']); $graph = get_db_row ("tgraph", "id_graph", $content['id_gs']);
$data["title"] = __('Custom graph'); $data["title"] = __('Custom graph');
$data["objdata"]["img_name"] = $graph["name"]; $data["objdata"]["img_name"] = $graph["name"];
$result = get_db_all_rows_field_filter ("tgraph_source","id_graph",$content['id_gs']); $result = get_db_all_rows_field_filter ("tgraph_source","id_graph",$content['id_gs']);
$modules = array (); $modules = array ();
$weights = array (); $weights = array ();
if ($result === false)
if ($result === false) {
$result = array(); $result = array();
}
foreach ($result as $content2) { foreach ($result as $content2) {
array_push ($modules, $content2['id_agent_module']); array_push ($modules, $content2['id_agent_module']);
array_push ($weights, $content2["weight"]); array_push ($weights, $content2["weight"]);
} }
$data["objdata"]["img"] = 'reporting/fgraph.php?tipo=combined&amp;id='.implode (',', $modules).'&amp;weight_l='.implode (',', $weights).'&amp;height=230&amp;width=720&amp;period='.$content['period'].'&amp;date='.$datetime.'&amp;stacked='.$graph["stacked"].'&amp;pure=1'; $data["objdata"]["img"] = 'reporting/fgraph.php?tipo=combined&amp;id='.implode (',', $modules).'&amp;weight_l='.implode (',', $weights).'&amp;height=230&amp;width=720&amp;period='.$content['period'].'&amp;date='.$datetime.'&amp;stacked='.$graph["stacked"].'&amp;pure=1';
break; break;
case 3: case 3:
case 'SLA': case 'SLA':
$data["title"] = __('S.L.A.'); $data["title"] = __('S.L.A.');
$slas = get_db_all_rows_field_filter ('treport_content_sla_combined', 'id_report_content', $content['id_rc']); $slas = get_db_all_rows_field_filter ('treport_content_sla_combined','id_report_content', $content['id_rc']);
if ($slas === false) { if ($slas === false) {
$data["objdata"]["error"] = __('There are no SLAs defined'); $data["objdata"]["error"] = __('There are no SLAs defined');
$slas = array (); $slas = array ();
} }
$data["objdata"]["sla"] = array (); $data["objdata"]["sla"] = array ();
$sla_failed = false; $sla_failed = false;
foreach ($slas as $sla) { foreach ($slas as $sla) {
@ -201,7 +225,6 @@ foreach ($contents as $content) {
$sla_data["module"] = get_agentmodule_name ($sla['id_agent_module']); $sla_data["module"] = get_agentmodule_name ($sla['id_agent_module']);
$sla_data["max"] = $sla['sla_max']; $sla_data["max"] = $sla['sla_max'];
$sla_data["min"] = $sla['sla_min']; $sla_data["min"] = $sla['sla_min'];
$sla_value = get_agentmodule_sla ($sla['id_agent_module'], $content['period'], $sla['sla_min'], $sla['sla_max'], $datetime); $sla_value = get_agentmodule_sla ($sla['id_agent_module'], $content['period'], $sla['sla_min'], $sla['sla_max'], $datetime);
if ($sla_value === false) { if ($sla_value === false) {
$sla_data["error"] = __('Unknown'); $sla_data["error"] = __('Unknown');
@ -213,99 +236,75 @@ foreach ($contents as $content) {
} }
array_push ($data["objdata"]["sla"], $sla_data); array_push ($data["objdata"]["sla"], $sla_data);
} }
break;
break;
case 4: case 4:
case 'event_report': case 'event_report':
$data["title"] = __("Event report"); $data["title"] = __("Event report");
$table_report = event_reporting ($report['id_group'], $content['period'], $datetime, true); $table_report = event_reporting ($report['id_group'], $content['period'], $datetime, true);
$data["objdata"] = "<![CDATA["; $data["objdata"] = "<![CDATA[";
$data["objdata"] .= print_table ($table_report, true); $data["objdata"] .= print_table ($table_report, true);
$data["objdata"] .= "]]>"; $data["objdata"] .= "]]>";
break; break;
case 5: case 5:
case 'alert_report': case 'alert_report':
$data["title"] = __('Alert report'); $data["title"] = __('Alert report');
$data["objdata"] = "<![CDATA["; $data["objdata"] = "<![CDATA[";
$data["objdata"] .= alert_reporting ($report['id_group'], $content['period'], $datetime, true); $data["objdata"] .= alert_reporting ($report['id_group'], $content['period'], $datetime, true);
$data["objdata"] .= "]]>"; $data["objdata"] .= "]]>";
break; break;
case 6: case 6:
case 'monitor_report': case 'monitor_report':
$data["title"] = __('Monitor report'); $data["title"] = __('Monitor report');
$monitor_value = format_numeric (get_agentmodule_sla ($content['id_agent_module'], $content['period'], 1, false, $datetime)); $monitor_value = format_numeric (get_agentmodule_sla ($content['id_agent_module'], $content['period'], 1, false, $datetime));
$data["objdata"]["good"] = $monitor_value; $data["objdata"]["good"] = $monitor_value;
$data["objdata"]["bad"] = format_numeric (100 - $monitor_value, 2); $data["objdata"]["bad"] = format_numeric (100 - $monitor_value, 2);
break; break;
case 7: case 7:
case 'avg_value': case 'avg_value':
$data["title"] = __('Avg. Value'); $data["title"] = __('Avg. Value');
$data["objdata"] = format_numeric (get_agentmodule_data_average ($content['id_agent_module'], $content['period'], $datetime)); $data["objdata"] = format_numeric (get_agentmodule_data_average ($content['id_agent_module'], $content['period'], $datetime));
break; break;
case 8: case 8:
case 'max_value': case 'max_value':
$data["title"] = __('Max. Value'); $data["title"] = __('Max. Value');
$data["objdata"] = format_numeric (get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $datetime)); $data["objdata"] = format_numeric (get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $datetime));
break; break;
case 9: case 9:
case 'min_value': case 'min_value':
$data["title"] = __('Min. Value'); $data["title"] = __('Min. Value');
$data["objdata"] = format_numeric (get_agentmodule_data_min ($content['id_agent_module'], $content['period'], $datetime)); $data["objdata"] = format_numeric (get_agentmodule_data_min ($content['id_agent_module'], $content['period'], $datetime));
break; break;
case 10: case 10:
case 'sumatory': case 'sumatory':
$data["title"] = __('Sumatory'); $data["title"] = __('Sumatory');
$data["objdata"] = format_numeric (get_agentmodule_data_sum ($content['id_agent_module'], $content['period'], $datetime)); $data["objdata"] = format_numeric (get_agentmodule_data_sum ($content['id_agent_module'], $content['period'], $datetime));
break; break;
case 11: case 11:
case 'general_group_report': case 'general_group_report':
$data["title"] = __('Group'); $data["title"] = __('Group');
$data["objdata"] = "<![CDATA["; $data["objdata"] = "<![CDATA[";
$data["objdata"] .= print_group_reporting ($report['id_group'], true); $data["objdata"] .= print_group_reporting ($report['id_group'], true);
$data["objdata"] .= "]]>"; $data["objdata"] .= "]]>";
break; break;
case 12: case 12:
case 'monitor_health': case 'monitor_health':
$data["title"] = __('Monitor health'); $data["title"] = __('Monitor health');
$data["objdata"] = "<![CDATA["; $data["objdata"] = "<![CDATA[";
$data["objdata"] .= monitor_health_reporting ($report['id_group'], $content['period'], $datetime, true); $data["objdata"] .= monitor_health_reporting ($report['id_group'], $content['period'], $datetime, true);
$data["objdata"] .= "]]>"; $data["objdata"] .= "]]>";
break; break;
case 13: case 13:
case 'agents_detailed': case 'agents_detailed':
$data["title"] = __('Agents detailed view'); $data["title"] = __('Agents detailed view');
$data["objdata"] = "<![CDATA["; $data["objdata"] = "<![CDATA[";
$data["objdata"] .= get_agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true); $data["objdata"] .= get_group_agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true);
$data["objdata"] .= "]]>"; $data["objdata"] .= "]]>";
break; break;
} }
array_push ($xml["reports"], $data); xml_array ($data);
echo '</object>';
$counter++;
} }
function xml_array ($array) { echo '</reports></report>';
foreach ($array as $name => $value) {
if (is_int ($name)) {
echo "<object id=\"".$name."\">";
$name = "object";
} else {
echo "<".$name.">";
}
if (is_array ($value)) {
xml_array ($value);
} else {
echo $value;
}
echo "</".$name.">";
}
}
$time = get_system_time ();
echo '<report>';
echo '<generated><unix>'.$time.'</unix>';
echo '<rfc2822>'.date ("r",$time).'</rfc2822></generated>';
xml_array ($xml);
echo '</report>';
?> ?>