2013-02-20 Sergio Martin <sergio.martin@artica.es>

* 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



git-svn-id: https://svn.code.sf.net/p/pandora/code/trunk@7687 c3f86ba8-e40f-0410-aaad-9ba5e7f4b01f
This commit is contained in:
zarzuelo 2013-02-20 17:15:38 +00:00
parent 50fddb6a55
commit c734c1072d
9 changed files with 204 additions and 77 deletions

View File

@ -1,3 +1,19 @@
2013-02-20 Sergio Martin <sergio.martin@artica.es>
* 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 <sergio.martin@artica.es>
* general/main_menu.php: Update missed change from

View File

@ -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 "<br>";
echo "&nbsp;";
$out .= "<br>";
$out .= "&nbsp;";
foreach ($legend as $hour) {
echo "<span style='font-size: 6pt'>" . $hour . "</span>";
echo "&nbsp;";
$out .= "<span style='font-size: 6pt'>" . $hour . "</span>";
$out .= "&nbsp;";
}
}
if($return) {
return $out;
}
else {
echo $out;
}
}
// Prints an error image

View File

@ -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) {

View File

@ -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,

View File

@ -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 .= "<script type='text/javascript'>";
$return .= "pandoraFlotPie('$graph_id', '$values', '$labels',
'$series', '$width', $font_size, $water_mark,
'$separator', '$legend_position', '$height')";
'$separator', '$legend_position', '$height', '$colors')";
$return .= "</script>";

View File

@ -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));

View File

@ -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:

View File

@ -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] = '<b>';
$data[5] .= $agent_info["modules"];
$data[5] .= $agent["total_count"];
if ($agent_info["monitor_alertsfired"] > 0)
$data[5] .= ' : <span class="orange">' . $agent_info["monitor_alertsfired"] . '</span>';
if ($agent_info["monitor_critical"] > 0)
$data[5] .= ' : <span class="red">' . $agent_info["monitor_critical"] . '</span>';
if ($agent_info["monitor_warning"] > 0)
$data[5] .= ' : <span class="yellow">' . $agent_info["monitor_warning"] . '</span>';
if ($agent_info["monitor_unknown"] > 0)
$data[5] .= ' : <span class="grey">' . $agent_info["monitor_unknown"] . '</span>';
if ($agent_info["monitor_normal"] > 0)
$data[5] .= ' : <span class="green">' . $agent_info["monitor_normal"] . '</span>';
if ($agent["fired_count"] > 0)
$data[5] .= ' : <span class="orange">' . $agent["fired_count"] . '</span>';
if ($agent["critical_count"] > 0)
$data[5] .= ' : <span class="red">' . $agent["critical_count"] . '</span>';
if ($agent["warning_count"] > 0)
$data[5] .= ' : <span class="yellow">' . $agent["warning_count"] . '</span>';
if ($agent["unknown_count"] > 0)
$data[5] .= ' : <span class="grey">' . $agent["unknown_count"] . '</span>';
if ($agent["normal_count"] > 0)
$data[5] .= ' : <span class="green">' . $agent["normal_count"] . '</span>';
$data[5] .= '</b>';
$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"]);

View File

@ -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 '<div style="height: 10px">&nbsp;</div>';
//Floating div
echo '<div id="agent_access" style="float:right; width:320px; padding-top:10px;">';
$params = array();
$params['position'] = 'right';
$params['icon_closed'] = 'images/setup.png';
$params['body_text'] = '';
if ($config["agentaccess"]) {
echo '<b>'.__('Agent access rate (24h)').'</b><br />';
$params['body_text'] .= '<b>'.__('Agent access rate (24h)').'</b><br />';
graphic_agentaccess($id_agente, 280, 110, 86400);
$params['body_text'] .= graphic_agentaccess($id_agente, 350, 110, 86400, true);
}
echo '<div style="height:25px">&nbsp;</div>';
echo '<b>'.__('Events generated -by module-').'</b><br />';
echo graph_event_module (290, 120, $id_agente);
echo '<br>';
graph_graphic_agentevents ($id_agente, 290, 15, 86400, '');
$params['body_text'] .= '<div style="height:25px">&nbsp;</div>';
$params['body_text'] .= '<b>'.__('Events generated -by module-').'</b><br />';
$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 '</div>';
echo '<div width="450px">';
echo '<table cellspacing="4" cellpadding="4" border="0" class="databox" style="width:53%">';
echo '<table cellspacing="4" cellpadding="4" border="0" class="databox" style="width:98%">';
//Agent name
echo '<tr><td class="datos"><b>'.__('Agent name').'</b></td>';
if ($agent['disabled']) {
@ -90,6 +95,13 @@ echo '<td class="datos"><b>'.$cellName.'</b></td>';
echo '<td class="datos" width="40"><a href="index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;id_agente='.$id_agente.'&amp;refr=60">' . html_print_image("images/refresh.png", true, array("border" => '0', "title" => __('Refresh data'), "alt" => "")) . '</a>&nbsp;';
echo '<a href="index.php?sec=estado&amp;sec2=operation/agentes/ver_agente&amp;flag_agent=1&amp;id_agente='.$id_agente.'">' . html_print_image("images/target.png", true, array("border" => '0', "title" => __('Force'), "alt" => "")) . '</a></td></tr>';
// Status
$status_img = agents_tree_view_status_img ($agent["critical_count"],
$agent["warning_count"], $agent["unknown_count"]);
echo '<tr><td class="datos"><b>' . __('Status') . '</b></td>';
echo '<td class="datos f9" colspan="2">' . $status_img . '</td></tr>';
//Addresses
echo '<tr><td class="datos2"><b>'.__('IP Address').'</b></td>';
echo '<td class="datos2" colspan="2">';
@ -202,6 +214,12 @@ $progress = agents_get_next_contact($id_agente);
echo '<tr><td class="datos"><b>' . __('Next agent contact') . '</b></td>';
echo '<td class="datos f9" colspan="2">' . progress_bar($progress, 200, 20) . '</td></tr>';
echo '<tr><td class="datos"><b>' . __('Events') . '</b></td>';
echo '<td class="datos f9" colspan="2">' . graph_graphic_agentevents ($id_agente, 290, 15, 86400, '', true) . '</td></tr>';
echo '<tr><td class="datos"><b>' . __('Modules status') . '</b></td>';
echo '<td class="datos f9" colspan="2">' . graph_agent_status ($id_agente, 100, 100, true) . '</td></tr>';
// Custom fields
$fields = db_get_all_rows_filter('tagent_custom_fields', array('display_on_front' => 1));
if ($fields === false) {