fixed errors in new macro graph treshold

This commit is contained in:
daniel 2017-09-08 13:55:03 +02:00
parent 2689213fdf
commit 8a7b0a0f79
2 changed files with 49 additions and 28 deletions

View File

@ -9942,6 +9942,13 @@ function api_get_module_graph($id_module, $thrash2, $other, $thrash4) {
: :
SECONDS_1HOUR; // 1 hour by default 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) { if (is_nan($graph_seconds) || $graph_seconds <= 0) {
// returnError('error_module_graph', __('')); // returnError('error_module_graph', __(''));
return; return;
@ -9952,7 +9959,8 @@ function api_get_module_graph($id_module, $thrash2, $other, $thrash4) {
$id_module, $graph_seconds, false, 600, 300, '', $id_module, $graph_seconds, false, 600, 300, '',
'', false, false, true, time(), '', 0, 0, true, true, '', false, false, true, time(), '', 0, 0, true, true,
ui_get_full_url(false) . '/', 1, false, '', false, 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("/<img src='(.+)'./", $graph_html, $matches)) { if (preg_match("/<img src='(.+)'./", $graph_html, $matches)) {
@ -9987,6 +9995,8 @@ function api_get_module_graph($id_module, $thrash2, $other, $thrash4) {
$_GET["id_graph"] = $id_graph; $_GET["id_graph"] = $id_graph;
$_GET["graph_type"] = $graph_type; $_GET["graph_type"] = $graph_type;
$_GET["static_graph"] = $static_graph; $_GET["static_graph"] = $static_graph;
$_GET["graph_threshold"] = $graph_threshold;
$_GET["id_module"] = $id_module;
} }
ob_start(); ob_start();

View File

@ -1110,8 +1110,10 @@ sub pandora_execute_action ($$$$$$$$$;$) {
$field3 = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module); $field3 = subst_alert_macros ($field3, \%macros, $pa_config, $dbh, $agent, $module);
# Check for _module_graph_Xh_ macros # Check for _module_graph_Xh_ macros
# Check for _module_graph_Xh_ macros and _module_graphth_Xh_
my $module_graph_list = {}; my $module_graph_list = {};
my $macro_regexp = "_modulegraph_(\\d+)h_"; my $macro_regexp = "_modulegraph_(\\d+)h_";
my $macro_regexp2 = "_modulegraphth_(\\d+)h_";
# API connection # API connection
my $ua = new LWP::UserAgent; my $ua = new LWP::UserAgent;
@ -1124,13 +1126,21 @@ sub pandora_execute_action ($$$$$$$$$;$) {
$params->{"op"} = "get"; $params->{"op"} = "get";
$params->{"op2"} = "module_graph"; $params->{"op2"} = "module_graph";
$params->{"id"} = $module->{'id_agente_modulo'}; $params->{"id"} = $module->{'id_agente_modulo'};
my $cid ='';
my $subst_func = sub { my $subst_func = sub {
my $hours = shift; my $hours = shift;
my $threshold = shift;
my $period = $hours * 3600; # Hours to seconds my $period = $hours * 3600; # Hours to seconds
$params->{"other"} = $period . '%7C0'; if($threshold == 0){
$params->{"other"} = $period . '%7C0%7C0';
$cid = 'module_graph_' . $hours . 'h';
}
else{
$params->{"other"} = $period . '%7C0%7C1';
$cid = 'module_graphth_' . $hours . 'h';
}
$params->{"other_mode"} = 'url_encode_separator_%7C'; $params->{"other_mode"} = 'url_encode_separator_%7C';
my $cid = 'module_graph_' . $hours . 'h';
if (! exists($module_graph_list->{$cid}) && defined $url) { if (! exists($module_graph_list->{$cid}) && defined $url) {
# Get the module graph image in base 64 # Get the module graph image in base 64
@ -1150,7 +1160,8 @@ sub pandora_execute_action ($$$$$$$$$;$) {
eval { eval {
no warnings; no warnings;
local $SIG{__DIE__}; 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 # Default content type