Skip to content

Commit

Permalink
peers: add support for tagging
Browse files Browse the repository at this point in the history
  • Loading branch information
sni committed Oct 2, 2024
1 parent 24fe273 commit fee8c7c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
39 changes: 38 additions & 1 deletion lib/Thruk/Backend/Manager.pm
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,44 @@ sub get_peers {

for my $b (@{$self->pool->{'objects'}}) {
next if(defined $b->{'active'} && !$b->{'active'} && !$inactive_too);
next if(!$b->{'addr'} && !$all);
next if(!$b->{'addr'} && !$all); # config-only don't have an address
next unless $b->{'tags'}->{'live'};
push @peers, $b;
}
return \@peers;
}

##########################################################

=head2 get_peers_by_tags
get_peers_by_tags($tags)
returns all configured peers with given tags, ex: [ 'tag1', '!tag2' ]
=cut

sub get_peers_by_tags {
my($self, $tags) = @_;
my @peers;

for my $b (@{$self->pool->{'objects'}}) {
next if(defined $b->{'active'} && !$b->{'active'});

my $found = 0;
for my $t (@{$tags}) {
if($t =~ m/^\!(.*)$/mx) {
my $t = $1;
if($b->{'tags'}->{$t}) {
$found = 0;
last;
}
} elsif($b->{'tags'}->{$t}) {
$found = 1;
}
};

next unless $found;
push @peers, $b;
}
return \@peers;
Expand Down
2 changes: 2 additions & 0 deletions lib/Thruk/Backend/Peer.pm
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ sub _initialise_peer {
$self->{'last_error'} = undef;
$self->{'logcache'} = undef;
$self->{'authoritive'} = $peer_config->{'authoritive'};
$self->{'tags'} = Thruk::Base::array2hash(Thruk::Base::comma_separated_list($peer_config->{'tags'}));
$self->{'tags'}->{'live'} = 'live' unless scalar keys %{$self->{'tags'}} > 0;

# shorten backend id
my $key = $peer_config->{'id'};
Expand Down

0 comments on commit fee8c7c

Please sign in to comment.