diff --git a/plugins/plugins-available/conf/lib/Monitoring/Config.pm b/plugins/plugins-available/conf/lib/Monitoring/Config.pm index 62df3bf3ce..9f4862dd86 100644 --- a/plugins/plugins-available/conf/lib/Monitoring/Config.pm +++ b/plugins/plugins-available/conf/lib/Monitoring/Config.pm @@ -234,8 +234,6 @@ sub get_objects_by_name { my $templates_only = shift || 0; my $name2 = shift; - my @objs; - # object with secondary name if(defined $name2 and $name2 ne '') { my $subtype; @@ -248,14 +246,16 @@ sub get_objects_by_name { $id = $objects->{'hostgroup_name'}->{$name2}; } if(defined $id) { - push @objs, $self->get_object_by_id($id); + return [$self->get_object_by_id($id)]; } - return \@objs; + return []; } # existing template - if(defined $self->{'objects'}->{'byname'}->{'templates'}->{$type}->{$name}) { - push @objs, $self->get_object_by_id($self->{'objects'}->{'byname'}->{'templates'}->{$type}->{$name}); + my $objs = {}; + my $tid = $self->{'objects'}->{'byname'}->{'templates'}->{$type}->{$name}; + if(defined $tid) { + $objs->{$tid} = $self->get_object_by_id($tid); } # existing object @@ -263,22 +263,18 @@ sub get_objects_by_name { if(defined $self->{'objects'}->{'byname'}->{$type}->{$name}) { my $id = $self->{'objects'}->{'byname'}->{$type}->{$name}; unless(ref $id) { - push @objs, $self->get_object_by_id($id); + $objs->{$id} = $self->get_object_by_id($id); } else { - my %ids; for my $subtype (keys %{$id}) { for my $subid (values %{$id->{$subtype}}) { - $ids{$subid} = 1; + $objs->{$subid} = $self->get_object_by_id($id); } } - for my $id (keys %ids) { - push @objs, $self->get_object_by_id($id); - } } } } - return \@objs; + return [ values %{$objs} ]; } @@ -1249,7 +1245,7 @@ sub _update_obj_in_index { $objects->{'byid'}->{$obj->{'id'}} = $obj; # by type - if(!defined $tname) { + if(!defined $obj->{'conf'}->{'register'} or $obj->{'conf'}->{'register'} != 0) { push @{$objects->{'bytype'}->{$obj->{'type'}}}, $obj->{'id'}; } } diff --git a/plugins/plugins-available/conf/lib/Monitoring/Config/Object/Parent.pm b/plugins/plugins-available/conf/lib/Monitoring/Config/Object/Parent.pm index 97b12b7f3b..663c7933ce 100644 --- a/plugins/plugins-available/conf/lib/Monitoring/Config/Object/Parent.pm +++ b/plugins/plugins-available/conf/lib/Monitoring/Config/Object/Parent.pm @@ -97,15 +97,12 @@ sub is_template { =head2 get_template_name -return the objects template name +return the objects template name or undef =cut sub get_template_name { my $self = shift; - if(defined $self->{'conf'}->{'register'} and $self->{'conf'}->{'register'} == 0 and defined $self->{'conf'}->{'name'}) { - return $self->{'conf'}->{'name'}; - } - return; + return $self->{'conf'}->{'name'}; } @@ -118,7 +115,7 @@ return the objects name =cut sub get_name { my $self = shift; - if(defined $self->{'conf'}->{'register'} and $self->{'conf'}->{'register'} == 0 and defined $self->{'conf'}->{'name'}) { + if($self->is_template()) { return $self->get_template_name(); } return $self->get_primary_name(); @@ -163,10 +160,6 @@ sub get_primary_name { my $full = shift || 0; my $conf = shift || $self->{'conf'}; - if(defined $conf->{'register'} and $conf->{'register'} == 0 and defined $conf->{'name'}) { - return; - } - return $conf->{$self->{'primary_key'}} unless ref $self->{'primary_key'}; unless($full) { diff --git a/plugins/plugins-available/conf/lib/Thruk/Controller/conf.pm b/plugins/plugins-available/conf/lib/Thruk/Controller/conf.pm index c8f0629c59..292edcc08b 100644 --- a/plugins/plugins-available/conf/lib/Thruk/Controller/conf.pm +++ b/plugins/plugins-available/conf/lib/Thruk/Controller/conf.pm @@ -1193,10 +1193,10 @@ sub _get_context_object { my @newobjs; for my $o (@{$objs}) { if($templates == 1) { - push @newobjs, $o if defined $o->{'conf'}->{'register'} and $o->{'conf'}->{'register'} == 0; + push @newobjs, $o if $o->is_template(); } if($templates == 2) { - push @newobjs, $o if !defined $o->{'conf'}->{'register'} or $o->{'conf'}->{'register'} == 1; + push @newobjs, $o if !defined $o->{'conf'}->{'register'} or $o->{'conf'}->{'register'} != 0; } } @{$objs} = @newobjs;