Subject: | find_object does not locate ServiceEscalation, ServiceDependency, or HostEscalation templates |
If you try to look up a template for a ServiceEscalation,
ServiceDependency or HostEscalation type, find_object() will not find
it, even when the name is known to be correct. Attached is a patch for
find_object() as well as a 'make test' script that demonstrates the issue.
Subject: | perl-Nagios-Object-0.21.12-find_object-bug.patch |
--- ./lib/Nagios/Object.pm.orig 2010-12-01 15:20:10.000000000 -0500
+++ ./lib/Nagios/Object.pm 2010-12-01 15:22:06.000000000 -0500
@@ -658,19 +658,18 @@
sub name {
my $self = shift;
- my $name_method = $self->_name_attribute;
-
- if ( $name_method eq 'generated' ) {
- $_name_hack++;
- return
- ref($self) . '-'
- . $_name_hack; # FIXME: this should work but feels wrong
- }
-
if ( !$self->register ) {
return $self->{name};
}
else {
+ my $name_method = $self->_name_attribute;
+ if ( $name_method eq 'generated' ) {
+ $_name_hack++;
+ return
+ ref($self) . '-'
+ . $_name_hack; # FIXME: this should work but feels wrong
+ }
+
my $name = $self->$name_method();
# recurse down on references to get the names, then generate something
--- ./t/find_object-template.cfg.orig 2010-11-29 11:06:09.000000000 -0500
+++ ./t/find_object-template.cfg 2010-11-29 10:58:44.000000000 -0500
@@ -0,0 +1,61 @@
+###############################################################################
+#
+# HostEscalation Objects
+#
+###############################################################################
+
+define hostescalation{
+ name hostescalation-template
+ first_notification 4
+ last_notification 10
+ notification_interval 60
+ contact_groups all-escalation
+ register 0
+}
+
+define hostescalation{
+ use hostescalation-template
+ host_name host1
+}
+
+###############################################################################
+#
+# ServiceDependency Objects
+#
+###############################################################################
+
+define servicedependency{
+ name servicedependency-template
+ execution_failure_criteria n
+ notification_failure_criteria w,u,c
+ register 0
+}
+
+define servicedependency{
+ use servicedependency-template
+ host_name host1
+ service_description http check
+ dependent_host_name host1
+ dependent_service_description http process check
+}
+
+###############################################################################
+#
+# ServiceEscalation Objects
+#
+###############################################################################
+
+define serviceescalation{
+ name serviceescalation-template
+ first_notification 4
+ last_notification 10
+ notification_interval 60
+ contact_groups all-escalation
+ register 0
+}
+
+define serviceescalation{
+ use serviceescalation-template
+ host_name host1
+ service_description http check
+}
--- ./t/find_object-template.t.orig 2010-11-29 11:06:11.000000000 -0500
+++ ./t/find_object-template.t 2010-11-29 11:11:25.000000000 -0500
@@ -0,0 +1,36 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+use Test::More;
+use lib qw( ../lib ./lib );
+
+BEGIN { plan tests => 3 }
+
+use Nagios::Object::Config;
+
+my $err = 0;
+my $file = 'find_object-template.cfg';
+
+my @types = qw/Nagios::ServiceEscalation Nagios::HostEscalation Nagios::ServiceDependency/;
+my @methods = qw/list_serviceescalations list_hostescalations list_servicedependencies/;
+
+eval { chdir('t'); };
+
+my $obj = Nagios::Object::Config->new();
+$obj->parse($file) || die "Could not parse object file ($file)\n";
+$obj->resolve_objects();
+
+for (my $i = 0; $i < scalar @types; $i++) {
+ my $method = $methods[$i];
+ foreach my $o ( @{$obj->$method()} ) {
+ # If we have use a template, find that object.
+ if ( exists $o->{'use'} && defined $o->{'use'} ) {
+ my $res = $obj->find_object($o->{'use'}, $types[$i]);
+ my $ref = ref $res;
+ ok( $ref eq $types[$i], "Looking for a $types[$i] object" );
+ }
+ }
+}
+
+exit $err;