2010-04-21 Sancho Lerena <slerena@artica.es>

* include/functions_reporting.php: Added function render_report_html_item()
    to render a given report element in HTML format. Fixed a small problem in
    SUM report type (int truncate invalidate most of SUM reports when not using
    a _inc data type).

    * include/functions.php: Updated all "is_module_xxx" from using ereg 
    (deprecated) to use preg_match.

    * include/functions_db.php: Moved reporting functions 
    get_agentmodule_data_average(); get_agentmodule_data_max(), 
    get_agentmodule_data_min() and  get_agentmodule_data_sum() from here
    to functions_reporting.php.

    * godmode/groups/group_list.php: Removing a group put all agents assigned
    to that group in other available group (choosen in realtime).

    * AUTHORS: Authors file update, was very outdated!.

    * operation/agentes/estado_generalagente.php: Fixed bug #2990430.

    * operation/reporting/reporting_viewer.php: Some changes for better 
    structuration of the HTML reporting viewer. Removed big chunk of code
    and put in function_reporting/render_report_html_item() function.



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@2583 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
slerena 2010-04-21 17:52:08 +00:00
parent ab29f0de25
commit f2ab3ea2de
8 changed files with 673 additions and 599 deletions

View File

@ -5,6 +5,10 @@ Raul Mateos <raulofpandora@gmail.com>
Ramon Novoa <ramon.novoa@artica.es>
Evi Vanoost <vanooste@rcbi.rochester.edu>
Miguel de Dios <miguel.dedios@artica.es>
Junichi Satoh <junichi@rworks.jp>
Sergio Martin <sergio.martin@artica.es>
Pablo de la Concepción <pablo.concepcion@artica.es>
Eric Ross <eric.ross.c@gmail.com>
See full list of contributors on:

View File

@ -1,3 +1,29 @@
2010-04-21 Sancho Lerena <slerena@artica.es>
* include/functions_reporting.php: Added function render_report_html_item()
to render a given report element in HTML format. Fixed a small problem in
SUM report type (int truncate invalidate most of SUM reports when not using
a _inc data type).
* include/functions.php: Updated all "is_module_xxx" from using ereg
(deprecated) to use preg_match.
* include/functions_db.php: Moved reporting functions
get_agentmodule_data_average(); get_agentmodule_data_max(),
get_agentmodule_data_min() and get_agentmodule_data_sum() from here
to functions_reporting.php.
* godmode/groups/group_list.php: Removing a group put all agents assigned
to that group in other available group (choosen in realtime).
* AUTHORS: Authors file update, was very outdated!.
* operation/agentes/estado_generalagente.php: Fixed bug #2990430.
* operation/reporting/reporting_viewer.php: Some changes for better
structuration of the HTML reporting viewer. Removed big chunk of code
and put in function_reporting/render_report_html_item() function.
2010-04-21 Miguel de Dios <miguel.dedios@artica.es>
* include/javascript/pandora.js: small improve, added new parameter into

View File

@ -113,13 +113,17 @@ if ($update_group) {
if ($delete_group) {
$id_group = (int) get_parameter ('id_group');
$sql = sprintf ('UPDATE tagente set id_grupo = 1 WHERE id_grupo = %d', $id_group);
$result = mysql_query ($sql);
// First valid group for destination group in agents affected by this group delete
$valid_group = process_sql ("SELECT id_group FROM tgrupo WHERE id_grupo != $id_group AND id_grupo > 0 LIMIT 1");
$sql = sprintf ('UPDATE tagente set id_grupo = 1 WHERE id_grupo = %d', $valid_group);
$result = process_sql ($sql);
$sql = sprintf ('DELETE FROM tgrupo WHERE id_grupo = %d', $id_group);
$result = mysql_query ($sql);
$result = process_sql ($sql);
$sql = sprintf ('DELETE FROM tgroup_stat WHERE id_group = %d', $id_group);
$result = mysql_query ($sql);
$result = process_sql ($sql);
if (! $result)
echo "<h3 class='error'>".__('There was a problem deleting group')."</h3>";

View File

@ -695,10 +695,7 @@ function get_report_type_data_source ($type) {
* @return bool True if the module is of type "data"
*/
function is_module_data ($module_name) {
$result = ereg ("^(.*_data)$", $module_name);
if ($result === false)
return false;
return true;
return preg_match ('/\_data$/', $module_name);
}
/**
@ -709,10 +706,7 @@ function is_module_data ($module_name) {
* @return bool true if the module is of type "proc"
*/
function is_module_proc ($module_name) {
$result = ereg ('^(.*_proc)$', $module_name);
if ($result === false)
return false;
return true;
return preg_match ('/\_proc$/', $module_name);
}
/**
@ -723,10 +717,7 @@ function is_module_proc ($module_name) {
* @return bool true if the module is of type "inc"
*/
function is_module_inc ($module_name) {
$result = ereg ('^(.*_inc)$', $module_name);
if ($result === false)
return false;
return true;
return preg_match ('/\_inc$/', $module_name);
}
/**
@ -737,10 +728,7 @@ function is_module_inc ($module_name) {
* @return bool true if the module is of type "string"
*/
function is_module_data_string ($module_name) {
$result = ereg ('^(.*string)$', $module_name);
if ($result === false)
return false;
return true;
return preg_match ('/\_string$/', $module_name);
}
/**

View File

@ -2530,196 +2530,6 @@ function get_agentmodule_data ($id_agent_module, $period, $date = 0) {
return $values;
}
/**
* Get the average value of an agent module in a period of time.
*
* @param int Agent module id
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The average module value in the interval.
*/
function get_agentmodule_data_average ($id_agent_module, $period, $date = 0) {
if ($date < 1) {
$date = get_system_time ();
}
$datelimit = $date - $period;
$sql = sprintf ("SELECT * FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d
ORDER BY utimestamp ASC",
$id_agent_module, $datelimit, $date);
$values = get_db_all_rows_sql ($sql, true);
if ($values === false) {
$values = array ();
}
/* Get also the previous data before the selected interval. */
$sum = 0;
$total = 0;
$module_interval = get_module_interval ($id_agent_module);
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false) {
$values = array_merge (array ($previous_data), $values);
}
foreach ($values as $data) {
$interval_total = 1;
$interval_sum = $data['datos'];
if ($previous_data !== false && $data['utimestamp'] - $previous_data['utimestamp'] > $module_interval) {
$interval_total = round (($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval, 0);
$interval_sum *= $interval_total;
}
$total += $interval_total;
$sum += $interval_sum;
$previous_data = $data;
}
if ($total == 0) {
return 0;
}
return $sum / $total;
}
/**
* Get the maximum value of an agent module in a period of time.
*
* @param int Agent module id to get the maximum value.
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The maximum module value in the interval.
*/
function get_agentmodule_data_max ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT MAX(datos) FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d",
$id_agent_module, $datelimit, $date);
$max = (float) get_db_sql ($sql, 0, true);
/* Get also the previous report before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false)
return max ($previous_data['datos'], $max);
return max ((float) $previous_data, $max);
}
/**
* Get the minimum value of an agent module in a period of time.
*
* @param int Agent module id to get the minimum value.
* @param int Period of time to check (in seconds)
* @param int Top date to check the values in Unix time. Default current time.
*
* @return float The minimum module value of the module
*/
function get_agentmodule_data_min ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT MIN(datos) FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d",
$id_agent_module, $datelimit, $date);
$min = (float) get_db_sql ($sql, 0, true);
/* Get also the previous data before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data)
return min ($previous_data['datos'], $min);
return $min;
}
/**
* Get the sum of values of an agent module in a period of time.
*
* @param int Agent module id to get the sumatory.
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The sumatory of the module values in the interval.
*/
function get_agentmodule_data_sum ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = get_system_time ();
$datelimit = $date - $period; // limit date
$id_module_type = get_db_value ('id_tipo_modulo', 'tagente_modulo','id_agente_modulo', $id_agent_module);
$module_name = get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', $id_module_type);
if (is_module_data_string ($module_name)) {
return __('Wrong module type');
}
// Get the whole interval of data
$sql = sprintf ('SELECT utimestamp, datos FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d
ORDER BY utimestamp ASC',
$id_agent_module, $datelimit, $date);
$datas = get_db_all_rows_sql ($sql, true);
/* Get also the previous data before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data) {
/* Add data to the beginning */
array_unshift ($datas, $previous_data);
}
if ($datas === false) {
return 0;
}
$last_data = "";
$total_badtime = 0;
$module_interval = get_module_interval ($id_agent_module);
$timestamp_begin = $datelimit + $module_interval;
$timestamp_end = 0;
$sum = 0;
$data_value = 0;
foreach ($datas as $data) {
$timestamp_end = $data["utimestamp"];
$elapsed = $timestamp_end - $timestamp_begin;
$times = intval ($elapsed / $module_interval);
if (is_module_inc ($module_name)) {
$data_value = $data['datos'] * $module_interval;
} else {
$data_value = $data['datos'];
}
$sum += $times * $data_value;
$timestamp_begin = $data["utimestamp"];
}
/* The last value must be get from tagente_estado, but
it will count only if it's not older than date demanded
*/
$timestamp_end = get_db_value ('utimestamp', 'tagente_estado', 'id_agente_modulo', $id_agent_module);
if ($timestamp_end <= $datelimit) {
$elapsed = $timestamp_end - $timestamp_begin;
$times = intval ($elapsed / $module_interval);
if (is_module_inc ($module_name)) {
$data_value = $data['datos'] * $module_interval;
} else {
$data_value = $data['datos'];
}
$sum += $times * $data_value;
}
return (float) $sum;
}
/**
* Get a translated string
*

View File

@ -26,6 +26,202 @@ require_once ($config["homedir"]."/include/functions.php");
require_once ($config["homedir"]."/include/functions_db.php");
require_once ($config["homedir"]."/include/functions_agents.php");
/**
* Get the average value of an agent module in a period of time.
*
* @param int Agent module id
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The average module value in the interval.
*/
function get_agentmodule_data_average ($id_agent_module, $period, $date = 0) {
if ($date < 1) {
$date = get_system_time ();
}
$datelimit = $date - $period;
$sql = sprintf ("SELECT * FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d
ORDER BY utimestamp ASC",
$id_agent_module, $datelimit, $date);
$values = get_db_all_rows_sql ($sql, true);
if ($values === false) {
$values = array ();
}
/* Get also the previous data before the selected interval. */
$sum = 0;
$total = 0;
$module_interval = get_module_interval ($id_agent_module);
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false) {
$values = array_merge (array ($previous_data), $values);
}
foreach ($values as $data) {
$interval_total = 1;
$interval_sum = $data['datos'];
if ($previous_data !== false && $data['utimestamp'] - $previous_data['utimestamp'] > $module_interval) {
$interval_total = round (($data['utimestamp'] - $previous_data['utimestamp']) / $module_interval, 0);
$interval_sum *= $interval_total;
}
$total += $interval_total;
$sum += $interval_sum;
$previous_data = $data;
}
if ($total == 0) {
return 0;
}
return $sum / $total;
}
/**
* Get the maximum value of an agent module in a period of time.
*
* @param int Agent module id to get the maximum value.
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The maximum module value in the interval.
*/
function get_agentmodule_data_max ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT MAX(datos) FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d",
$id_agent_module, $datelimit, $date);
$max = (float) get_db_sql ($sql, 0, true);
/* Get also the previous report before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data !== false)
return max ($previous_data['datos'], $max);
return max ((float) $previous_data, $max);
}
/**
* Get the minimum value of an agent module in a period of time.
*
* @param int Agent module id to get the minimum value.
* @param int Period of time to check (in seconds)
* @param int Top date to check the values in Unix time. Default current time.
*
* @return float The minimum module value of the module
*/
function get_agentmodule_data_min ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = get_system_time ();
$datelimit = $date - $period;
$sql = sprintf ("SELECT MIN(datos) FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d",
$id_agent_module, $datelimit, $date);
$min = (float) get_db_sql ($sql, 0, true);
/* Get also the previous data before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data)
return min ($previous_data['datos'], $min);
return $min;
}
/**
* Get the sum of values of an agent module in a period of time.
*
* @param int Agent module id to get the sumatory.
* @param int Period of time to check (in seconds)
* @param int Top date to check the values. Default current time.
*
* @return float The sumatory of the module values in the interval.
*/
function get_agentmodule_data_sum ($id_agent_module, $period, $date = 0) {
if (! $date)
$date = get_system_time ();
$datelimit = $date - $period; // limit date
$id_module_type = get_db_value ('id_tipo_modulo', 'tagente_modulo','id_agente_modulo', $id_agent_module);
$module_name = get_db_value ('nombre', 'ttipo_modulo', 'id_tipo', $id_module_type);
if (is_module_data_string ($module_name)) {
return 0;
// Wrong module type, we cannot sum alphanumerical data !
}
// Get the whole interval of data
$sql = sprintf ('SELECT utimestamp, datos FROM tagente_datos
WHERE id_agente_modulo = %d
AND utimestamp > %d AND utimestamp <= %d
ORDER BY utimestamp ASC',
$id_agent_module, $datelimit, $date);
$datas = get_db_all_rows_sql ($sql, true);
/* Get also the previous data before the selected interval. */
$previous_data = get_previous_data ($id_agent_module, $datelimit);
if ($previous_data) {
/* Add data to the beginning */
array_unshift ($datas, $previous_data);
}
if ($datas === false) {
return 0;
}
$last_data = "";
$total_badtime = 0;
$module_interval = get_module_interval ($id_agent_module);
$timestamp_begin = $datelimit + $module_interval;
$timestamp_end = 0;
$sum = 0;
$data_value = 0;
$elapsed = 1;
foreach ($datas as $data) {
$timestamp_end = $data["utimestamp"];
if ($timestamp_begin < $timestamp_end)
$elapsed = $timestamp_end - $timestamp_begin;
$times = $elapsed / $module_interval;
if (is_module_inc ($module_name)) {
$data_value = $data['datos'] * $module_interval;
} else {
$data_value = $data['datos'];
}
$sum += $times * $data_value;
$timestamp_begin = $data["utimestamp"];
}
/* The last value must be get from tagente_estado, but
it will count only if it's not older than date demanded
*/
$timestamp_end = get_db_value ('utimestamp', 'tagente_estado', 'id_agente_modulo', $id_agent_module);
if ($timestamp_end <= $datelimit) {
$elapsed = $timestamp_end - $timestamp_begin;
$times = intval ($elapsed / $module_interval);
if (is_module_inc ($module_name)) {
$data_value = $data['datos'] * $module_interval;
} else {
$data_value = $data['datos'];
}
$sum += $times * $data_value;
}
return (float) $sum;
}
/**
* Get SLA of a module.
*
@ -972,4 +1168,406 @@ function get_agent_module_info_with_filter ($id_agent,$filter = '') {
return $return;
}
/**
* This function is used once, in reporting_viewer.php, the HTML report render
* file. This function proccess each report item and write the render in the
* table record.
*
* @param array $content Record of treport_content table for current item
* @param array $table HTML Table row
* @param array $report Report contents, with some added fields.
*
*/
function render_report_html_item ($content, $table, $report){
global $config;
$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']);
switch ($content["type"]) {
case 1:
case 'simple_graph':
$table->colspan[1][0] = 4;
$data = array ();
$data[0] = '<h4>'.__('Simple graph').'</h4>';
$data[1] = '<h4>'.$agent_name.' - '.$module_name.'</h4>';
$data[2] = '<h4>'.human_time_description ($content['period']).'</h4>';
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[2][0] = 4;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$data[0] = '<img src="include/fgraph.php?tipo=sparse&id='.$content['id_agent_module'].'&height=230&width=750&period='.$content['period'].'&date='.$report["datetime"].'&avg_only=1&pure=1" border="0" alt="">';
array_push ($table->data, $data);
break;
case 2:
case 'custom_graph':
$graph = get_db_row ("tgraph", "id_graph", $content['id_gs']);
$data = array ();
$data[0] = '<h4>'.__('Custom graph').'</h4>';
$data[1] = "<h4>".$graph["name"]."</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</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);
}
$result = get_db_all_rows_field_filter ("tgraph_source", "id_graph", $content['id_gs']);
$modules = array ();
$weights = array ();
if ($result === false)
$result = array();
foreach ($result as $content2) {
array_push ($modules, $content2['id_agent_module']);
array_push ($weights, $content2["weight"]);
}
$graph_width = get_db_sql ("SELECT width FROM tgraph WHERE id_graph = ".$content["id_gs"]);
$graph_height= get_db_sql ("SELECT height FROM tgraph WHERE id_graph = ".$content["id_gs"]);
$table->colspan[2][0] = 3;
$data = array ();
$data[0] = '<img src="include/fgraph.php?tipo=combined&id='.implode (',', $modules).'&weight_l='.implode (',', $weights).'&height=235&width=750&period='.$content['period'].'&date='.$report["datetime"].'&stacked='.$graph["stacked"].'&pure=1" border="1" alt="">';
array_push ($table->data, $data);
break;
case 3:
case 'SLA':
$table->style[1] = 'text-align: right';
$data = array ();
$data[0] = '<h4>'.__('S.L.A.').'</h4>';
$data[1] = '<h4>'.human_time_description ($content['period']).'</h4>';;
$n = 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);
}
$slas = get_db_all_rows_field_filter ('treport_content_sla_combined',
'id_report_content', $content['id_rc']);
if ($slas === false) {
$data = array ();
$table->colspan[2][0] = 3;
$data[0] = __('There are no SLAs defined');
array_push ($table->data, $data);
$slas = array ();
}
$sla_failed = false;
foreach ($slas as $sla) {
$data = array ();
$data[0] = '<strong>'.__('Agent')."</strong> : ";
$data[0] .= get_agentmodule_agent_name ($sla['id_agent_module'])."<br />";
$data[0] .= '<strong>'.__('Module')."</strong> : ";
$data[0] .= get_agentmodule_name ($sla['id_agent_module'])."<br />";
$data[0] .= '<strong>'.__('SLA Max. (value)')."</strong> : ";
$data[0] .= $sla['sla_max']."<br />";
$data[0] .= '<strong>'.__('SLA Min. (value)')."</strong> : ";
$data[0] .= $sla['sla_min']."<br />";
$data[0] .= '<strong>'.__('SLA Limit')."</strong> : ";
$data[0] .= $sla['sla_limit'];
$sla_value = get_agentmodule_sla ($sla['id_agent_module'], $content['period'],
$sla['sla_min'], $sla['sla_max'], $report["datetime"]);
if ($sla_value === false) {
$data[1] = '<span style="font: bold 3em Arial, Sans-serif; color: #0000FF;">';
$data[1] .= __('Unknown');
} else {
if ($sla_value >= $sla['sla_limit'])
$data[1] = '<span style="font: bold 3em Arial, Sans-serif; color: #000000;">';
else {
$sla_failed = true;
$data[1] = '<span style="font: bold 3em Arial, Sans-serif; color: #ff0000;">';
}
$data[1] .= format_numeric ($sla_value). " %";
}
$data[1] .= "</span>";
$n = array_push ($table->data, $data);
}
if (!empty ($slas)) {
$data = array ();
if ($sla_failed == false)
$data[0] = '<span style="font: bold 3em Arial, Sans-serif; color: #000000;">'.__('OK').'</span>';
else
$data[0] = '<span style="font: bold 3em Arial, Sans-serif; color: #ff0000;">'.__('Fail').'</span>';
$n = array_push ($table->data, $data);
$table->colspan[$n - 1][0] = 3;
$table->rowstyle[$n - 1] = 'text-align: right';
}
break;
case 4:
case 'event_report':
$id_agent = get_agent_id ($agent_name);
$data = array ();
$data[0] = "<h4>".__('Event report')."</h4>";
$data[1] = "<h4>".human_time_description ($content['period'])."</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);
}
$table->colspan[2][0] = 3;
$data = array ();
$table_report = event_reporting ($report['id_group'], $content['period'], $report["datetime"], true);
$table_report->class = 'databox';
$table_report->width = '100%';
$data[0] = print_table ($table_report, true);
array_push ($table->data, $data);
break;
case 5:
case 'alert_report':
$data = array ();
$data[0] = "<h4>".__('Alert report')."</h4>";
$data[1] = "<h4>".$report["group_name"]."</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</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] = alert_reporting ($report['id_group'], $content['period'], $report["datetime"], true);
array_push ($table->data, $data);
break;
case 6:
case 'monitor_report':
$data = array ();
$data[0] = "<h4>".__('Monitor report')."</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</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 ();
$monitor_value = format_numeric (get_agentmodule_sla ($content['id_agent_module'], $content['period'], 1, false, $report["datetime"]));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">';
$data[0] .= $monitor_value.' % <img src="images/b_green.png" height="32" width="32" /></p>';
$monitor_value = format_numeric (100 - $monitor_value, 2) ;
$data[1] = '<p style="font: bold 3em Arial, Sans-serif; color: #ff0000;">';
$data[1] .= $monitor_value.' % <img src="images/b_red.png" height="32" width="32" /></p>';
array_push ($table->data, $data);
break;
case 7:
case 'avg_value':
$data = array ();
$data[0] = "<h4>".__('Avg. Value')."</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</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;
$value = format_numeric (get_agentmodule_data_average ($content['id_agent_module'], $content['period'], $report["datetime"]));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">'.$value.'</p>';
array_push ($table->data, $data);
break;
case 8:
case 'max_value':
$data = array ();
$data[0] = "<h4>".__('Max. Value')."</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</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;
$value = format_numeric (get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $report["datetime"]));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">'.$value.'</p>';
array_push ($table->data, $data);
break;
case 9:
case 'min_value':
$data = array ();
$data[0] = "<h4>".__('Min. Value')."</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[0][0] = 2;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$table->colspan[1][0] = 2;
$value = format_numeric (get_agentmodule_data_min ($content['id_agent_module'], $content['period'], $report["datetime"]));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">'.$value.'</p>';
array_push ($table->data, $data);
break;
case 10:
case 'sumatory':
$data = array ();
$data[0] = "<h4>".__('Sumatory')."</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[0][0] = 2;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$table->colspan[1][0] = 2;
$value = format_numeric (get_agentmodule_data_sum ($content['id_agent_module'], $content['period'], $report["datetime"]));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">'.$value.'</p>';
array_push ($table->data, $data);
break;
case 11:
case 'general_group_report':
$data = array ();
$data[0] = "<h4>".__('Group')."</h4>";
$data[1] = "<h4>".$report["group_name"]."</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[0][0] = 2;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$table->colspan[1][0] = 2;
$data[0] = print_group_reporting ($report['id_group'], true);
array_push ($table->data, $data);
break;
case 12:
case 'monitor_health':
$data = array ();
$data[0] = "<h4>".__('Monitor health')."</h4>";
$data[1] = "<h4>".$report["group_name"]."</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[0][0] = 4;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$table->colspan[1][0] = 4;
$data[0] = monitor_health_reporting ($report['id_group'], $content['period'], $report["datetime"], true);
array_push ($table->data, $data);
break;
case 13:
case 'agents_detailed':
$data = array ();
$data[0] = "<h4>".__('Agents detailed view')."</h4>";
$data[1] = "<h4>".$report["group_name"]."</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[0][0] = 2;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$table->colspan[0][0] = 2;
$data = array ();
$table->colspan[1][0] = 3;
$data[0] = get_group_agents_detailed_reporting ($report['id_group'], $content['period'], $report["datetime"], true);
array_push ($table->data, $data);
break;
case 'agent_detailed_event':
$data = array ();
$data[0] = "<h4>".__('Agent detailed event')."</h4>";
$data[1] = "<h4>".get_agent_name($content['id_agent'])."</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_agents_detailed_event_reporting ($content['id_agent'], $content['period'], $report["datetime"]);
array_push ($table->data, $data);
break;
}
}
?>

View File

@ -41,6 +41,10 @@ if (! give_acl ($config["id_user"], $agent["id_grupo"], "AR")) {
require_once ("general/noaccess.php");
return;
}
// Blank space below title, DONT remove this, this
// Breaks the layout when Flash charts are enabled :-o
echo '<div style="height: 10px">&nbsp;</div>';
//Floating div
echo '<div style="float:right; width:320px; padding-top:11px;">';

View File

@ -27,27 +27,44 @@ if (! $id_report) {
return;
}
// Get Report record (to get id_group)
$report = get_db_row ('treport', 'id_report', $id_report);
// Check ACL on the report to see if user has access to the report.
if (! give_acl ($config['id_user'], $report['id_group'], "AR")) {
audit_db ($config['id_user'], $_SERVER['REMOTE_ADDR'], "ACL Violation","Trying to access graph reader");
include ("general/noaccess.php");
exit;
}
// Include with the functions to calculate each kind of report.
require ("include/functions_reporting.php");
/* Check if the user can see the graph */
// Check if the report is a private report.
if ($report['private'] && ($report['id_user'] != $config['id_user'] && ! is_user_admin ($config['id_user']))) {
include ("general/noaccess.php");
return;
}
// Get different date to search the report.
$date = (string) get_parameter ('date', date ('Y-m-j'));
$time = (string) get_parameter ('time', date ('h:iA'));
// Header
print_page_header (__('Reporting'). " &raquo; ". __('Custom reporting'). " - ".$report["name"], "images/reporting.png", false, "", false, "" );
// Standard header
$url = "index.php?sec=reporting&sec2=operation/reporting/reporting_viewer&id=$id_report&date=$date&time=$time";
if ($config["pure"] == 0) {
$options[] = "<a href='$url&pure=1'>"
. print_image ("images/fullscreen.png", true, array ("title" => __('Full screen mode')))
. "</a>";
} else {
$options[] = "<a href='$url&pure=0'>"
. print_image ("images/normalscreen.png", true, array ("title" => __('Back to normal mode')))
. "</a>";
}
print_page_header (__('Reporting'). " &raquo; ". __('Custom reporting'). " - ".$report["name"], "images/reporting.png", false, "", false, $options);
$table->width = '99%';
$table->class = 'databox';
@ -79,6 +96,7 @@ echo '</div>';
/* We must add javascript here. Otherwise, the date picker won't
work if the date is not correct because php is returning. */
require_css_file ('datepicker');
require_jquery_file ('ui.core');
require_jquery_file ('ui.datepicker');
@ -96,12 +114,16 @@ $(document).ready (function () {
<?php
$datetime = strtotime ($date.' '.$time);
$report["datetime"] = $datetime;
if ($datetime === false || $datetime == -1) {
echo '<h3 class="error">'.__('Invalid date selected').'</h3>';
return;
}
// TODO: Evaluate if it's better to render blocks when are calculated (enabling realtime flush) or if it's better to wait report to be finished before showing anything (this could break the execution by overflowing the running PHP memory on HUGE reports).
$table->size = array ();
$table->style = array ();
$table->width = '99%';
@ -109,11 +131,13 @@ $table->class = 'databox report_table';
$table->rowclass = array ();
$table->rowclass[0] = 'datos3';
$group_name = get_group_name ($report['id_group']);
$report["group_name"] = get_group_name ($report['id_group']);
$contents = get_db_all_rows_field_filter ("treport_content", "id_report", $id_report, "`order`");
if ($contents === false) {
return;
}
foreach ($contents as $content) {
$table->data = array ();
$table->head = array ();
@ -121,392 +145,8 @@ foreach ($contents as $content) {
$table->colspan = array ();
$table->rowstyle = array ();
$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']);
switch ($content["type"]) {
case 1:
case 'simple_graph':
$table->colspan[1][0] = 4;
$data = array ();
$data[0] = '<h4>'.__('Simple graph').'</h4>';
$data[1] = '<h4>'.$agent_name.' - '.$module_name.'</h4>';
$data[2] = '<h4>'.human_time_description ($content['period']).'</h4>';
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[2][0] = 4;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$data[0] = '<img src="include/fgraph.php?tipo=sparse&id='.$content['id_agent_module'].'&height=230&width=750&period='.$content['period'].'&date='.$datetime.'&avg_only=1&pure=1" border="0" alt="">';
array_push ($table->data, $data);
break;
case 2:
case 'custom_graph':
$graph = get_db_row ("tgraph", "id_graph", $content['id_gs']);
$data = array ();
$data[0] = '<h4>'.__('Custom graph').'</h4>';
$data[1] = "<h4>".$graph["name"]."</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</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);
}
$result = get_db_all_rows_field_filter ("tgraph_source", "id_graph", $content['id_gs']);
$modules = array ();
$weights = array ();
if ($result === false)
$result = array();
foreach ($result as $content2) {
array_push ($modules, $content2['id_agent_module']);
array_push ($weights, $content2["weight"]);
}
$graph_width = get_db_sql ("SELECT width FROM tgraph WHERE id_graph = ".$content["id_gs"]);
$graph_height= get_db_sql ("SELECT height FROM tgraph WHERE id_graph = ".$content["id_gs"]);
render_report_html_item ($content, $table, $report);
$table->colspan[2][0] = 3;
$data = array ();
$data[0] = '<img src="include/fgraph.php?tipo=combined&id='.implode (',', $modules).'&weight_l='.implode (',', $weights).'&height=235&width=750&period='.$content['period'].'&date='.$datetime.'&stacked='.$graph["stacked"].'&pure=1" border="1" alt="">';
array_push ($table->data, $data);
break;
case 3:
case 'SLA':
$table->style[1] = 'text-align: right';
$data = array ();
$data[0] = '<h4>'.__('S.L.A.').'</h4>';
$data[1] = '<h4>'.human_time_description ($content['period']).'</h4>';;
$n = 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);
}
$slas = get_db_all_rows_field_filter ('treport_content_sla_combined',
'id_report_content', $content['id_rc']);
if ($slas === false) {
$data = array ();
$table->colspan[2][0] = 3;
$data[0] = __('There are no SLAs defined');
array_push ($table->data, $data);
$slas = array ();
}
$sla_failed = false;
foreach ($slas as $sla) {
$data = array ();
$data[0] = '<strong>'.__('Agent')."</strong> : ";
$data[0] .= get_agentmodule_agent_name ($sla['id_agent_module'])."<br />";
$data[0] .= '<strong>'.__('Module')."</strong> : ";
$data[0] .= get_agentmodule_name ($sla['id_agent_module'])."<br />";
$data[0] .= '<strong>'.__('SLA Max. (value)')."</strong> : ";
$data[0] .= $sla['sla_max']."<br />";
$data[0] .= '<strong>'.__('SLA Min. (value)')."</strong> : ";
$data[0] .= $sla['sla_min']."<br />";
$data[0] .= '<strong>'.__('SLA Limit')."</strong> : ";
$data[0] .= $sla['sla_limit'];
$sla_value = get_agentmodule_sla ($sla['id_agent_module'], $content['period'],
$sla['sla_min'], $sla['sla_max'], $datetime);
if ($sla_value === false) {
$data[1] = '<span style="font: bold 3em Arial, Sans-serif; color: #0000FF;">';
$data[1] .= __('Unknown');
} else {
if ($sla_value >= $sla['sla_limit'])
$data[1] = '<span style="font: bold 3em Arial, Sans-serif; color: #000000;">';
else {
$sla_failed = true;
$data[1] = '<span style="font: bold 3em Arial, Sans-serif; color: #ff0000;">';
}
$data[1] .= format_numeric ($sla_value). " %";
}
$data[1] .= "</span>";
$n = array_push ($table->data, $data);
}
if (!empty ($slas)) {
$data = array ();
if ($sla_failed == false)
$data[0] = '<span style="font: bold 3em Arial, Sans-serif; color: #000000;">'.__('OK').'</span>';
else
$data[0] = '<span style="font: bold 3em Arial, Sans-serif; color: #ff0000;">'.__('Fail').'</span>';
$n = array_push ($table->data, $data);
$table->colspan[$n - 1][0] = 3;
$table->rowstyle[$n - 1] = 'text-align: right';
}
break;
case 4:
case 'event_report':
$id_agent = get_agent_id ($agent_name);
$data = array ();
$data[0] = "<h4>".__('Event report')."</h4>";
$data[1] = "<h4>".human_time_description ($content['period'])."</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);
}
$table->colspan[2][0] = 3;
$data = array ();
$table_report = event_reporting ($report['id_group'], $content['period'], $datetime, true);
$table_report->class = 'databox';
$table_report->width = '100%';
$data[0] = print_table ($table_report, true);
array_push ($table->data, $data);
break;
case 5:
case 'alert_report':
$data = array ();
$data[0] = "<h4>".__('Alert report')."</h4>";
$data[1] = "<h4>$group_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</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] = alert_reporting ($report['id_group'], $content['period'], $datetime, true);
array_push ($table->data, $data);
break;
case 6:
case 'monitor_report':
$data = array ();
$data[0] = "<h4>".__('Monitor report')."</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</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 ();
$monitor_value = format_numeric (get_agentmodule_sla ($content['id_agent_module'], $content['period'], 1, false, $datetime));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">';
$data[0] .= $monitor_value.' % <img src="images/b_green.png" height="32" width="32" /></p>';
$monitor_value = format_numeric (100 - $monitor_value, 2) ;
$data[1] = '<p style="font: bold 3em Arial, Sans-serif; color: #ff0000;">';
$data[1] .= $monitor_value.' % <img src="images/b_red.png" height="32" width="32" /></p>';
array_push ($table->data, $data);
break;
case 7:
case 'avg_value':
$data = array ();
$data[0] = "<h4>".__('Avg. Value')."</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</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;
$value = format_numeric (get_agentmodule_data_average ($content['id_agent_module'], $content['period'], $datetime));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">'.$value.'</p>';
array_push ($table->data, $data);
break;
case 8:
case 'max_value':
$data = array ();
$data[0] = "<h4>".__('Max. Value')."</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</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;
$value = format_numeric (get_agentmodule_data_max ($content['id_agent_module'], $content['period'], $datetime));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">'.$value.'</p>';
array_push ($table->data, $data);
break;
case 9:
case 'min_value':
$data = array ();
$data[0] = "<h4>".__('Min. Value')."</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[0][0] = 2;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$table->colspan[1][0] = 2;
$value = format_numeric (get_agentmodule_data_min ($content['id_agent_module'], $content['period'], $datetime));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">'.$value.'</p>';
array_push ($table->data, $data);
break;
case 10:
case 'sumatory':
$data = array ();
$data[0] = "<h4>".__('Sumatory')."</h4>";
$data[1] = "<h4>$agent_name - $module_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[0][0] = 2;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$table->colspan[1][0] = 2;
$value = format_numeric (get_agentmodule_data_sum ($content['id_agent_module'], $content['period'], $datetime));
$data[0] = '<p style="font: bold 3em Arial, Sans-serif; color: #000000;">'.$value.'</p>';
array_push ($table->data, $data);
break;
case 11:
case 'general_group_report':
$data = array ();
$data[0] = "<h4>".__('Group')."</h4>";
$data[1] = "<h4>$group_name</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[0][0] = 2;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$table->colspan[1][0] = 2;
$data[0] = print_group_reporting ($report['id_group'], true);
array_push ($table->data, $data);
break;
case 12:
case 'monitor_health':
$data = array ();
$data[0] = "<h4>".__('Monitor health')."</h4>";
$data[1] = "<h4>$group_name</h4>";
$data[2] = "<h4>".human_time_description ($content['period'])."</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[0][0] = 4;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$data = array ();
$table->colspan[1][0] = 4;
$data[0] = monitor_health_reporting ($report['id_group'], $content['period'], $datetime, true);
array_push ($table->data, $data);
break;
case 13:
case 'agents_detailed':
$data = array ();
$data[0] = "<h4>".__('Agents detailed view')."</h4>";
$data[1] = "<h4>$group_name</h4>";
array_push ($table->data, $data);
// Put description at the end of the module (if exists)
if ($content["description"] != ""){
$table->colspan[0][0] = 2;
$data_desc = array();
$data_desc[0] = $content["description"];
array_push ($table->data, $data_desc);
}
$table->colspan[0][0] = 2;
$data = array ();
$table->colspan[1][0] = 3;
$data[0] = get_group_agents_detailed_reporting ($report['id_group'], $content['period'], $datetime, true);
array_push ($table->data, $data);
break;
case 'agent_detailed_event':
$data = array ();
$data[0] = "<h4>".__('Agent detailed event')."</h4>";
$data[1] = "<h4>".get_agent_name($content['id_agent'])."</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_agents_detailed_event_reporting ($content['id_agent'], $content['period'], $datetime);
array_push ($table->data, $data);
break;
}
print_table ($table);
flush ();
}