Skip to content

Instantly share code, notes, and snippets.

@mattdees
Last active December 28, 2015 04:38
Show Gist options
  • Save mattdees/7443499 to your computer and use it in GitHub Desktop.
Save mattdees/7443499 to your computer and use it in GitHub Desktop.
sub _load_targets {
my @targets;
Smokeping::load_cfg($config_file, 1);
# get each server's info.
foreach my $group ( keys %{ $Smokeping::cfg->{'Targets'} } ) {
unless ( ref $Smokeping::cfg->{'Targets'}->{$group} ) {
# Unless the entry in the smokeping hash is a reference to another datastructure
next;
}
my $group_hr = $Smokeping::cfg->{'Targets'}->{$group};
foreach my $server ( keys %{ $group_hr } ) {
unless ( ref $group_hr->{$server} && ref $group_hr->{$server} eq 'HASH' ) {
# Unless the entry in the smokeping hash is a reference to another datastructure
next;
}
# set target to Group.Name, like in the UI
my $target = "${group}.${server}";
if ( !exists $group_hr->{$server}->{'host'} ) {
# this is actually just another level deeper of config
# This is for entries that are +++ headed, if we need another level, we'll make this recursive
foreach my $third_level ( keys %{ $group_hr->{$server} } ) {
next if ref $group_hr->{$server}->{$third_level} ne 'HASH';
next if !exists $group_hr->{$server}->{$third_level}->{'host'};
my $host = $group_hr->{$server}->{$third_level}->{'host'};
push @targets, { 'target' => "${target}.${third_level}", 'host' => $host };
}
}
else {
my $host = $group_hr->{$server}->{host};
push @targets, { 'target' => $target, 'host' => $host };
}
}
}
return @targets;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment