From 5450c682a9b95cd72e3d2775e6552f14d65ff109 Mon Sep 17 00:00:00 2001 From: fbsanchez Date: Wed, 7 Mar 2018 16:56:35 +0100 Subject: [PATCH] Added get_agent as unified function It unifies: - get_agent_from_alias - get_agent_from_addr - get_agent_from_name --- pandora_server/lib/PandoraFMS/Core.pm | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/pandora_server/lib/PandoraFMS/Core.pm b/pandora_server/lib/PandoraFMS/Core.pm index d1bc237845..6cd70a7441 100644 --- a/pandora_server/lib/PandoraFMS/Core.pm +++ b/pandora_server/lib/PandoraFMS/Core.pm @@ -230,6 +230,7 @@ our @EXPORT = qw( pandora_self_monitoring pandora_process_policy_queue subst_alert_macros + get_agent get_agent_from_alias get_agent_from_addr get_agent_from_name @@ -254,6 +255,27 @@ our $EventStormProtection :shared = 0; # Current master server my $Master :shared = 0; + +########################################################################## +# Return the agent given the agent name or alias or address. +########################################################################## +sub get_agent { + my ($dbh, $field) = @_; + + return undef if (! defined ($field) || $field eq ''); + + my $rs = get_agent_from_alias($dbh, $field); + return $rs if defined($rs) && (ref($rs)); # defined and not a scalar + + my $rs = get_agent_from_addr($dbh, $field); + return $rs if defined($rs) && (ref($rs)); # defined and not a scalar + + my $rs = get_agent_from_name($dbh, $field); + return $rs if defined($rs) && (ref($rs)); # defined and not a scalar + + return undef; +} + ########################################################################## # Return the agent given the agent name. ##########################################################################