From 0c57d35f53ae39aa43fe9d4e550c29ff3f4dfa76 Mon Sep 17 00:00:00 2001 From: Arturo Gonzalez Date: Mon, 5 Jun 2017 17:48:37 +0200 Subject: [PATCH] Added a first version to multi origin macros feature. --- pandora_server/lib/PandoraFMS/Core.pm | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index 03ff320add..bfca52f510 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -1019,7 +1019,8 @@ sub pandora_execute_action ($$$$$$$$$;$) { _phone_tag_ => undef, _name_tag_ => undef, _all_address_ => undef, - '_address_\d+_' => undef, + '_address_\d+_' => undef, + '_data_module_\S+_ ' => undef, ); if ((defined ($extra_macros)) && (ref($extra_macros) eq "HASH")) { @@ -3637,6 +3638,28 @@ sub on_demand_macro($$$$$$) { $field_value = 'Ip not defined'; } + return(defined($field_value)) ? $field_value : ''; + } elsif ($macro =~ /_data_module_(\S+)_/) { + my $field_number = $1; + + my @rows = get_db_rows ($dbh, 'SELECT alias FROM tagente WHERE id_agente = (SELECT id_agente FROM tagente_modulo WHERE nombre = ?)', $field_number); + + use Data::Dumper; + $Data::Dumper::Sortkeys = 1; + + my $field_value = ''; + foreach my $row (@rows) { + my $agent_name = $row->{'alias'}; + + if ($agent_name ne "") { + $field_value .= "Agent " . $agent_name . " - Module " . $field_number; + } + } + + if($field_value eq ''){ + $field_value = 'Module ' . $field_number . " not found"; + } + return(defined($field_value)) ? $field_value : ''; } }