'; $output .= " "; if (!$return) echo $output; return $output; } } /////////////////////////////// ////////// AREA GRAPHS //////// /////////////////////////////// function flot_area_graph ( $agent_module_id, $array_data, $legend, $series_type, $color, $date_array, $data_module_graph, $params, $water_mark, $array_events_alerts ) { global $config; // include_javascript_dependencies_flot_graph(); // Get a unique identifier to graph $graph_id = uniqid('graph_'); $background_style = ''; switch ($params['backgroundColor']) { case 'white': $background_style = ' background: #fff; '; $params['grid_color'] = '#C1C1C1'; break; case 'black': $background_style = ' background: #000; '; $params['grid_color'] = '#BDBDBD'; break; case 'transparent': $background_style = ''; $params['grid_color'] = '#A4A4A4'; break; default: $background_style = 'background-color: ' . $params['backgroundColor']; $params['grid_color'] = '#C1C1C1'; break; } $padding_vconsole = $params['dashboard'] ? 'padding: 1px 0px 10px 10px;' : ''; // Parent layer $return = "
"; // Set some containers to legend, graph, timestamp tooltip, etc. if($params['show_legend']){ $return .= "

"; } if(isset($params['graph_combined']) && $params['graph_combined'] && (!isset($params['from_interface']) || !$params['from_interface']) ){ if( isset($params['threshold_data']) && is_array($params['threshold_data'])){ $yellow_threshold = $params['threshold_data']['yellow_threshold']; $red_threshold = $params['threshold_data']['red_threshold']; $yellow_up = $params['threshold_data']['yellow_up']; $red_up = $params['threshold_data']['red_up']; $yellow_inverse = $params['threshold_data']['yellow_inverse']; $red_inverse = $params['threshold_data']['red_inverse']; } else{ $yellow_up = 0; $red_up = 0; $yellow_inverse = false; $red_inverse = false; } } elseif(!isset($params['combined']) || !$params['combined']){ $yellow_threshold = $data_module_graph['w_min']; $red_threshold = $data_module_graph['c_min']; // Get other required module datas to draw warning and critical if ($agent_module_id == 0) { $yellow_up = 0; $red_up = 0; $yellow_inverse = false; $red_inverse = false; } else { $yellow_up = $data_module_graph['w_max']; $red_up = $data_module_graph['c_max']; $yellow_inverse = !($data_module_graph['w_inv'] == 0); $red_inverse = !($data_module_graph['c_inv'] == 0); } } elseif(isset($params['from_interface']) && $params['from_interface']){ if( isset($params['threshold_data']) && is_array($params['threshold_data'])){ $yellow_threshold = $params['threshold_data']['yellow_threshold']; $red_threshold = $params['threshold_data']['red_threshold']; $yellow_up = $params['threshold_data']['yellow_up']; $red_up = $params['threshold_data']['red_up']; $yellow_inverse = $params['threshold_data']['yellow_inverse']; $red_inverse = $params['threshold_data']['red_inverse']; } else{ $yellow_up = 0; $red_up = 0; $yellow_inverse = false; $red_inverse = false; } } else{ $yellow_up = 0; $red_up = 0; $yellow_inverse = false; $red_inverse = false; } if ($params['menu']) { $return .= menu_graph( $yellow_threshold, $red_threshold, $yellow_up, $red_up, $yellow_inverse, $red_inverse, $graph_id, $params ); } $return .= html_print_input_hidden('line_width_graph', $config['custom_graph_width'], true); $return .= "
"; $return .= "
"; if ($params['menu']) { $params['height'] = 100; } else { $params['height'] = 1; } if (!$vconsole){ $return .= "
"; } if ($water_mark != '') { $return .= ""; $watermark = 'true'; } else { $watermark = 'false'; } foreach($series_type as $k => $v){ $series_type_unique["data_" . $graph_id . "_" . $k] = $v; } // Store data series in javascript format $extra_width = (int)($params['width'] / 3); $return .= "
"; // Trick to get translated string from javascript $return .= html_print_input_hidden('unknown_text', __('Unknown'), true); $values = json_encode($array_data); $legend = json_encode($legend); $series_type = json_encode($series_type); $color = json_encode($color); $date_array = json_encode($date_array); $data_module_graph = json_encode($data_module_graph); $params = json_encode($params); $array_events_alerts = json_encode($array_events_alerts); // Javascript code if ($font_size == '') $font_size = '\'\''; $return .= ""; // Parent layer $return .= "
"; return $return; } function menu_graph( $yellow_threshold, $red_threshold, $yellow_up, $red_up, $yellow_inverse, $red_inverse, $graph_id, $params ){ $return = ''; $threshold = false; if ($yellow_threshold != $yellow_up || $red_threshold != $red_up) { $threshold = true; } if ( $params['dashboard'] == false AND $params['vconsole'] == false) { $return .= ""; } if ($params['dashboard']) { $return .= ""; } return $return; } /////////////////////////////// /////////////////////////////// /////////////////////////////// // Prints a FLOT pie chart function flot_pie_chart ($values, $labels, $width, $height, $water_mark, $font = '', $font_size = 8, $legend_position = '', $colors = '', $hide_labels = false) { // include_javascript_dependencies_flot_graph(); $series = sizeof($values); if (($series != sizeof ($labels)) || ($series == 0) ) { return; } $graph_id = uniqid('graph_'); switch ($legend_position) { case 'bottom': $height = $height + (count($values) * 24); break; case 'right': default: //TODO FOR TOP OR LEFT OR RIGHT break; } $return = "
"; if ($water_mark != '') { $return .= ""; $water_mark = 'true'; } else { $water_mark = 'false'; } $separator = ';;::;;'; $labels = implode($separator, $labels); $values = implode($separator, $values); if (!empty($colors)) { $colors = implode($separator, $colors); } $return .= ""; return $return; } // Prints a FLOT pie chart function flot_custom_pie_chart ($flash_charts, $graph_values, $width, $height, $colors, $module_name_list, $long_index, $no_data,$xaxisname, $yaxisname, $water_mark, $fontpath, $font_size, $unit, $ttl, $homeurl, $background_color, $legend_position) { global $config; ///TODO // include_javascript_dependencies_flot_graph(); $total_modules = $graph_values['total_modules']; unset($graph_values['total_modules']); foreach ($graph_values as $label => $value) { if ($value['value']) { if ($value['value'] > 1000000) $legendvalue = sprintf("%sM", remove_right_zeros(number_format($value['value'] / 1000000, $config['graph_precision']))); else if ($value['value'] > 1000) $legendvalue = sprintf("%sK", remove_right_zeros(number_format($value['value'] / 1000, $config['graph_precision']))); else $legendvalue = remove_right_zeros(number_format($value['value'], $config['graph_precision'])); } else $legendvalue = __('No data'); $values[] = $value['value']; $legend[] = $label .": " . $legendvalue . " " .$value['unit']; $labels[] = $label; } $graph_id = uniqid('graph_'); $return = "
"; if ($water_mark != '') { $return .= ""; $water_mark = 'true'; } else { $water_mark = 'false'; } $separator = ';;::;;'; $labels = implode($separator, $labels); $legend = implode($separator, $legend); $values = implode($separator, $values); if (!empty($colors)) { foreach ($colors as $color) { $temp_colors[] = $color['color']; } } $colors = implode($separator, $temp_colors); $return .= ""; return $return; } // Returns a 3D column chart function flot_hcolumn_chart ($graph_data, $width, $height, $water_mark, $font = '', $font_size = 7, $background_color = "white", $tick_color = "white", $val_min=null, $val_max=null) { global $config; // include_javascript_dependencies_flot_graph(); $return = ''; $stacked_str = ''; $multicolor = true; // Get a unique identifier to graph $graph_id = uniqid('graph_'); $graph_id2 = uniqid('graph_'); // Set some containers to legend, graph, timestamp tooltip, etc. $return .= "
"; $return .= ""; if ($water_mark != '') { $return .= ""; $watermark = 'true'; } else { $watermark = 'false'; } // Set a weird separator to serialize and unserialize passing data // from php to javascript $separator = ';;::;;'; $separator2 = ':,:,,,:,:'; // Transform data from our format to library format $labels = array(); $a = array(); $vars = array(); $max = PHP_INT_MIN+1; $min = PHP_INT_MAX-1; $i = count($graph_data); $data = array(); foreach ($graph_data as $label => $values) { $labels[] = io_safe_output($label); $i--; foreach ($values as $key => $value) { $jsvar = "data_" . $graph_id . "_" . $key; $data[$jsvar][] = $value; if ($value > $max) { $max = $value; } if ($value < $min) { $min = $value; } } } if (!is_numeric($val_min)) { $val_min = $min; } if (!is_numeric($val_max)) { $val_max = $max; } // Store serialized data to use it from javascript $labels = implode($separator,$labels); // Store data series in javascript format $jsvars = ''; $jsseries = array(); $i = 0; $values2 = array(); foreach ($data as $jsvar => $values) { $values2[] = implode($separator,$values); } $values = implode($separator2, $values2); $jsseries = implode(',', $jsseries); // Javascript code $return .= ""; return $return; } // Returns a 3D column chart function flot_vcolumn_chart ($graph_data, $width, $height, $color, $legend, $long_index, $homeurl, $unit, $water_mark, $homedir, $font, $font_size, $from_ux, $from_wux, $background_color = 'white', $tick_color = 'white') { global $config; // include_javascript_dependencies_flot_graph(); $stacked_str = ''; $multicolor = false; // Get a unique identifier to graph $graph_id = uniqid('graph_'); $graph_id2 = uniqid('graph_'); if ($width != 'auto') { $width = $width . "px"; } // Set some containers to legend, graph, timestamp tooltip, etc. $return .= "
"; $return .= ""; if ($water_mark != '') { $return .= ""; $watermark = 'true'; } else { $watermark = 'false'; } $colors = array_map(function ($elem) { return $elem['color'] ? $elem['color'] : null; }, $color); // Set a weird separator to serialize and unserialize passing data from php to javascript $separator = ';;::;;'; $separator2 = ':,:,,,:,:'; // Transform data from our format to library format $labels = array(); $a = array(); $vars = array(); $max = 0; $i = count($graph_data); foreach ($graph_data as $label => $values) { $labels[] = $label; $i--; foreach ($values as $key => $value) { $jsvar = "data_" . $graph_id . "_" . $key; $data[$jsvar][] = $value; if ($value > $max) { $max = $value; } } } // Store serialized data to use it from javascript $labels = implode($separator,$labels); $colors = implode($separator, $colors); // Store data series in javascript format $jsvars = ''; $jsseries = array(); $i = 0; $values2 = array(); foreach ($data as $jsvar => $values) { $values2[] = implode($separator,$values); } $values = implode($separator2, $values2); $jsseries = implode(',', $jsseries); // Javascript code $return .= ""; return $return; } function flot_slicesbar_graph ($graph_data, $period, $width, $height, $legend, $colors, $fontpath, $round_corner, $homeurl, $watermark = '', $adapt_key = '', $stat_win = false, $id_agent = 0, $full_legend_date = array()) { global $config; // include_javascript_dependencies_flot_graph(); $stacked_str = 'stack: stack,'; // Get a unique identifier to graph $graph_id = uniqid('graph_'); // Set some containers to legend, graph, timestamp tooltip, etc. if ($stat_win) { $return = "
"; } else { $return = "
"; } $return .= ""; // Set a weird separator to serialize and unserialize passing data from php to javascript $separator = ';;::;;'; $separator2 = ':,:,,,:,:'; // Transform data from our format to library format $labels = array(); $a = array(); $vars = array(); $datacolor = array(); $max = 0; $i = count($graph_data); $intervaltick = $period / $i; $leg_max_length = 0; foreach ($legend as $l) { if (strlen($l) > $leg_max_length) { $leg_max_length = strlen($l); } } $fontsize = 7; $extra_height = 15; if (defined("METACONSOLE")) $extra_height = 20; $return .= ""; $maxticks = (int) ($width / ($fontsize * $leg_max_length)); $i_aux = $i; while(1) { if ($i_aux <= $maxticks ) { break; } $intervaltick*= 2; $i_aux /= 2; } $intervaltick = (int) $intervaltick; $acumulate = 0; $c = 0; $acumulate_data = array(); foreach ($graph_data as $label => $values) { $labels[] = $label; $i--; foreach ($values as $key => $value) { $jsvar = "d_".$graph_id."_".$i; if ($key == 'data') { $datacolor[$jsvar] = $colors[$value]; continue; } $data[$jsvar][] = $value; $acumulate_data[$c] = $acumulate; $acumulate += $value; $c++; if ($value > $max) { $max = $value; } } } // Store serialized data to use it from javascript $labels = implode($separator,$labels); $datacolor = implode($separator,$datacolor); $legend = io_safe_output(implode($separator,$legend)); if (!empty($full_legend_date)) { $full_legend_date = io_safe_output(implode($separator,$full_legend_date)); } else { $full_legend_date = false; } $acumulate_data = io_safe_output(implode($separator,$acumulate_data)); // Store data series in javascript format $jsvars = ''; $jsseries = array(); $date = get_system_time (); $datelimit = ($date - $period) * 1000; $i = 0; $values2 = array(); foreach ($data as $jsvar => $values) { $values2[] = implode($separator,$values); $i ++; } $values = implode($separator2, $values2); // Javascript code $return .= ""; return $return; } ?>