diff --git a/pandora_console/include/functions_api.php b/pandora_console/include/functions_api.php
index bba8cb1cc3..5ecac3a944 100644
--- a/pandora_console/include/functions_api.php
+++ b/pandora_console/include/functions_api.php
@@ -9941,7 +9941,14 @@ function api_get_module_graph($id_module, $thrash2, $other, $thrash4) {
$other['data'][0]
:
SECONDS_1HOUR; // 1 hour by default
-
+
+ $graph_threshold =
+ (!empty($other) && isset($other['data'][2]))
+ ?
+ $other['data'][2]
+ :
+ 0;
+
if (is_nan($graph_seconds) || $graph_seconds <= 0) {
// returnError('error_module_graph', __(''));
return;
@@ -9952,41 +9959,44 @@ function api_get_module_graph($id_module, $thrash2, $other, $thrash4) {
$id_module, $graph_seconds, false, 600, 300, '',
'', false, false, true, time(), '', 0, 0, true, true,
ui_get_full_url(false) . '/', 1, false, '', false, true,
- true, 'white', null, false, false, $config['type_module_charts']);
+ true, 'white', null, false, false, $config['type_module_charts'],
+ false, false);
- $graph_image_file_encoded = false;
+ $graph_image_file_encoded = false;
if (preg_match("/ 200,
- "GridG" => 200,
- "GridB" => 200,
- "GridAlpha" => 30,
- "DrawSubTicks" => true,
- "CycleBackground" => true,
- "BackgroundAlpha1" => 35,
- "BackgroundAlpha2" => 35,
- "Mode" => $mode,
- "ManualScale" => $ManualScale,
- "LabelRotation" => 40,
- "XMargin" => 0,
- "MinDivHeight" => 15,
- "TicksFontSize" => $font_size - 1);
-
- $scaleSettings['AxisR'] = '200';
- $scaleSettings['AxisG'] = '200';
- $scaleSettings['AxisB'] = '200';
- $scaleSettings['TickR'] = '200';
- $scaleSettings['TickG'] = '200';
- $scaleSettings['TickB'] = '200';
-
- $myPicture->drawScale($scaleSettings);
-
+ if($graph_threshold){
+ $sql_treshold = 'select min_critical, max_critical, min_warning, max_warning, critical_inverse, warning_inverse from tagente_modulo where id_agente_modulo =' . $id_module;
+ $treshold_position = db_get_all_rows_sql($sql_treshold);
+
+ //min, max and inverse critical and warning
+ $p_min_crit = $treshold_position[0]['min_critical'];
+ $p_max_crit = $treshold_position[0]['max_critical'];
+ $p_inv_crit = $treshold_position[0]['critical_inverse'];
+ $p_min_warn = $treshold_position[0]['min_warning'];
+ $p_max_warn = $treshold_position[0]['max_warning'];
+ $p_inv_warn = $treshold_position[0]['warning_inverse'];
+
+ //interval warning
+ $print_rectangle_warning = 1;
+ if($p_min_warn == "0.00" && $p_max_warn == "0.00" && $p_inv_warn == 0){
+ $print_rectangle_warning = 0;
+ }
+ if($print_rectangle_warning){
+ if($p_inv_warn){
+ if($p_max_warn == 0){
+ $p_max_warn = $p_min_warn;
+ $p_min_warn = "none";
+ }
+ else{
+ $p_max_warn_inv = $p_min_warn;
+ $p_min_warn_inv = $min_data + 2;
+
+ $p_min_warn = $p_max_warn;
+ if($p_max_warn > $max_data){
+ $p_max_warn = $p_max_warn + 21;
+ }
+ else{
+ $p_max_warn = $max_data + 21;
+ }
+ }
+ }
+ else{
+ if($p_max_warn == 0){
+ if($max_data > $p_min_warn){
+ $p_max_warn = $max_data + 21;
+ }
+ else{
+ $p_max_warn = $p_min_warn + 21;
+ }
+ }
+ }
+ }
+
+ //interval critical
+ $print_rectangle_critical = 1;
+ if($p_min_crit == "0.00" && $p_max_crit == "0.00" && $p_inv_crit == 0){
+ $print_rectangle_critical = 0;
+ }
+
+ if($print_rectangle_critical){
+ if($p_inv_crit){
+ if($p_max_crit == 0){
+ $p_max_crit = $p_min_crit;
+ $p_min_crit = "none";
+ }
+ else{
+ $p_max_crit_inv = $p_min_crit;
+ $p_min_crit_inv = $min_data + 2;
+
+ $p_min_crit = $p_max_crit;
+ if($p_inv_warn){
+ if($p_max_crit < $p_max_warn){
+ $p_max_crit = $p_max_warn;
+ }
+ }
+ else{
+ if($p_max_crit > $max_data){
+ $p_max_crit = $p_max_crit + 21;
+ }
+ else{
+ $p_max_crit = $max_data + 21;
+ }
+ }
+ }
+ }
+ else{
+ if($p_max_crit == 0){
+ if($p_max_warn > $p_min_crit){
+ $p_max_crit = $p_max_warn;
+ }
+ else{
+ if($max_data > $p_min_crit){
+ $p_max_crit = $max_data + 21;
+ }
+ else{
+ $p_max_crit = $p_min_crit + 21;
+ }
+ }
+ }
+ }
+ }
+
+ //Check size scale
+ //Which of the thresholds is higher?
+ if($p_max_crit > $p_max_warn){
+ $check_scale = $p_max_crit;
+ }
+ else{
+ $check_scale = $p_max_warn;
+ }
+
+ if($p_min_crit < $p_min_warn){
+ $check_scale_min = $p_min_crit;
+ }
+ else{
+ $check_scale_min = $p_min_warn;
+ }
+
+ //Is the threshold higher than our maximum?
+ if($max_data > $check_scale){
+ $check_scale = $max_data;
+ }
+
+ if($min_data < $check_scale_min){
+ $check_scale_min = $min_data;
+ }
+
+ $ManualScale = array( 0 => array("Min" => $check_scale_min, "Max" => $check_scale) );
+ $mode = SCALE_MODE_MANUAL;
+
+ /* Draw the scale */
+ $scaleSettings = array(
+ "GridR" => 200,
+ "GridG" => 200,
+ "GridB" => 200,
+ "GridAlpha" => 30,
+ "DrawSubTicks" => true,
+ "CycleBackground" => true,
+ "BackgroundAlpha1" => 35,
+ "BackgroundAlpha2" => 35,
+ "Mode" => $mode,
+ "ManualScale" => $ManualScale,
+ "LabelRotation" => 40,
+ "XMargin" => 0,
+ "MinDivHeight" => 15,
+ "TicksFontSize" => $font_size - 1);
+
+ $scaleSettings['AxisR'] = '200';
+ $scaleSettings['AxisG'] = '200';
+ $scaleSettings['AxisB'] = '200';
+ $scaleSettings['TickR'] = '200';
+ $scaleSettings['TickG'] = '200';
+ $scaleSettings['TickB'] = '200';
+
+ $myPicture->drawScale($scaleSettings);
+
+
+ //values
+ $scale_max = $myPicture->DataSet->Data["Axis"][0]["ScaleMax"];
+ $scale_min = $myPicture->DataSet->Data["Axis"][0]["ScaleMin"];
+
+ $position_y1 = $myPicture->GraphAreaY1;
+ $position_y2 = $myPicture->GraphAreaY2;
+
+ $position1 = $myPicture->GraphAreaX1;
+ $position3 = $myPicture->GraphAreaX2;
+
+ $cte = ($position_y2 - $position_y1) / ($scale_max - $scale_min);
+
+ //warning
+ if($print_rectangle_warning){
+ $RectangleSettings = array("R"=>255,"G"=>255,"B"=>000,"Dash"=>TRUE,"DashR"=>170,"DashG"=>220,"DashB"=>190);
+ if($p_min_warn == "none"){
+ $p_min_warn = $scale_min;
+ }
+
+ $position2 = ($scale_max - $p_min_warn)*$cte + $position_y1;
+ $position4 = ($scale_max - $p_max_warn)*$cte + $position_y1;
+
+ $myPicture->drawFilledRectangle($position1, floor($position2),
+ $position3, floor($position4),
+ $RectangleSettings);
+ if($p_inv_warn){
+ $position2 = ($scale_max - $p_min_warn_inv)*$cte + $position_y1;
+ $position4 = ($scale_max - $p_max_warn_inv)*$cte + $position_y1;
+ $myPicture->drawFilledRectangle($position1, floor($position2),
+ $position3, floor($position4),
+ $RectangleSettings);
+ }
+ }
+
+ //critical
+ if($print_rectangle_critical){
+ $RectangleSettings = array("R"=>248,"G"=>000,"B"=>000,"Dash"=>TRUE,"DashR"=>170,"DashG"=>220,"DashB"=>190);
+
+ if($p_min_crit == "none"){
+ $p_min_crit = $scale_min;
+ }
+
+ $position2 = ($scale_max - $p_min_crit)*$cte + $position_y1;
+ $position4 = ($scale_max - $p_max_crit)*$cte + $position_y1;
+ $myPicture->drawFilledRectangle($position1, $position2,
+ $position3, $position4,
+ $RectangleSettings);
+
+ if($p_inv_crit){
+ $position2 = ($scale_max - $p_min_crit_inv)*$cte + $position_y1;
+ $position4 = ($scale_max - $p_max_crit_inv)*$cte + $position_y1;
+ $myPicture->drawFilledRectangle($position1, $position2,
+ $position3, $position4,
+ $RectangleSettings);
+ }
+ }
+
+ }
+ else{
+ /* Draw the scale */
+ $scaleSettings = array(
+ "GridR" => 200,
+ "GridG" => 200,
+ "GridB" => 200,
+ "GridAlpha" => 30,
+ "DrawSubTicks" => true,
+ "CycleBackground" => true,
+ "BackgroundAlpha1" => 35,
+ "BackgroundAlpha2" => 35,
+ "Mode" => $mode,
+ "ManualScale" => $ManualScale,
+ "LabelRotation" => 40,
+ "XMargin" => 0,
+ "MinDivHeight" => 15,
+ "TicksFontSize" => $font_size - 1);
+
+ $scaleSettings['AxisR'] = '200';
+ $scaleSettings['AxisG'] = '200';
+ $scaleSettings['AxisB'] = '200';
+ $scaleSettings['TickR'] = '200';
+ $scaleSettings['TickG'] = '200';
+ $scaleSettings['TickB'] = '200';
+
+ $myPicture->drawScale($scaleSettings);
+ }
+
/* Turn on shadow computing */
//$myPicture->setShadow(TRUE,array("X"=>0,"Y"=>1,"R"=>0,"G"=>0,"B"=>0,"Alpha"=>10));
@@ -1087,7 +1304,6 @@ function pch_vertical_graph ($graph_type, $index, $data, $width, $height,
}
}
-
/* Render the picture */
$myPicture->stroke();
}
diff --git a/pandora_console/include/help/en/help_alert_config.php b/pandora_console/include/help/en/help_alert_config.php
index 6fcd868841..a0262a6c5f 100644
--- a/pandora_console/include/help/en/help_alert_config.php
+++ b/pandora_console/include/help/en/help_alert_config.php
@@ -64,6 +64,7 @@ Apart from the defined module macros, the following macros are also available:
diff --git a/pandora_console/include/help/en/help_alert_macros.php b/pandora_console/include/help/en/help_alert_macros.php index 43a0738f94..b96476a59d 100644 --- a/pandora_console/include/help/en/help_alert_macros.php +++ b/pandora_console/include/help/en/help_alert_macros.php @@ -67,6 +67,7 @@ Besides the defined module macros, the following macros are available: Returns an image encoded in base64 of a module’s graph with a period of n hours (eg. _modulegraph_24h_). A correct setup of the connection between the server and the console's API is required. This setup is done on the server's configuration file. +
diff --git a/pandora_console/include/help/es/help_alert_config.php b/pandora_console/include/help/es/help_alert_config.php index 1353021b9e..001d21e2f2 100644 --- a/pandora_console/include/help/es/help_alert_config.php +++ b/pandora_console/include/help/es/help_alert_config.php @@ -65,7 +65,8 @@ Además de las macros de módulo definidas, las siguientes macros están disponi
diff --git a/pandora_console/include/help/es/help_alert_macros.php b/pandora_console/include/help/es/help_alert_macros.php index bbffe76b03..2f1519bd8d 100644 --- a/pandora_console/include/help/es/help_alert_macros.php +++ b/pandora_console/include/help/es/help_alert_macros.php @@ -67,6 +67,7 @@ Además de las macros de módulo definidas, las siguientes macros están disponi Devuelve una imagen codificada en base64 de una gráfica del módulo con un período de n horas (eg. _modulegraph_24h_). Requiere de una configuración correcta de la conexión del servidor a la consola vía api, la cual se realiza en el fichero de configuración del servidor. +
diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 319fef0bab..5bd389a46b 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1095,9 +1095,10 @@ sub pandora_execute_action ($$$$$$$$$;$) { # Message $field3 = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module); - # Check for _module_graph_Xh_ macros + # Check for _module_graph_Xh_ macros and _module_graphth_Xh_ my $module_graph_list = {}; my $macro_regexp = "_modulegraph_(\\d+)h_"; + my $macro_regexp2 = "_modulegraphth_(\\d+)h_"; # API connection my $ua = new LWP::UserAgent; @@ -1113,8 +1114,14 @@ sub pandora_execute_action ($$$$$$$$$;$) { my $subst_func = sub { my $hours = shift; + my $threshold = shift; my $period = $hours * 3600; # Hours to seconds - $params->{"other"} = $period . '%7C0'; + if($threshold == 0){ + $params->{"other"} = $period . '%7C0%7C0'; + } + else{ + $params->{"other"} = $period . '%7C0%7C1'; + } $params->{"other_mode"} = 'url_encode_separator_%7C'; my $cid = 'module_graph_' . $hours . 'h'; @@ -1136,7 +1143,8 @@ sub pandora_execute_action ($$$$$$$$$;$) { eval { no warnings; local $SIG{__DIE__}; - $field3 =~ s/$macro_regexp/$subst_func->($1)/ige; + $field3 =~ s/$macro_regexp/$subst_func->($1, 0)/ige; + $field3 =~ s/$macro_regexp2/$subst_func->($1, 1)/ige; }; # Default content type