fixed errors in new macro graph treshold
This commit is contained in:
parent
2689213fdf
commit
8a7b0a0f79
|
@ -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("/<img src='(.+)'./", $graph_html, $matches)) {
|
||||
$file_url = $matches[1];
|
||||
|
||||
if (preg_match("/\?(.+)&(.+)&(.+)&(.+)/", $file_url,$parameters)) {
|
||||
array_shift ($parameters);
|
||||
foreach ($parameters as $parameter){
|
||||
$value = explode ("=",$parameter);
|
||||
if (preg_match("/\?(.+)&(.+)&(.+)&(.+)/", $file_url,$parameters)) {
|
||||
array_shift ($parameters);
|
||||
foreach ($parameters as $parameter){
|
||||
$value = explode ("=",$parameter);
|
||||
|
||||
if (strcmp($value[0], "static_graph") == 0){
|
||||
$static_graph = $value[1];
|
||||
}
|
||||
elseif (strcmp($value[0], "graph_type") == 0){
|
||||
$graph_type = $value[1];
|
||||
}
|
||||
elseif (strcmp($value[0], "ttl") == 0){
|
||||
$ttl = $value[1];
|
||||
}
|
||||
elseif (strcmp($value[0], "id_graph") == 0){
|
||||
$id_graph = $value[1];
|
||||
}
|
||||
}
|
||||
if (strcmp($value[0], "static_graph") == 0){
|
||||
$static_graph = $value[1];
|
||||
}
|
||||
elseif (strcmp($value[0], "graph_type") == 0){
|
||||
$graph_type = $value[1];
|
||||
}
|
||||
elseif (strcmp($value[0], "ttl") == 0){
|
||||
$ttl = $value[1];
|
||||
}
|
||||
elseif (strcmp($value[0], "id_graph") == 0){
|
||||
$id_graph = $value[1];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check values are OK
|
||||
if ( (isset ($graph_type))
|
||||
&& (isset ($ttl))
|
||||
&& (isset ($id_graph))) {
|
||||
$_GET["ttl"] = $ttl;
|
||||
$_GET["id_graph"] = $id_graph;
|
||||
$_GET["graph_type"] = $graph_type;
|
||||
$_GET["static_graph"] = $static_graph;
|
||||
$_GET["ttl"] = $ttl;
|
||||
$_GET["id_graph"] = $id_graph;
|
||||
$_GET["graph_type"] = $graph_type;
|
||||
$_GET["static_graph"] = $static_graph;
|
||||
$_GET["graph_threshold"] = $graph_threshold;
|
||||
$_GET["id_module"] = $id_module;
|
||||
}
|
||||
|
||||
ob_start();
|
||||
|
|
|
@ -1110,8 +1110,10 @@ sub pandora_execute_action ($$$$$$$$$;$) {
|
|||
$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;
|
||||
|
@ -1124,13 +1126,21 @@ sub pandora_execute_action ($$$$$$$$$;$) {
|
|||
$params->{"op"} = "get";
|
||||
$params->{"op2"} = "module_graph";
|
||||
$params->{"id"} = $module->{'id_agente_modulo'};
|
||||
|
||||
my $cid ='';
|
||||
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';
|
||||
$cid = 'module_graph_' . $hours . 'h';
|
||||
}
|
||||
else{
|
||||
$params->{"other"} = $period . '%7C0%7C1';
|
||||
$cid = 'module_graphth_' . $hours . 'h';
|
||||
}
|
||||
|
||||
$params->{"other_mode"} = 'url_encode_separator_%7C';
|
||||
my $cid = 'module_graph_' . $hours . 'h';
|
||||
|
||||
if (! exists($module_graph_list->{$cid}) && defined $url) {
|
||||
# Get the module graph image in base 64
|
||||
|
@ -1150,7 +1160,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
|
||||
|
|
Loading…
Reference in New Issue