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

[dev.icinga.com #949] Optionally allow empty hostgroup assigment for services #436

Closed
icinga-migration opened this issue Nov 2, 2010 · 7 comments

Comments

@icinga-migration
Copy link

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

Created by mfriedrich on 2010-11-02 16:58:57 +00:00

Assignee: mfriedrich
Status: Resolved (closed on 2012-02-23 18:41:13 +00:00)
Target Version: 1.7
Last Update: 2012-02-23 18:41:13 +00:00 (in Redmine)


-------- Original Message --------
Subject:    Re: [Nagios-users] hostgroup with no members - Enhancement
Date:   Tue, 2 Nov 2010 11:50:03 -0400
From:   Max Schubert 
Reply-To:   Nagios Users List 
To:     Nagios Users List 


On Tue, Nov 2, 2010 at 10:52 AM, Fredrik Barrud  wrote:
> Hi,
>
> I would also like to be able to create empty hostgroups with services assigned.
>
> The reason for this is that I've setup a nagios installation for a customer where a host is only member to one hostgroup to inherit services from other hostgroups, like all->windows->citrix->server and for a few special servertypes I would like to prepare the chain with hostgroup and services so that when the servers are ready to be monitored everything is prepared and the servers only needs to be added to the apropriate hostgroup.

We have a local patch to turn the error into a warning, patched
against 3.2.0 - we needed this because we have customers who can use
host -> hostgroup -> N related services mappings but we do not control
their configs, we only define the global service sets - so we could
not have this be fatal and fail everyone's changes just because one
customer stopped using the mapping.

We have been using this patch in production for a year without issues.

To apply:
1) Put patch in top level source directory
2) patch -p0 < name-of-patch

- Max

Attachments

Changesets

2010-12-17 16:44:13 +00:00 by mfriedrich 305ec37

core: allow empty hostgroup aissgments for services as opt-in config option (Max Schubert) #949

--SNIP--
We used to bomb out with an error on such configurations, but with
this option it becomes optional if we should produce an error or a
warning.

It's useful to be able to assign services to empty hostgroups when
configuration files or pre-cached object files are distributed to
various pollers, or when the process of generating Nagios config is
automated, or when a set of services is slowly being phased out but
should be kept around in case of 'oh shit' epiphanies, such as one
might experience when phasing out old monitoring agents.

Thanks to Comcast in general and Max Schubert in particular for
sharing this patch.

Authored-by: Max Schubert <maxs@webwizarddesign.com>
Reviewed-by: Daniel Wittenberg <daniel.wittenberg.r0ko@statefarm.com>
Reviewed-by: Michael Friedrich <michael.friedrich@univie.ac.at>
Signed-off-by: Andreas Ericsson <ae@op5.se>
--SNIP--

this patch makes the checking for host_name on service definition
a warning in order to allow such behahvior.

fixes #949

2012-02-17 21:25:11 +00:00 by mfriedrich c440478

core: fix handling of allow_empty_hostgroup_assignment when hitting NULL'edhost_name attribute, now properly finishing #949

previously we were checking if host_name attribute was NULL, warning the
user about that and then looping to the objects_skiplist_insert and
finally erroring out due to wrongly to-be-registered incomplete object.
this is now fixed for both, the default is an error, using
allow_empty_hostgroup_assignment will now discard the warning and
ignoring the object.

oh, and updated the config description a bit, to tell where this
functionality is useful (and somewhat not to do some object tricks like
people tried to do and bug report then...)

refs #949

Relations:

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2010-11-03 15:32:02 +00:00

  • Status changed from New to Assigned
  • Assigned to set to mfriedrich
  • Target Version set to 1.3

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2010-11-24 09:11:17 +00:00

normal behavior

define hostgroup {
  hostgroup_name  test-servers
  alias           Test Servers
}

define service {
  hostgroup_name           test-servers
  service_description      SSH
  check_command            check_ssh
  use                      generic-service
  notification_interval    0
}

Error: Could not expand hostgroups and/or hosts specified in service (config file '/etc/nagios/test-conf/etc/test.cfg', starting on line 6)

having the patch applied, the proposed example lacks of a host_name in the service definition which will lead the service into not being registered correctly. nagios ignores that while icinga spits out an error.

so this needs further investigation.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2010-12-03 15:47:38 +00:00

  • Subject changed from allow hostgroup with no members to Optionally allow assigning services to empty hostgroups

    From: Andreas Ericsson
    Date: Mon, 29 Nov 2010 12:48:35 +0000 (+0000)
    Subject: Optionally allow assigning services to empty hostgroups
    X-Git-Url: http://git.nagiosprojects.org/?p=nagios.git;a=commitdiff_plain;h=041ff80210711c1877745e04b36869c9e67344a6;hp=9ff2abc4d3e15f0fd4fe23ae02d5961a6fec1a5d

    Optionally allow assigning services to empty hostgroups

    We used to bomb out with an error on such configurations, but with
    this option it becomes optional if we should produce an error or a
    warning.

    It's useful to be able to assign services to empty hostgroups when
    configuration files or pre-cached object files are distributed to
    various pollers, or when the process of generating Nagios config is
    automated, or when a set of services is slowly being phased out but
    should be kept around in case of 'oh shit' epiphanies, such as one
    might experience when phasing out old monitoring agents.

    Thanks to Comcast in general and Max Schubert in particular for
    sharing this patch.

    Authored-by: Max Schubert
    Reviewed-by: Daniel Wittenberg
    Reviewed-by: Michael Friedrich
    Signed-off-by: Andreas Ericsson

    diff --git a/THANKS b/THANKS
    index 6cc4855..a634466 100644
    --- a/THANKS
    +++ b/THANKS
    @@ -242,6 +242,7 @@ since 1999. If I missed your name, let me know.

    • Mark Schenker
    • David Schlecht
    • Russell Scibetti
      +* Max Schubert
    • Thomas Sebastien
    • Brian Seklecki
    • Denis Seleznyov
      diff --git a/base/config.c b/base/config.c
      index 12c528d..3fd1287 100644
      --- a/base/config.c
      +++ b/base/config.c
      @@ -212,6 +212,8 @@ extern int debug_level;
      extern int debug_verbosity;
      extern unsigned long max_debug_file_size;

    +extern int allow_empty_hostgroup_assignment;
    +

    /******************************************************************/
    @@ -1336,6 +1338,9 @@ int read_main_config_file(char *main_config_file)
    continue;
    else if(strstr(input,"precached_object_file=")==input)
    continue;

    •   else if(!strcmp(variable,"allow_empty_hostgroup_assignment")){
      
    •       allow_empty_hostgroup_assignment=(atoi(value)>0)?TRUE:FALSE;
      
    •                }
      
        /* we don't know what this variable is... */
        else{
      

    diff --git a/base/nagios.c b/base/nagios.c
    index 45ee1ad..f1aa5d7 100644
    --- a/base/nagios.c
    +++ b/base/nagios.c
    @@ -237,6 +237,8 @@ int embedded_perl_initialized=FALSE;
    int date_format=DATE_FORMAT_US;
    char *use_timezone=NULL;

    +int allow_empty_hostgroup_assignment=DEFAULT_ALLOW_EMPTY_HOSTGROUP_ASSIGNMENT;
    +
    int command_file_fd;
    FILE *command_file_fp;
    int command_file_created=FALSE;
    diff --git a/html/docs/configmain.html b/html/docs/configmain.html
    index e25f7b9..dc71631 100644
    --- a/html/docs/configmain.html
    +++ b/html/docs/configmain.html
    @@ -7024,9 +7024,51 @@ This option determines the maximum size (in bytes) of the

    +Allow Empty Hostgroup Assignment
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +
    +Format:
    +
    +allow_empty_hostgroup_assignment=[01]

    +Example:

    +allow_empty_hostgroup_assignment=1
    +
    +
    +
    +
    +
    +
    +
    +
    +This boolean option determines whether services assigned to empty host groups (host groups with no host members) will cause Nagios to exit with error on start up (or during a configuration check) or not. The default behavior if the option is not present in the main configuration file is for Nagios to exit with error if services are associated with host groups that have no hosts associated with them. Enabling this option can be useful when:
    +
    +
    +

    • Configuration files or pre-cached object files are distributed across many Nagios pollers.
    • Automation is used to generate a Nagios configuration file tree.
    • There is one set of services maintained by administrators that users may add to their hosts through host group membership for convenience (e.g. a suite of checks associated with a remote monitoring agent) but there is no guarantee that users will use the services associated with the host group (e.g. a remote agent that is being deprecated over time).

    diff --git a/include/nagios.h b/include/nagios.h
    index da9d9d4..a4e5bc0 100644
    --- a/include/nagios.h
    +++ b/include/nagios.h
    @@ -138,6 +138,7 @@ extern "C" {
    #define BASE_UPDATE_CHECK_RETRY_INTERVAL 60601 /* 1 hour base retry interval /
    #define UPDATE_CHECK_RETRY_INTERVAL_WOBBLE 60
    603 / 3 hour wobble on top of base retry interval */

    +#define DEFAULT_ALLOW_EMPTY_HOSTGROUP_ASSIGNMENT 0 /* Do not allow empty hostgroups by default */

    /******************** HOST STATUS *********************/

    diff --git a/xdata/xodtemplate.c b/xdata/xodtemplate.c
    index 94dfb92..91668bd 100644
    --- a/xdata/xodtemplate.c
    +++ b/xdata/xodtemplate.c
    @@ -123,6 +123,8 @@ char *xodtemplate_precache_file=NULL;

    int presorted_objects=FALSE;

    +extern int allow_empty_hostgroup_assignment;
    +
    /*
    * Macro magic used to determine if a service is assigned
    * via hostgroup_name or host_name. Those assigned via host_name
    @@ -4112,6 +4114,7 @@ int xodtemplate_duplicate_services(void){
    int result=OK;
    xodtemplate_service *temp_service=NULL;
    xodtemplate_memberlist *temp_memberlist=NULL;

    • xodtemplate_memberlist *temp_rejectlist=NULL;
      xodtemplate_memberlist *this_memberlist=NULL;
      char *host_name=NULL;
      int first_item=FALSE;
      @@ -4124,6 +4127,26 @@ int xodtemplate_duplicate_services(void){
      if(temp_service->hostgroup_name==NULL && temp_service->host_name==NULL)
      continue;

    •   /* If hostgroup is not null and hostgroup has no members, check to see if */
      
    •   /* allow_empty_hostgroup_assignment is set to 1 - if it is, continue without error  */
      
    •   if(temp_service->hostgroup_name!=NULL){
      
    •       if(xodtemplate_expand_hostgroups(&temp_memberlist,&temp_rejectlist,temp_service->hostgroup_name,temp_service->_config_file,temp_service->_start_line)==ERROR){
      
    •           return ERROR;
      
    •           }
      
    •       else{
      
    •           xodtemplate_free_memberlist(&temp_rejectlist);
      
    •           if (temp_memberlist!=NULL){
      
    •               xodtemplate_free_memberlist(&temp_memberlist);
      
    •               }
      
    •           else{
      
    •               /* User is ok with hostgroup -> service mappings with no hosts */
      
    •               if(allow_empty_hostgroup_assignment==1){
      
    •                   continue;
      
    •                                           }
      
    •               }
      
    •           }
      
    •       }
      
    •   /* skip services that shouldn't be registered */
        if(temp_service->register_object==FALSE)
            continue;
      

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2010-12-17 16:29:25 +00:00

  • Subject changed from Optionally allow assigning services to empty hostgroups to Optionally allow empty hostgroup assigment for services
  • Done % changed from 0 to 90

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2010-12-17 19:52:56 +00:00

  • Status changed from Assigned to Resolved
  • Done % changed from 90 to 100

Applied in changeset commit:"305ec37a447bda3333de8c5574d20ecc70629532".

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2012-02-17 21:24:40 +00:00

  • Status changed from Resolved to Assigned
  • Target Version changed from 1.3 to 1.7
  • Done % changed from 100 to 90

this does not properly work, because icinga threats the first and secondary loop differently (and ofc wrong).

original

        /* First loop for single host service definition*/
        for(temp_service = xodtemplate_service_list; temp_service != NULL; temp_service = temp_service->next) {

                /* skip services that shouldn't be registered */
                if(temp_service->register_object == FALSE)
                        continue;

                /* skip service definitions without enough data */
                if(temp_service->host_name == NULL || temp_service->service_description == NULL)
                        continue;

modified to warn the user about some possible missing attributes:

        /* First loop for single host service definition*/
        for (temp_service = xodtemplate_service_list; temp_service != NULL; temp_service = temp_service->next) {

                /* skip services that shouldn't be registered */
                if (temp_service->register_object == FALSE)
                        continue;

                if (xodtemplate_is_service_is_from_hostgroup(temp_service)) {
                        continue;
                }

                /* skip service definitions without enough data */
                /* make host_name optional for services, only warn */
                if (temp_service->host_name == NULL) {
                        logit(NSLOG_CONFIG_WARNING, TRUE, "Warning: No host_name found for service definition or used template (config file '%s', starting on line %d)\n", xodtemplate_config_file_name(temp_service->_config_file), temp_service->_start_line);
                        result = ERROR;
                }

                if (temp_service->service_description == NULL) {
                        logit(NSLOG_CONFIG_ERROR, TRUE, "Error: No service_description found for service definition or used template (config file '%s', starting on line %d)\n", xodtemplate_config_file_name(temp_service->_config_file), temp_service->_start_line);
                        return ERROR;
                }

the first condition let's things pass through, even if checking allow_empty_hostgroups_assignment before, and then being inserted to objects_skiplist either way, resulting in the final error of missing an important attribute when registering to the core.
by preventing that object being inserted to skiplists, a proper fix must be provided - in case allow_empty_hostgroup_assigment just loop without a warning, in case of default behaviour return a shiny error and error out.

@icinga-migration
Copy link
Author

Updated by mfriedrich on 2012-02-23 18:41:13 +00:00

  • Status changed from Assigned to Resolved
  • Done % changed from 90 to 100

finally fixed correctly.

in master and next (which will be the source for r1.7)

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