Bug #2619

unable to exclude hostgroups when using nested hostgroups

Added by ladams almost 2 years ago. Updated about 1 year ago.

Status:ResolvedStart date:05/17/2012
Priority:NormalDue date:
Assignee:dnsmichi% Done:

100%

Category:Configuration
Target version:Icinga 1.x - 1.9
Icinga Version:1.7.1 OS Version:RHEL

Description

Below is a dummy config that illustrates the issue with Icinga 1.4.
define hostgroup {
hostgroup_name groupA
}
define hostgroup {
hostgroup_name groupB
}
define host {
use generic-host
host_name foo
address 127.0.0.1
hostgroups groupA
}
define host {
use generic-host
host_name foo2
address 127.0.0.1
hostgroups groupB,groupA
}

define hostgroup {
hostgroup_name groupC
hostgroup_members groupA,!groupB
}

When running verify, Error: Could not find member group '!groupB' specified in hostgroup

Since exclusions are allowed at all, I really feel like exclusions should be allowed here as well.

2619.cfg (742 Bytes) dnsmichi, 08/01/2012 04:28 am

reject-in-subhostgroups.diff Magnifier (6.52 KB) Animux, 10/30/2012 03:17 am

0001-xdata-exclude-hostgroups-when-using-nested-hostgroup.patch Magnifier (8.28 KB) Animux, 03/21/2013 11:07 am

Associated revisions

Revision df5047f5
Added by Michael Friedrich about 1 year ago

core: fix unable to exclude hostgroups when using nested hostgroups (Alexander Sulfrian) #2619

patch adds a dedicated reject list, which then also allows to exclude
hostgroups. thanks for the neat patch.

a testcase is added as well, it passes config verification where
previously an error was thrown.

refs #2619

History

#1 Updated by dnsmichi over 1 year ago

  • Category set to Configuration
  • Status changed from New to Assigned
  • Assignee set to dnsmichi

#2 Updated by dnsmichi over 1 year ago

exclusions are not possible when recursing down into subgroups of host/service/contactgroup and their members.

xdata/xodtemplate.c

        /* expand subgroup membership recursively */
        for (temp_hostgroup = xodtemplate_hostgroup_list; temp_hostgroup; temp_hostgroup = temp_hostgroup->next)
                xodtemplate_recombobulate_hostgroup_subgroups(temp_hostgroup, NULL);

as well as recursing all subgroup members down then.

                ptr = hgmembers;
                while ((buf = ptr) != NULL) {

                        /* get next member for next run*/
                        ptr = strchr(ptr, ',');
                        if (ptr) {
                                ptr[0] = '\x0';
                                ptr++;
                        }

                        strip(buf);

                        /* find subgroup and recurse */
                        if ((sub_group = xodtemplate_find_real_hostgroup(buf)) == NULL) {
                                logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not find member group '%s' specified in hostgroup (config file '%s', starting on line %d)\n", buf, xodtemplate_config_file_name(temp_hostgroup->_config_file), temp_hostgroup->_start_line);
                                return ERROR;
                        }
                        xodtemplate_recombobulate_hostgroup_subgroups(sub_group, &newmembers);

                        /* add new (sub) members */
                        if (newmembers != NULL) {
                                if (temp_hostgroup->members == NULL)
                                        temp_hostgroup->members = (char *)strdup(newmembers);
                                else if ((temp_hostgroup->members = realloc(temp_hostgroup->members, strlen(temp_hostgroup->members) + strlen(newmembers) + 2))) {
                                        strcat(temp_hostgroup->members, ",");
                                        strcat(temp_hostgroup->members, newmembers);
                                }
                        }
                }

the error is a bit misleading, as it's the function xodtemplate_find_real_hostgroup not finding the !hostname.

either way, i do not really have an idea how to make exclusions work in this sector of the configs, especially since i do not know what other irritations such an exclusions could cause.

#3 Updated by dnsmichi over 1 year ago

  • File 2619.cfg added
  • Status changed from Assigned to Feedback

using the attached config, one might test this diff - which requires rework for service and contact groups as well.

still, i do not know what other troubles this might cause, so i won't put that into my git dev trees, but leave it here for testers feedback only.

diff --git a/xdata/xodtemplate.c b/xdata/xodtemplate.c
index 2698f31..46e3842 100644
--- a/xdata/xodtemplate.c
+++ b/xdata/xodtemplate.c
@@ -8031,6 +8031,7 @@ int xodtemplate_recombobulate_hostgroup_subgroups(xodtemplate_hostgroup *temp_ho
        char *newmembers = NULL;
        char *buf = NULL;
        char *ptr = NULL;
+       int reject_item = FALSE;

        if (temp_hostgroup == NULL)
                return ERROR;
@@ -8058,6 +8059,15 @@ int xodtemplate_recombobulate_hostgroup_subgroups(xodtemplate_hostgroup *temp_ho
                        strip(buf);

                        /* find subgroup and recurse */
+                       if (buf[0] == '!') {
+                               reject_item = TRUE;
+                               buf++;
+                               logit(NSLOG_CONFIG_ERROR, TRUE, "Warning: Excluding member group '%s' specified in hostgroup (config file '%s', starting on line %d)\n", buf, xodtemplate_config_file_name(temp_hostgroup->_config_file), temp_hostgroup->_start_line);
+                       }
+
+                       if (reject_item == TRUE)
+                               continue;
+
                        if ((sub_group = xodtemplate_find_real_hostgroup(buf)) == NULL) {
                                logit(NSLOG_CONFIG_ERROR, TRUE, "Error: Could not find member group '%s' specified in hostgroup (config file '%s', starting on line %d)\n", buf, xodtemplate_config_file_name(temp_hostgroup->_config_file), temp_hostgroup->_start_line);
                                return ERROR;

#4 Updated by ladams over 1 year ago

May I ask about the Warning? We use exclusions all over the place and don't see any warnings about them. Why would there be one here?

#5 Updated by dnsmichi over 1 year ago

that's debug output i left in the diff, intentionally. especially to see if you tested it, when providing output ;-)

#6 Updated by dnsmichi over 1 year ago

  • Icinga Version set to 1.7.1
  • OS Version set to RHEL

so, any updates on your tests?

#7 Updated by lcho@cloudmark.com over 1 year ago

I'm not going to be able to run these tests. We are on an older version still, and I don't have the time to take this on right now. I reported the bug because I saw an issue and that's what the forums said to do. If there are other developers/testers out there, I would prefer that they actually run this test.

#8 Updated by dnsmichi over 1 year ago

  • Assignee changed from dnsmichi to ladams

well, then find someone else wanting that feature as well. if that's so minor audience, i won't apply and maintain that upstream. though, once you are in the lucky position to upgrade you can probably test that as well.

#9 Updated by Animux over 1 year ago

I have tested the proposed patch and it does not work. The patch simply skips the hostgroup_members prefixed by a ! and does no rejection. I have reworked the hostgroup_member parsing and I could confirm that it works with my patch. The current design does not have the possibility to reject members, because every member is instantaneously appended to the member string and could there for not be removed later.

My patch changes the parsing, so that the hostgroup_members are now parsed into two xodtemplate_memberlist (one for members and one for rejects) and all rejected elements get filtered out. The member string is only calculated at the end of the processing of the hostgroup.

After applying my patch the listed config on top results in the following hostgroup definitions:

define hostgroup {
        hostgroup_name  groupA
        members foo,foo2
        }

define hostgroup {
        hostgroup_name  groupB
        members foo2
        }

define hostgroup {
        hostgroup_name  groupC
        members foo
        }

So it seems it works. I use this patch to specify services for some hosts, that are in two hostgroups:

define hostgroup {
        hostgroup_name  debian-servers
        alias           Debian GNU/Linux Servers
        members         some,server,foo,bar
}

define hostgroup {
        hostgroup_name virtual-hosts
        members        some,other,members,bar
}

define hostgroup {
        hostgroup_name non-debian-servers
        hostgroup_members all,!debian-servers
}

define service {
        use generic-service
        hostgroup_name virtual-hosts,!non-debian-servers
        service_description some service for virtual debian servers
}

Using my patch, the service is available for the hosts some and bar.

#10 Updated by dnsmichi over 1 year ago

  • Status changed from Feedback to Assigned
  • Assignee changed from ladams to dnsmichi
  • Target version set to 1.9

very nice, thank you. let's see when i get time to test that one. who should the kudos be given to in case?

#11 Updated by Animux over 1 year ago

Alexander Sulfrian <>

#12 Updated by dnsmichi about 1 year ago

hm, tried to apply the patch against my 1.9 tree, and it is not clean. nor is it for 1.8 ... on which basis is this one built against?

#13 Updated by Animux about 1 year ago

As specified the patch was based on icinga-1.7.1 from debian squeeze-backports. Should I rebase it in 1.9?

#14 Updated by dnsmichi about 1 year ago

would be great if you could rebase it against current git 'next' branch which will be the source for 1.9 then.

#15 Updated by Animux about 1 year ago

Here is the patch, rebased on top of next.

#16 Updated by dnsmichi about 1 year ago

  • Status changed from Assigned to 7
  • % Done changed from 0 to 100

without the patch

Error: Could not find member group '!2619groupB' specified in hostgroup (config file '/etc/icinga/tests/2619.cfg', starting on line 28)
   Error processing object config files!

with the patch it works like a charm. thanks.

#17 Updated by dnsmichi about 1 year ago

patch lives in next now, anyone willing to test?

#18 Updated by dnsmichi about 1 year ago

  • Status changed from 7 to Resolved

Also available in: Atom PDF