Skip to content
This repository has been archived by the owner on Jan 15, 2019. It is now read-only.

[dev.icinga.com #2619] unable to exclude hostgroups when using nested hostgroups #978

Closed
icinga-migration opened this issue May 17, 2012 · 18 comments

Comments

@icinga-migration
Copy link

This issue has been migrated from Redmine: https://dev.icinga.com/issues/2619

Created by ladams on 2012-05-17 18:31:21 +00:00

Assignee: mfriedrich
Status: Resolved (closed on 2013-04-10 18:47:57 +00:00)
Target Version: 1.9
Last Update: 2013-04-10 18:47:57 +00:00 (in Redmine)

Icinga Version: 1.7.1
OS Version: RHEL

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.

Attachments

Changesets

2013-04-06 23:24:33 +00:00 by (unknown) df5047f

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
@icinga-migration
Copy link
Author

Updated by mfriedrich on 2012-07-31 19:19:33 +00:00

  • Category set to Configuration
  • Status changed from New to Assigned
  • Assigned to set to mfriedrich

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2012-08-01 02:26:00 +00:00

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.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2012-08-01 02:28:25 +00:00

  • File added 2619.cfg
  • 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;

@icinga-migration
Copy link
Author

Updated by ladams on 2012-08-01 03:32:02 +00:00

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?

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2012-08-01 12:12:07 +00:00

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

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2012-08-11 19:19:57 +00:00

  • Icinga Version set to 1
  • OS Version set to RHEL

so, any updates on your tests?

@icinga-migration
Copy link
Author

Updated by lcho@cloudmark.com on 2012-08-13 03:42:22 +00:00

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.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2012-08-22 18:12:46 +00:00

  • Assigned to changed from mfriedrich 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.

@icinga-migration
Copy link
Author

Updated by Animux on 2012-10-30 02:17:55 +00:00

  • File added reject-in-subhostgroups.diff

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.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2012-10-30 18:23:40 +00:00

  • Status changed from Feedback to Assigned
  • Assigned to changed from ladams to mfriedrich
  • 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?

@icinga-migration
Copy link
Author

Updated by Animux on 2012-10-30 20:46:10 +00:00

Alexander Sulfrian <alexander@sulfrian.net>

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2013-03-10 19:54:49 +00:00

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?

@icinga-migration
Copy link
Author

Updated by Animux on 2013-03-13 20:21:56 +00:00

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

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2013-03-13 20:23:27 +00:00

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

@icinga-migration
Copy link
Author

Updated by Animux on 2013-03-21 10:07:38 +00:00

  • File added 0001-xdata-exclude-hostgroups-when-using-nested-hostgroup.patch

Here is the patch, rebased on top of next.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2013-04-06 23:25:26 +00:00

  • 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.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2013-04-09 12:16:26 +00:00

patch lives in next now, anyone willing to test?

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2013-04-10 18:47:57 +00:00

  • Status changed from 7 to Resolved

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant