2010-04-27 Miguel de Dios <miguel.dedios@artica.es>

* include/functions_reporting.php: in function
	"get_agents_detailed_event_reporting" fixed param for $id_agents to array
	type, fixed the loop to save events and fixed in the loop to make the table.
	Added the function "get_module_detailed_event_reporting" for events of any
	module. In function "render_report_html_item" remove trace function, added
	the render option "event_report_module" for render list of events of any
	module.

	* include/functions_db.php: added function "get_module_events".
	
	* operation/gis_maps/ajax.php: cleaned source code.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2619 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
mdtrooper 2010-04-27 17:43:32 +00:00
parent f0f981b262
commit 2a6bf96073
4 changed files with 137 additions and 14 deletions

View File

@ -1,3 +1,17 @@
2010-04-27 Miguel de Dios <miguel.dedios@artica.es>
* include/functions_reporting.php: in function
"get_agents_detailed_event_reporting" fixed param for $id_agents to array
type, fixed the loop to save events and fixed in the loop to make the table.
Added the function "get_module_detailed_event_reporting" for events of any
module. In function "render_report_html_item" remove trace function, added
the render option "event_report_module" for render list of events of any
module.
* include/functions_db.php: added function "get_module_events".
* operation/gis_maps/ajax.php: cleaned source code.
2010-04-27 Sergio Martin <sergio.martin@artica.es> 2010-04-27 Sergio Martin <sergio.martin@artica.es>
* include/functions_db.php * include/functions_db.php

View File

@ -885,7 +885,33 @@ function get_agent_events ($id_agent, $period, $date = 0) {
return get_db_all_rows_sql ($sql); return get_db_all_rows_sql ($sql);
} }
/**
* Get all the events happened in an Agent during a period of time.
*
* The returned events will be in the time interval ($date - $period, $date]
*
* @param int $id_agent_module Module id to get events.
* @param int $period Period of time in seconds to get events.
* @param int $date Beginning date to get events.
*
* @return array An array with all the events happened.
*/
function get_module_events ($id_agent_module, $period, $date = 0) {
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
$datelimit = $date - $period;
$sql = sprintf ('SELECT evento, event_type, criticity, count(*) as count_rep, max(timestamp) AS time2
FROM tevento WHERE id_agentmodule = %d AND utimestamp > %d AND utimestamp <= %d
GROUP BY id_agentmodule, evento ORDER BY time2 DESC', $id_agent_module, $datelimit, $date);
return get_db_all_rows_sql ($sql);
}
/** /**
* Get all the monitors defined in an agent. * Get all the monitors defined in an agent.

View File

@ -930,7 +930,7 @@ function get_group_agents_detailed_reporting ($id_group, $period = 0, $date = 0,
* @return A table object (XHTML) * @return A table object (XHTML)
*/ */
function get_agents_detailed_event_reporting ($id_agents, $period = 0, $date = 0, $return = false) { function get_agents_detailed_event_reporting ($id_agents, $period = 0, $date = 0, $return = false) {
$id_agents = safe_int ($id_agents, 1); $id_agents = (array)safe_int ($id_agents, 1);
if (!is_numeric ($date)) { if (!is_numeric ($date)) {
$date = strtotime ($date); $date = strtotime ($date);
@ -953,7 +953,7 @@ function get_agents_detailed_event_reporting ($id_agents, $period = 0, $date = 0
$table->head[4] = __('Timestamp'); $table->head[4] = __('Timestamp');
$events = array (); $events = array ();
if ($events)
foreach ($id_agents as $id_agent) { foreach ($id_agents as $id_agent) {
$event = get_agent_events ($id_agent, (int) $period, (int) $date); $event = get_agent_events ($id_agent, (int) $period, (int) $date);
if (!empty ($event)) { if (!empty ($event)) {
@ -962,7 +962,8 @@ function get_agents_detailed_event_reporting ($id_agents, $period = 0, $date = 0
} }
if ($events) if ($events)
foreach ($events as $event) { foreach ($events as $eventRow) {
foreach ($eventRow as $event) {
$data = array (); $data = array ();
$data[0] = $event['evento']; $data[0] = $event['evento'];
$data[1] = $event['event_type']; $data[1] = $event['event_type'];
@ -971,6 +972,69 @@ function get_agents_detailed_event_reporting ($id_agents, $period = 0, $date = 0
$data[4] = $event['time2']; $data[4] = $event['time2'];
array_push ($table->data, $data); array_push ($table->data, $data);
} }
}
if ($events)
return print_table ($table, $return);
}
/**
* Get a detailed report of summarized events per agent
*
* It construct a table object with all the grouped events happened in an agent
* during a period of time.
*
* @param mixed Module id to get the report from.
* @param int Period of time (in seconds) to get the report.
* @param int Beginning date (unixtime) of the report
* @param bool Flag to return or echo the report table (echo by default).
*
* @return A table object (XHTML)
*/
function get_module_detailed_event_reporting ($id_modules, $period = 0, $date = 0, $return = false) {
$id_modules = (array)safe_int ($id_modules, 1);
if (!is_numeric ($date)) {
$date = strtotime ($date);
}
if (empty ($date)) {
$date = get_system_time ();
}
if (empty ($period)) {
global $config;
$period = $config["sla_period"];
}
$table->width = '99%';
$table->data = array ();
$table->head = array ();
$table->head[0] = __('Event name');
$table->head[1] = __('Event type');
$table->head[2] = __('Criticity');
$table->head[3] = __('Count');
$table->head[4] = __('Timestamp');
$events = array ();
foreach ($id_modules as $id_module) {
$event = get_agent_events ($id_module, (int) $period, (int) $date);
if (!empty ($event)) {
array_push ($events, $event);
}
}
if ($events)
foreach ($events as $eventRow) {
foreach ($eventRow as $event) {
$data = array ();
$data[0] = $event['evento'];
$data[1] = $event['event_type'];
$data[2] = get_priority_name ($event['criticity']);
$data[3] = $event['count_rep'];
$data[4] = $event['time2'];
array_push ($table->data, $data);
}
}
if ($events) if ($events)
return print_table ($table, $return); return print_table ($table, $return);
@ -1182,7 +1246,7 @@ function get_agent_module_info_with_filter ($id_agent,$filter = '') {
function render_report_html_item ($content, $table, $report) { function render_report_html_item ($content, $table, $report) {
global $config; global $config;
$module_name = get_db_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']); debugPrint($module_name); $module_name = get_db_value ('nombre', 'tagente_modulo', 'id_agente_modulo', $content['id_agent_module']);
$agent_name = get_agentmodule_agent_name ($content['id_agent_module']); $agent_name = get_agentmodule_agent_name ($content['id_agent_module']);
switch ($content["type"]) { switch ($content["type"]) {
@ -1642,6 +1706,25 @@ function render_report_html_item ($content, $table, $report) {
$cellContent = print_table($table2, true); $cellContent = print_table($table2, true);
array_push($table->data, array($cellContent)); array_push($table->data, array($cellContent));
break; break;
case 'event_report_module':
$data = array ();
$data[0] = "<h4>" . __('Module detailed event') . "</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[1][0] = 3;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$table->colspan[2][0] = 3;
$data[0] = get_module_detailed_event_reporting($content['id_agent_module'], $content['period'], $report["datetime"]);
array_push ($table->data, $data);
break;
} }
} }