Merge branch 'ent-9958-Nueva-macro-alerta-para-mandar-imagenes-de-modulos-del-mismo-agente-que-dispara-la-alerta-modulegraph-X-nh' into 'develop'

Ent 9958 nueva macro alerta para mandar imagenes de modulos del mismo agente que dispara la alerta modulegraph x nh

See merge request artica/pandorafms!5652
This commit is contained in:
Rafael Ameijeiras 2023-05-31 11:15:36 +00:00
commit f59fcb580c
1 changed files with 11 additions and 4 deletions

View File

@ -1543,8 +1543,9 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
# 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_regexp = "_modulegraph_(?!([\\w\\s-]+_\\d+h_))(\\d+)h_";
my $macro_regexp2 = "_modulegraphth_(\\d+)h_";
my $macro_regexp3 = "_modulegraph_([\\w\\s-]+)_(\\d+)h_";
# API connection
my $ua = new LWP::UserAgent;
@ -1570,6 +1571,7 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
my $subst_func = sub {
my $hours = shift;
my $threshold = shift;
my $module = shift if @_;
my $period = $hours * 3600; # Hours to seconds
if($threshold == 0){
$params->{"other"} = $period . '%7C1%7C0%7C225%7C%7C14';
@ -1580,8 +1582,12 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
$cid = 'module_graphth_' . $hours . 'h';
}
if (defined($module)) {
$params->{"id"} = get_agent_module_id($dbh, $module, $agent->{'id_agente'});
}
$params->{"other_mode"} = 'url_encode_separator_%7C';
if (! exists($module_graph_list->{$cid}) && defined $url) {
# Get the module graph image in base 64
my $response = $ua->post($url, $params);
@ -1600,10 +1606,11 @@ sub pandora_execute_action ($$$$$$$$$;$$) {
eval {
no warnings;
local $SIG{__DIE__};
$field3 =~ s/$macro_regexp/$subst_func->($1, 0)/ige;
$field3 =~ s/$macro_regexp/$subst_func->($2, 0)/ige;
$field3 =~ s/$macro_regexp2/$subst_func->($1, 1)/ige;
$field3 =~ s/$macro_regexp3/$subst_func->($2, 0, $1)/ige;
};
# Default content type
my $content_type = $field4 . '; charset="iso-8859-1"';