From 36db9ce4bd03313b9bc402a6cb2f09a45bb63940 Mon Sep 17 00:00:00 2001 From: mdtrooper Date: Mon, 18 Apr 2011 14:05:54 +0000 Subject: [PATCH] 2011-04-18 Miguel de Dios * include/functions_graph.php, include/graphs/functions_pchart.php, include/graphs/fgraph.php, operation/agentes/estado_generalagente.php: some fixes and changes in the new graph engine. * operation/agentes/stat_win.php: fixed the tittle of popup window. git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@4236 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f --- pandora_console/ChangeLog | 8 ++ pandora_console/include/functions_graph.php | 131 +++++++++++++++++- pandora_console/include/graphs/fgraph.php | 1 + .../include/graphs/functions_pchart.php | 10 +- .../agentes/estado_generalagente.php | 2 +- .../operation/agentes/stat_win.php | 34 +++-- 6 files changed, 164 insertions(+), 22 deletions(-) diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index e9efced3c7..13aa296ac8 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,11 @@ +2011-04-18 Miguel de Dios + + * include/functions_graph.php, include/graphs/functions_pchart.php, + include/graphs/fgraph.php, operation/agentes/estado_generalagente.php: some + fixes and changes in the new graph engine. + + * operation/agentes/stat_win.php: fixed the tittle of popup window. + 2011-04-18 Miguel de Dios * include/functions_reporting.php: changed to use new engine. diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 18b8e7f1b6..fb162eca5d 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -30,6 +30,8 @@ function grafico_modulo_sparse2 ($agent_module_id, $period, $show_events, global $config; global $graphic_type; + //include_flash_chart_script(); + // Set variables if ($date == 0) $date = get_system_time(); $datelimit = $date - $period; @@ -74,7 +76,8 @@ function grafico_modulo_sparse2 ($agent_module_id, $period, $show_events, $min_necessary = 1; // Compressed module data - } else { + } + else { // Get previous data $previous_data = get_previous_data ($agent_module_id, $datelimit); if ($previous_data !== false) { @@ -86,7 +89,8 @@ function grafico_modulo_sparse2 ($agent_module_id, $period, $show_events, $nextData = get_next_data ($agent_module_id, $date); if ($nextData !== false) { array_push ($data, $nextData); - } else if (count ($data) > 0) { + } + else if (count ($data) > 0) { // Propagate the last known data to the end of the interval $nextData = array_pop ($data); array_push ($data, $nextData); @@ -657,6 +661,8 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width, function graphic_agentaccess2 ($id_agent, $width, $height, $period = 0) { global $config; global $graphic_type; + + include_flash_chart_script(); $data = array (); @@ -729,7 +735,7 @@ function graph_event_module2 ($width = 300, $height = 200, $id_agent) { } asort ($data); - return pie3d_graph(0, $data, $width, $height, __("other")); + return pie3d_graph($config['flash_charts'], $data, $width, $height, __("other")); } function progress_bar2($progress, $width, $height, $title = '', $mode = 1) { @@ -1289,4 +1295,123 @@ function graph_custom_sql_graph2 ($id, $width, $height, $type = 'sql_graph_vbar' break; } } + +/** + * Print a graph with event data of agents + * + * @param integer id_agent Agent ID + * @param integer width pie graph width + * @param integer height pie graph height + * @param integer period time period + */ +function graphic_agentevents2 ($id_agent, $width, $height, $period = 0) { + global $config; + global $graphic_type; + + include_flash_chart_script(); + + $data = array (); + + $resolution = $config['graph_res'] * ($period * 2 / $width); // Number of "slices" we want in graph + + $interval = (int) ($period / $resolution); + $date = get_system_time (); + $datelimit = $date - $period; + $periodtime = floor ($period / $interval); + $time = array (); + $data = array (); + + for ($i = 0; $i < $interval; $i++) { + $bottom = $datelimit + ($periodtime * $i); + if (! $graphic_type) { + $name = date('H\h', $bottom); + } else { + $name = $bottom; + } + + $top = $datelimit + ($periodtime * ($i + 1)); + $criticity = (int) get_db_value_filter ('criticity', + 'tevento', + array ('id_agente' => $id_agent, + 'utimestamp > '.$bottom, + 'utimestamp < '.$top)); + + switch ($criticity) { + case 3: $data[$name] = 'E5DF63'; + break; + case 4: $data[$name] = 'FF3C4B'; + break; + default: $data[$name] = '9ABD18'; + } + + } + + if (! $graphic_type) { + return fs_agent_event_chart2 ($data, $width, $height, $resolution / 750); + } +} + +// Clean FLASH string strips non-valid characters for flashchart +function clean_flash_string ($string) { + $string = html_entity_decode ($string, ENT_QUOTES, "UTF-8"); + $string = str_replace('&', '', $string); + $string = str_replace(' ', '', $string); + $string = str_replace ('"', '', $string); + return substr ($string, 0, 20); +} + +// Returns a Pandora FMS agent event chart +function fs_agent_event_chart2 ($data, $width, $height, $step = 1) { + global $config; + + if (sizeof ($data) == 0) { + return fs_error_image (); + } + + // Generate the XML + $chart = new FusionCharts('Area2D', $width, $height); + + $count = 0; + $num_vlines = 0; + foreach ($data as $name => $value) { + if ($count++ % $step == 0) { + $show_name = '1'; + $num_vlines++; + } else { + $show_name = '0'; + } + $chart->addChartData(1, 'name=' . clean_flash_string($name) . ';showName=' . $show_name . ';color=' . $value); + } + + $chart->setChartParams('numDivLines=0;numVDivLines=0;showNames=1;rotateNames=0;showValues=0;baseFontSize=9;showLimits=0;showAreaBorder=0;areaBorderThickness=1;canvasBgColor=9ABD18'); + + // Return the code + return get_chart_code ($chart, $width, $height, 'include/FusionCharts/FCF_Area2D.swf'); +} + +// Returns the code needed to display the chart +function get_chart_code ($chart, $width, $height, $swf) { + $random_number = rand (); + $div_id = 'chart_div_' . $random_number; + $chart_id = 'chart_' . $random_number; + $output = '
'; + $output .= ''; + return $output; +} + +// Prints an error image +function fs_error_image () { + global $config; + + return print_image("images/image_problem.png", true, array("border" => '0')); +} ?> \ No newline at end of file diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 6ee657dddc..3052893032 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -10,6 +10,7 @@ // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the // GNU General Public License for more details. + // If is called from index if(file_exists('include/functions.php')) { include_once('include/functions.php'); diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index 1436eb8af7..d26ba3e952 100755 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -60,15 +60,17 @@ if (!isset($graph)) { $data = $graph['data']; $width = $graph['width']; $height = $graph['height']; -if (isset($graph['color'])) { +$colors = null; +if (isset($graph['color'])) $colors = $graph['color']; -} -if (isset($graph['legend'])) { +$legend = null; +if (isset($graph['legend'])) $legend = $graph['legend']; -} +$xaxisname = ''; if(isset($graph['xaxisname'])) { $xaxisname = $graph['xaxisname']; } +$yaxisname = ''; if(isset($graph['yaxisname'])) { $yaxisname = $graph['yaxisname']; } diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 167dbb314e..dfb81471fb 100644 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -54,7 +54,7 @@ echo '
 
'; echo ''.__('Events generated -by module-').'
'; echo graph_event_module2 (290, 120, $id_agente); if ($config['flash_charts']) { - echo graphic_agentevents ($id_agente, 290, 60, 86400); + echo graphic_agentevents2 ($id_agente, 290, 60, 86400); } echo ''; diff --git a/pandora_console/operation/agentes/stat_win.php b/pandora_console/operation/agentes/stat_win.php index 7c7c5ac362..9d5d2086ea 100644 --- a/pandora_console/operation/agentes/stat_win.php +++ b/pandora_console/operation/agentes/stat_win.php @@ -30,6 +30,9 @@ require_once ($config["homedir"] . '/include/functions_reporting.php'); require_once ($config["homedir"] . '/include/functions_graph.php'); check_login (); + +$id = get_parameter('id'); +$label = base64_decode(get_parameter('label', '')); ?> @@ -134,14 +137,27 @@ if ($start_date != $current) else $date = $utime; +$urlImage = 'http://'; +if ($config['https']) { + $urlImage = 'https://'; +} +$urlImage .= $config['dbhost'] . $config['homeurl'] . '/'; + // log4x doesnt support flash yet // +switch ($graph_type) { + case 'sparse': + echo grafico_modulo_sparse2 ($id, $period, $draw_events, $width, $height, + $label, null, $draw_alerts, $avg_only, false, $date, $baseline, + 0, true, false, $urlImage); + break; + default: + echo fs_error_image ('../images'); + break; +} + if ($config['flash_charts'] && $graph_type != "log4x") { switch ($graph_type) { - case 'sparse': - echo grafico_modulo_sparse2 ($id, $period, $draw_events, $width, $height, - $label, $unit_name, $draw_alerts, $avg_only, $pure, $date, $baseline); - break; case 'boolean': echo grafico_modulo_boolean ($id, $period, $draw_events, $width, $height, $label, $unit_name, $draw_alerts, 1, $pure, $date); @@ -154,17 +170,10 @@ if ($config['flash_charts'] && $graph_type != "log4x") { echo grafico_modulo_log4x ($id, $period, $draw_events, $width, $height, $label, $unit_name, $draw_alerts, 1, $pure, $date, 1); break; - default: - echo fs_error_image ('../images'); - break; } } else { switch ($graph_type) { - case 'sparse': - echo grafico_modulo_sparse2 ($id, $period, $draw_events, $width, $height, - $label, $unit_name, $draw_alerts, $avg_only, $pure, $date, $baseline); - break; case 'boolean': echo grafico_modulo_boolean ($id, $period, $draw_events, $width, $height, $label, $unit_name, $draw_alerts, 1, $pure, $date); @@ -177,9 +186,6 @@ else { echo grafico_modulo_log4x ($id, $period, $draw_events, $width, $height, $label, $unit_name, $draw_alerts, 1, $pure, $date, 1); break; - default: - echo fs_error_image ('../images'); - break; } }