diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index a1e4fbf546..8e0f73f220 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,19 @@ +2013-02-20 Sergio Martin + + * include/functions_graph.php + include/graphs/functions_pchart.php + include/graphs/functions_flot.php + include/graphs/flot/pandora.flot.js + include/graphs/fgraph.php + include/graphs/functions_utils.php + operation/agentes/estado_generalagente.php: Add + a new agent status pie graph and partial remodelation + of the agent detail view hidding the graphs in a lateral + tab and adding graphs + + * operation/agentes/estado_agente.php: Optimize + useless queries to get the agents status + 2013-02-20 Sergio Martin * general/main_menu.php: Update missed change from diff --git a/pandora_console/include/functions_graph.php b/pandora_console/include/functions_graph.php index 9d5b5da9f6..a18ace407f 100755 --- a/pandora_console/include/functions_graph.php +++ b/pandora_console/include/functions_graph.php @@ -1267,8 +1267,9 @@ function graphic_combined_module ($module_list, $weight_list, $period, $width, $ * @param integer width pie graph width * @param integer height pie graph height * @param integer period time period + * @param bool return or echo the result flag */ -function graphic_agentaccess ($id_agent, $width, $height, $period = 0) { +function graphic_agentaccess ($id_agent, $width, $height, $period = 0, $return = false) { global $config; global $graphic_type; @@ -1321,15 +1322,61 @@ function graphic_agentaccess ($id_agent, $width, $height, $period = 0) { 'url' => ui_get_full_url("/images/logo_vertical_water.png")); if ($empty_data) - echo fs_error_image(); + $out = fs_error_image(); else { - echo area_graph($config['flash_charts'], $data, $width, $height, + $out = area_graph($config['flash_charts'], $data, $width, $height, null, null, null, ui_get_full_url("images/image_problem.opaque.png"), "", "", ui_get_full_url(false, false, false, false), $water_mark, $config['fontpath'], $config['font_size'], ""); } + + if($return) { + return $out; + } + else { + echo $out; + } } +/** + * Print a pie graph with events data of agent + * + * @param integer id_agent Agent ID + * @param integer width pie graph width + * @param integer height pie graph height + * @param bool return or echo flag + */ +function graph_agent_status ($id_agent, $width = 300, $height = 200, $return = false) { + global $config; + + $filter = array('id_agente' => $id_agent, 'disabled' => 0); + $fields = array('sum(critical_count) Critical', + 'sum(warning_count) Warning', + 'sum(normal_count) Normal', + 'sum(unknown_count) Unknown', + 'sum(notinit_count) "Not init"'); + + $agent_status = db_get_all_rows_filter('tagente', $filter, $fields); + + $data = reset($agent_status); + + $water_mark = array('file' => $config['homedir'] . "/images/logo_vertical_water.png", + 'url' => ui_get_full_url("/images/logo_vertical_water.png")); + + $colors = array(COL_CRITICAL, COL_WARNING, COL_NORMAL, COL_UNKNOWN, COL_NOTINIT); + + $out = pie2d_graph($config['flash_charts'], $data, $width, $height, __("other"), + '', $water_mark, $config['fontpath'], $config['font_size'], 1, "hidden", $colors); + + if ($return) { + return $out; + } + else { + echo $out; + } +} + + /** * Print a pie graph with events data of agent * @@ -1386,11 +1433,10 @@ function graph_event_module ($width = 300, $height = 200, $id_agent) { if ($value > 0) { $data[__('System').' ('.$value.')'] = $value; } - asort ($data); $water_mark = array('file' => $config['homedir'] . "/images/logo_vertical_water.png", 'url' => ui_get_full_url("/images/logo_vertical_water.png")); - + return pie3d_graph($config['flash_charts'], $data, $width, $height, __("other"), '', $water_mark, $config['fontpath'], $config['font_size'], 1, "bottom"); @@ -2228,8 +2274,10 @@ function graph_custom_sql_graph ($id, $width, $height, $type = 'sql_graph_vbar', * @param integer width pie graph width * @param integer height pie graph height * @param integer period time period + * @param string homeurl + * @param bool return or echo the result */ -function graph_graphic_agentevents ($id_agent, $width, $height, $period = 0, $homeurl) { +function graph_graphic_agentevents ($id_agent, $width, $height, $period = 0, $homeurl, $return = false) { global $config; global $graphic_type; @@ -2293,19 +2341,26 @@ function graph_graphic_agentevents ($id_agent, $width, $height, $period = 0, $ho // Draw slicebar graph if ($config['flash_charts']) { - echo flot_slicesbar_graph($data, $period, $width, $height, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $homeurl); + $out = flot_slicesbar_graph($data, $period, $width, $height, $full_legend, $colors, $config['fontpath'], $config['round_corner'], $homeurl); } else { - echo slicesbar_graph($data, $period, $width, $height, $colors, $config['fontpath'], $config['round_corner'], $homeurl); + $out = slicesbar_graph($data, $period, $width, $height, $colors, $config['fontpath'], $config['round_corner'], $homeurl); // Draw legend - echo "
"; - echo " "; + $out .= "
"; + $out .= " "; foreach ($legend as $hour) { - echo "" . $hour . ""; - echo " "; + $out .= "" . $hour . ""; + $out .= " "; } } + + if($return) { + return $out; + } + else { + echo $out; + } } // Prints an error image diff --git a/pandora_console/include/graphs/fgraph.php b/pandora_console/include/graphs/fgraph.php index bc52c52002..0ab44db06f 100755 --- a/pandora_console/include/graphs/fgraph.php +++ b/pandora_console/include/graphs/fgraph.php @@ -435,24 +435,25 @@ function hbar_graph($flash_chart, $chart_data, $width, $height, $color = array() function pie3d_graph($flash_chart, $chart_data, $width, $height, $others_str = "other", $homedir="", $water_mark = "", $font = '', - $font_size = '', $ttl = 1, $legend_position = false) { + $font_size = '', $ttl = 1, $legend_position = false, $colors = '') { return pie_graph('3d', $flash_chart, $chart_data, $width, $height, $others_str, $homedir, $water_mark, $font, $font_size, $ttl, - $legend_position); + $legend_position, $colors); } function pie2d_graph($flash_chart, $chart_data, $width, $height, $others_str = "other", $homedir="", $water_mark = "", $font = '', - $font_size = '', $ttl = 1, $legend_position = false) { + $font_size = '', $ttl = 1, $legend_position = false, $colors = '') { return pie_graph('2d', $flash_chart, $chart_data, $width, $height, - $others_str, $homedir, $water_mark, $font, $font_size, $ttl, $legend_position); + $others_str, $homedir, $water_mark, $font, $font_size, $ttl, + $legend_position, $colors); } function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height, $others_str = "other", $homedir="", $water_mark = "", $font = '', - $font_size = '', $ttl = 1, $legend_position = false) { + $font_size = '', $ttl = 1, $legend_position = false, $colors = '') { setup_watermark($water_mark, $water_mark_file, $water_mark_url); @@ -480,7 +481,7 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height, if ($flash_chart) { return flot_pie_chart(array_values($chart_data), array_keys($chart_data), $width, $height, $water_mark_url, - $font, $font_size, $legend_position); + $font, $font_size, $legend_position, $colors); } else { //TODO SET THE LEGEND POSITION @@ -492,7 +493,9 @@ function pie_graph($graph_type, $flash_chart, $chart_data, $width, $height, $graph['water_mark'] = $water_mark_file; $graph['font'] = $font; $graph['font_size'] = $font_size; - + $graph['legend_position'] = $legend_position; + $graph['color'] = $colors; + $id_graph = serialize_in_temp($graph, null, $ttl); switch($graph_type) { diff --git a/pandora_console/include/graphs/flot/pandora.flot.js b/pandora_console/include/graphs/flot/pandora.flot.js index 688b4eed50..31bc7e8a32 100644 --- a/pandora_console/include/graphs/flot/pandora.flot.js +++ b/pandora_console/include/graphs/flot/pandora.flot.js @@ -3,12 +3,20 @@ */ -function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, water_mark, separator, legend_position, height) { +function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, water_mark, separator, legend_position, height, colors) { var labels = labels.split(separator); var data = values.split(separator); + if(colors != '') { + colors = colors.split(separator); + } + var color = null; for (var i = 0; i < nseries; i++) { - data[i] = { label: labels[i], data: parseInt(data[i]) } + if(colors != '') { + color = colors[i]; + } + + data[i] = { label: labels[i], data: parseInt(data[i]), color: color} } var label_conf; @@ -34,6 +42,11 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, wat }; } + var show_legend = true; + if(legend_position == 'hidden') { + show_legend = false; + } + var conf_pie = { series: { pie: { @@ -45,7 +58,7 @@ function pandoraFlotPie(graph_id, values, labels, nseries, width, font_size, wat } }, legend: { - show: true + show: show_legend }, grid: { hoverable: true, diff --git a/pandora_console/include/graphs/functions_flot.php b/pandora_console/include/graphs/functions_flot.php index 965a95c2c2..4411d0dda3 100644 --- a/pandora_console/include/graphs/functions_flot.php +++ b/pandora_console/include/graphs/functions_flot.php @@ -318,7 +318,7 @@ function flot_area_graph($chart_data, $width, $height, $color, $legend, $long_in // Prints a FLOT pie chart function flot_pie_chart ($values, $labels, $width, $height, $water_mark, - $font = '', $font_size = 8, $legend_position = '') { + $font = '', $font_size = 8, $legend_position = '', $colors = '') { include_javascript_dependencies_flot_graph(); @@ -353,12 +353,15 @@ function flot_pie_chart ($values, $labels, $width, $height, $water_mark, $labels = implode($separator, $labels); $values = implode($separator, $values); + if(!empty($colors)) { + $colors = implode($separator, $colors); + } $return .= ""; diff --git a/pandora_console/include/graphs/functions_pchart.php b/pandora_console/include/graphs/functions_pchart.php index 7f12c87f8c..43c831722b 100755 --- a/pandora_console/include/graphs/functions_pchart.php +++ b/pandora_console/include/graphs/functions_pchart.php @@ -44,6 +44,7 @@ $legend = null; $colors = null; $font_size = 8; $force_steps = true; +$legend_position = null; $graph_type = get_parameter('graph_type', ''); @@ -65,6 +66,9 @@ $data = $graph['data']; $width = $graph['width']; $height = $graph['height']; +if (isset($graph['legend_position'])) { + $legend_position = $graph['legend_position']; +} if (isset($graph['color'])) { $colors = $graph['color']; } @@ -273,7 +277,7 @@ switch($graph_type) { case 'pie3d': case 'pie2d': pch_pie_graph($graph_type, array_values($data), array_keys($data), - $width, $height, $font, $water_mark, $font_size); + $width, $height, $font, $water_mark, $font_size, $legend_position, $colors); break; case 'slicebar': pch_slicebar_graph($graph_type, $data, $period, $width, $height, $colors, $font, $round_corner, $font_size); @@ -368,7 +372,7 @@ function pch_slicebar_graph ($graph_type, $data, $period, $width, $height, $colo } function pch_pie_graph ($graph_type, $data_values, $legend_values, $width, - $height, $font, $water_mark, $font_size) { + $height, $font, $water_mark, $font_size, $legend_position, $colors) { /* CAT:Pie charts */ /* Create and populate the pData object */ @@ -384,9 +388,7 @@ function pch_pie_graph ($graph_type, $data_values, $legend_values, $width, $myPicture = new pImage($width,$height,$MyData,TRUE); /* Set the default font properties */ - $myPicture->setFontProperties(array("FontName"=>$font,"FontSize"=>$font_size,"R"=>80,"G"=>80,"B"=>80)); - - + $myPicture->setFontProperties(array("FontName"=>$font,"FontSize"=>$font_size,"R"=>80,"G"=>80,"B"=>80)); $water_mark_height = 0; $water_mark_width = 0; @@ -403,6 +405,13 @@ function pch_pie_graph ($graph_type, $data_values, $legend_values, $width, /* Create the pPie object */ $PieChart = new pPie($myPicture,$MyData); + foreach($data_values as $key => $value) { + if(isset($colors[$key])) { + html_debug_print(hex_2_rgb($colors[$key]), true); + $PieChart->setSliceColor($key, hex_2_rgb($colors[$key])); + } + } + /* Draw an AA pie chart */ switch($graph_type) { case "pie2d": @@ -418,7 +427,9 @@ function pch_pie_graph ($graph_type, $data_values, $legend_values, $width, $max_chars = graph_get_max_index($legend_values); $legend_with_aprox = 32 + (7 * $max_chars); - $PieChart->drawPieLegend($width - $legend_with_aprox, 5, array("R"=>255,"G"=>255,"B"=>255, "BoxSize"=>10)); + if($legend_position != 'hidden') { + $PieChart->drawPieLegend($width - $legend_with_aprox, 5, array("R"=>255,"G"=>255,"B"=>255, "BoxSize"=>10)); + } /* Enable shadow computing */ $myPicture->setShadow(TRUE,array("X"=>3,"Y"=>3,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10)); diff --git a/pandora_console/include/graphs/functions_utils.php b/pandora_console/include/graphs/functions_utils.php index 4affbde2f7..8caf3f35c2 100644 --- a/pandora_console/include/graphs/functions_utils.php +++ b/pandora_console/include/graphs/functions_utils.php @@ -178,7 +178,7 @@ function hue_2_rgb($v1,$v2,$vh) { return ($v1); }; -function get_complementary_rgb ($hexcode) { +function hex_2_rgb($hexcode) { $hexcode = str_replace('#', '', $hexcode); // $hexcode is the six digit hex colour code we want to convert @@ -189,9 +189,19 @@ function get_complementary_rgb ($hexcode) { // $var_r, $var_g and $var_b are the three decimal fractions to be input to our RGB-to-HSL conversion routine - $var_r = (hexdec($redhex)) / 255; - $var_g = (hexdec($greenhex)) / 255; - $var_b = (hexdec($bluehex)) / 255; + $var_r = hexdec($redhex); + $var_g = hexdec($greenhex); + $var_b = hexdec($bluehex); + + return array('R' => $var_r, 'G' => $var_g, 'B' => $var_b); +} + +function get_complementary_rgb ($hexcode) { + $rgb = hex_2_rgb($hexcode); + + $var_r = $rgb['R'] / 255; + $var_g = $rgb['G'] / 255; + $var_b = $rgb['B'] / 255; //Now plug these values into the rgb2hsl routine. Below is my PHP version of EasyRGB.com's generic code for that conversion: diff --git a/pandora_console/operation/agentes/estado_agente.php b/pandora_console/operation/agentes/estado_agente.php index c6002479fe..d6b7f4f05f 100644 --- a/pandora_console/operation/agentes/estado_agente.php +++ b/pandora_console/operation/agentes/estado_agente.php @@ -346,7 +346,15 @@ $agents = agents_get_agents(array ( 'id_os', 'ultimo_contacto', 'intervalo', - 'comentarios description', 'quiet'), + 'comentarios description', + 'quiet', + 'normal_count', + 'warning_count', + 'critical_count', + 'unknown_count', + 'notinit_count', + 'total_count', + 'fired_count'), 'AR', $order); @@ -415,21 +423,11 @@ foreach ($agents as $agent) { $rowPair = !$rowPair; $iterator++; - $agent_info["monitor_alertsfired"] = agents_get_alerts_fired ($agent["id_agente"]); - - $agent_info["monitor_critical"] = agents_monitor_critical ($agent["id_agente"]); - $agent_info["monitor_warning"] = agents_monitor_warning ($agent["id_agente"]); - $agent_info["monitor_unknown"] = agents_monitor_unknown ($agent["id_agente"]); - $agent_info["monitor_normal"] = agents_monitor_ok ($agent["id_agente"]); - - $agent_info["alert_img"] = agents_tree_view_alert_img ($agent_info["monitor_alertsfired"]); - - $agent_info["status_img"] = agents_tree_view_status_img ($agent_info["monitor_critical"], - $agent_info["monitor_warning"], $agent_info["monitor_unknown"]); - - //Count all modules - $agent_info["modules"] = $agent_info["monitor_critical"] + $agent_info["monitor_warning"] + $agent_info["monitor_unknown"] + $agent_info["monitor_normal"]; + $alert_img = agents_tree_view_alert_img ($agent["fired_count"]); + $status_img = agents_tree_view_status_img ($agent["critical_count"], + $agent["warning_count"], $agent["unknown_count"]); + $data = array (); $data[0] = ''; @@ -458,23 +456,23 @@ foreach ($agents as $agent) { $data[4] = ui_print_group_icon ($agent["id_grupo"], true); $data[5] = ''; - $data[5] .= $agent_info["modules"]; + $data[5] .= $agent["total_count"]; - if ($agent_info["monitor_alertsfired"] > 0) - $data[5] .= ' : ' . $agent_info["monitor_alertsfired"] . ''; - if ($agent_info["monitor_critical"] > 0) - $data[5] .= ' : ' . $agent_info["monitor_critical"] . ''; - if ($agent_info["monitor_warning"] > 0) - $data[5] .= ' : ' . $agent_info["monitor_warning"] . ''; - if ($agent_info["monitor_unknown"] > 0) - $data[5] .= ' : ' . $agent_info["monitor_unknown"] . ''; - if ($agent_info["monitor_normal"] > 0) - $data[5] .= ' : ' . $agent_info["monitor_normal"] . ''; + if ($agent["fired_count"] > 0) + $data[5] .= ' : ' . $agent["fired_count"] . ''; + if ($agent["critical_count"] > 0) + $data[5] .= ' : ' . $agent["critical_count"] . ''; + if ($agent["warning_count"] > 0) + $data[5] .= ' : ' . $agent["warning_count"] . ''; + if ($agent["unknown_count"] > 0) + $data[5] .= ' : ' . $agent["unknown_count"] . ''; + if ($agent["normal_count"] > 0) + $data[5] .= ' : ' . $agent["normal_count"] . ''; $data[5] .= ''; - $data[6] = $agent_info["status_img"]; + $data[6] = $status_img; - $data[7] = $agent_info["alert_img"]; + $data[7] = $alert_img; $last_time = strtotime ($agent["ultimo_contacto"]); diff --git a/pandora_console/operation/agentes/estado_generalagente.php b/pandora_console/operation/agentes/estado_generalagente.php index 3ce3879b78..8b64d037b1 100644 --- a/pandora_console/operation/agentes/estado_generalagente.php +++ b/pandora_console/operation/agentes/estado_generalagente.php @@ -50,29 +50,34 @@ if (! check_acl ($config["id_user"], $agent["id_grupo"], "AR") && !$is_extra) { return; } -// Blank space below title, DONT remove this, this -// Breaks the layout when Flash charts are enabled :-o -echo '
 
'; - - //Floating div - echo '
'; +$params = array(); +$params['position'] = 'right'; +$params['icon_closed'] = 'images/setup.png'; +$params['body_text'] = ''; if ($config["agentaccess"]) { - echo ''.__('Agent access rate (24h)').'
'; + $params['body_text'] .= ''.__('Agent access rate (24h)').'
'; - graphic_agentaccess($id_agente, 280, 110, 86400); + $params['body_text'] .= graphic_agentaccess($id_agente, 350, 110, 86400, true); } -echo '
 
'; -echo ''.__('Events generated -by module-').'
'; -echo graph_event_module (290, 120, $id_agente); -echo '
'; -graph_graphic_agentevents ($id_agente, 290, 15, 86400, ''); +$params['body_text'] .= '
 
'; +$params['body_text'] .= ''.__('Events generated -by module-').'
'; +$params['body_text'] .= graph_event_module (350, 120, $id_agente); + +$params['icon_closed'] = '/images/chart_curve'; +$params['icon_open'] = '/images/chart_curve'; +$params['height'] = '460px'; +$params['top'] = 'auto_below'; +$params['autotop'] = 'menu_tab_frame_view'; +$params['icon_width'] = 16; +$params['icon_height'] = 16; + +html_print_side_layer($params); -echo '
'; echo '
'; -echo ''; +echo '
'; //Agent name echo ''; if ($agent['disabled']) { @@ -90,6 +95,13 @@ echo ''; echo ''; +// Status +$status_img = agents_tree_view_status_img ($agent["critical_count"], + $agent["warning_count"], $agent["unknown_count"]); + +echo ''; +echo ''; + //Addresses echo ''; echo ''; echo ''; +echo ''; +echo ''; + +echo ''; +echo ''; + // Custom fields $fields = db_get_all_rows_filter('tagent_custom_fields', array('display_on_front' => 1)); if ($fields === false) {
'.__('Agent name').''.$cellName.'' . html_print_image("images/refresh.png", true, array("border" => '0', "title" => __('Refresh data'), "alt" => "")) . ' '; echo '' . html_print_image("images/target.png", true, array("border" => '0', "title" => __('Force'), "alt" => "")) . '
' . __('Status') . '' . $status_img . '
'.__('IP Address').''; @@ -202,6 +214,12 @@ $progress = agents_get_next_contact($id_agente); echo '
' . __('Next agent contact') . '' . progress_bar($progress, 200, 20) . '
' . __('Events') . '' . graph_graphic_agentevents ($id_agente, 290, 15, 86400, '', true) . '
' . __('Modules status') . '' . graph_agent_status ($id_agente, 100, 100, true) . '