diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 8bb76d2202..b42acf694e 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,18 @@ +2011-04-12 Miguel de Dios + + * include/functions_graph.php: added constants for some graphs. Added + function "graphic_agentaccess2" and function "graph_event_module2". + + * include/graphs/functions_pchart.php: added checked previous $color and + $legend to avoid PHP warnings, added some code to calculate the bottom + margin. + + * include/graphs/fgraph.php: at the moment in this file call + "fs_3d_pie_chart2" instead "fs_3d_pie_chart". Erased the color and legend in + the piegraph. + + * operation/agentes/estado_generalagente.php: use new graphics functions. + 2011-04-12 Sergio Martin * include/graphs/functions_fsgraph.php diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 4b3968ff4d..0341ecc991 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -17,6 +17,11 @@ include_once($config["homedir"] . "/include/graphs/fgraph.php"); include_once($config["homedir"] . "/include/functions_reporting.php"); +define("GRAPH_AREA", 0); +define("GRAPH_STACKED_AREA", 1); +define("GRAPH_LINE", 2); +define("GRAPH_STACKED_LINE", 3); + function grafico_modulo_sparse2 ($agent_module_id, $period, $show_events, $width, $height , $title, $unit_name, $show_alerts, $avg_only = 0, $pure = false, @@ -600,56 +605,115 @@ function graphic_combined_module2 ($module_list, $weight_list, $period, $width, $title_period = __('Last %s days', format_numeric (($period / (3600 * 24)), 2)); $time_format = 'M j'; } - //////////////////////////////////////////////////////////////////////////// + switch ($stacked) { - case 0: + case GRAPH_AREA: $color = null; return area_graph($config['flash_charts'], $graph_values, $width, $height, - $color, $module_name_list, $long_index); - return; + $color, $module_name_list, $long_index, "images/image_problem.opaque.png"); break; default: - case 1: + case GRAPH_STACKED_AREA: $color = null; return stacked_area_graph($config['flash_charts'], $graph_values, $width, $height, - $color, $module_name_list, $long_index); + $color, $module_name_list, $long_index, "images/image_problem.opaque.png"); break; - case 2: + case GRAPH_LINE: $color = null; return line_graph($config['flash_charts'], $graph_values, $width, $height, - $color, $module_name_list, $long_index); + $color, $module_name_list, $long_index, "images/image_problem.opaque.png"); break; - case 3: + case GRAPH_STACKED_LINE: $color = null; - return line_graph($config['flash_charts'], $graph_values, $width, $height, - $color, $module_name_list, $long_index); + return stacked_line_graph($config['flash_charts'], $graph_values, $width, $height, + $color, $module_name_list, $long_index, "images/image_problem.opaque.png"); break; - } + } +} + +/** + * Print a graph with access 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_agentaccess2 ($id_agent, $width, $height, $period = 0) { + global $config; + global $graphic_type; + + $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 (); - //////////////////////////////////////////////////////////////////////////// - if (! $graphic_type) { - return fs_combined_chart ($graph_values, $graph, $module_name_list, $width, $height, $stacked, $resolution / 10, $time_format); + for ($i = 0; $i < $interval; $i++) { + $bottom = $datelimit + ($periodtime * $i); + if (! $graphic_type) { + $name = date('G:i', $bottom); + } else { + $name = $bottom; + } + + $top = $datelimit + ($periodtime * ($i + 1)); + $data[$name]['data'] = (int) get_db_value_filter ('COUNT(*)', + 'tagent_access', + array ('id_agent' => $id_agent, + 'utimestamp > '.$bottom, + 'utimestamp < '.$top)); + } + + echo area_graph($config['flash_charts'], $data, $width, $height, + null, null, null, "images/image_problem.opaque.png"); +} + +/** + * Print a pie graph with events data of agent + * + * @param integer width pie graph width + * @param integer height pie graph height + * @param integer id_agent Agent ID + */ +function graph_event_module2 ($width = 300, $height = 200, $id_agent) { + global $config; + global $graphic_type; + + $data = array (); + $max_items = 6; + $sql = sprintf ('SELECT COUNT(id_evento) as count_number, nombre + FROM tevento, tagente_modulo + WHERE id_agentmodule = id_agente_modulo + AND disabled = 0 AND tevento.id_agente = %d + GROUP BY id_agentmodule LIMIT %d', $id_agent, $max_items); + $events = get_db_all_rows_sql ($sql); + if ($events === false) { + if (! $graphic_type) { + return fs_error_image (); + } + graphic_error (); + return; } - $engine = get_graph_engine ($period); - - $engine->width = $width; - $engine->height = $height; - $engine->data = &$graph_values; - $engine->legend = $module_name_list; - $engine->fontpath = $config['fontpath']; - $engine->title = ""; - $engine->subtitle = ""; - $engine->show_title = !$pure; - $engine->stacked = $stacked; - $engine->xaxis_interval = $resolution; - $events = false; - $alerts = false; - if (!isset($max_value)) { - $max_value = 0; + + foreach ($events as $event) { + $data[$event['nombre'].' ('.$event['count_number'].')'] = $event["count_number"]; } - $engine->combined_graph ($graph, $events, $alerts, $unit_name, $max_value, $stacked); + /* System events */ + $sql = "SELECT COUNT(*) FROM tevento WHERE id_agentmodule = 0 AND id_agente = $id_agent"; + $value = get_db_sql ($sql); + if ($value > 0) { + $data[__('System').' ('.$value.')'] = $value; + } + asort ($data); + + return pie3d_graph(0, $data, $width, $height, __("other")); } ?> \ No newline at end of file diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index 8da5b48323..043cf9bf6c 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -133,7 +133,7 @@ function stacked_area_graph($flash_chart, $chart_data, $width, $height, $color, serialize_in_temp($graph, $id_graph); return ""; - } + } } function stacked_line_graph($flash_chart, $chart_data, $width, $height, $color, $legend, $long_index, $no_data_image) { @@ -241,7 +241,7 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height, $oth return fs_2d_pie_chart (array_values($chart_data), array_keys($chart_data), $width, $height); break; case "3d": - return fs_3d_pie_chart (array_values($chart_data), array_keys($chart_data), $width, $height); + return fs_3d_pie_chart2(array_values($chart_data), array_keys($chart_data), $width, $height); break; } } @@ -250,8 +250,6 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height, $oth $graph['data'] = $chart_data; $graph['width'] = $width; $graph['height'] = $height; - $graph['color'] = $color; - $graph['legend'] = $legend; $id_graph = serialize_in_temp($graph); diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index c8063d520c..025db28583 100755 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -52,8 +52,12 @@ if (!isset($graph)) { $data = $graph['data']; $width = $graph['width']; $height = $graph['height']; -$colors = $graph['color']; -$legend = $graph['legend']; +$colors = null; +if (isset($graph['color'])) + $colors = $graph['color']; +$legend = null; +if (isset($graph['legend'])) + $legend = $graph['legend']; $xaxisname = ''; if(isset($graph['xaxisname'])) { $xaxisname = $graph['xaxisname']; @@ -124,6 +128,8 @@ switch($graph_type) { case 'radar': case 'progress': case 'area': + case 'stacked_area': + case 'stacked_line': case 'line': case 'threshold': case 'scatter': @@ -147,11 +153,12 @@ switch($graph_type) { break; } - -if(!is_array(reset($data_values))) { - $data_values = array($data_values); - if(is_array($colors) && !empty($colors)) { - $colors = array($colors); +if (($graph_type != 'pie3d') && ($graph_type != 'pie2d')) { + if(!is_array(reset($data_values))) { + $data_values = array($data_values); + if(is_array($colors) && !empty($colors)) { + $colors = array($colors); + } } } @@ -240,7 +247,7 @@ function pch_pie_graph ($graph_type, $data_values, $legend_values, $width, $heig /* Set the default font properties */ $myPicture->setFontProperties(array("FontName"=>"../fonts/code.ttf","FontSize"=>10,"R"=>80,"G"=>80,"B"=>80)); - + /* Create the pPie object */ $PieChart = new pPie($myPicture,$MyData); @@ -489,13 +496,28 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height, $rgb_c $myPicture->drawLegend($width-$size['Width'], 8,array("Style"=>LEGEND_NOBORDER,"Mode"=>LEGEND_VERTICAL)); } + //Calculate the bottom margin from the size of string in each index + $max_chars = 0; + foreach ($index as $string_index) { + if (empty($string_index)) continue; + + $len = strlen($string_index); + if ($len > $max_chars) { + $max_chars = $len; + } + } + $margin_bottom = 10 * $max_chars; + //$margin_bottom = 90; + if (isset($size['Height'])) { /* Define the chart area */ - $myPicture->setGraphArea(40,$size['Height'],$width,$height - 90); + //$myPicture->setGraphArea(40,$size['Height'],$width,$height - 90); + $myPicture->setGraphArea(40,$size['Height'],$width,$height - $margin_bottom); } else { /* Define the chart area */ - $myPicture->setGraphArea(40, 5,$width,$height - 90); + //$myPicture->setGraphArea(40, 5,$width,$height - 90); + $myPicture->setGraphArea(40, 5,$width,$height - $margin_bottom); } /* Draw the scale */ diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 8a9adbbcbb..442a9a4f68 100644 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -20,6 +20,8 @@ global $config; require_once ("include/functions_agents.php"); +require_once ($config["homedir"] . '/include/functions_graph.php'); + if ($config['flash_charts']) { require_once ("include/fgraph.php"); } @@ -49,16 +51,17 @@ echo '
 
'; //Floating div echo '
'; echo ''.__('Agent access rate (24h)').'
'; -if ($config['flash_charts']) { - echo graphic_agentaccess ($id_agente, 280, 110, 86400); -} else { - echo ''; -} + +graphic_agentaccess2($id_agente, 280, 110, 86400); + echo '
 
'; echo ''.__('Events generated -by module-').'
'; if ($config['flash_charts']) { + /////// echo graphic_agentevents ($id_agente, 290, 60, 86400); - echo graph_event_module (290, 120, $id_agente); + /////// + echo graph_event_module2 (290, 120, $id_agente); + } else { echo ''; }