[icinga-checkins] icinga.org: icinga-core/mfriedrich/core: core: fix handling of allow_empty_hostgroup_assignment when hitting NULL' edhost_name attribute, now properly finishing #949

git at icinga.org git at icinga.org
Fri Feb 17 22:28:12 CET 2012


Module: icinga-core
Branch: mfriedrich/core
Commit: c440478b44d13e79da4db5bd5a2a984ab0573833
URL:    https://git.icinga.org/?p=icinga-core.git;a=commit;h=c440478b44d13e79da4db5bd5a2a984ab0573833

Author: Michael Friedrich <michael.friedrich at univie.ac.at>
Date:   Fri Feb 17 22:25:11 2012 +0100

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

---

 Changelog                   |    1 +
 sample-config/icinga.cfg.in |    5 +++++
 xdata/xodtemplate.c         |   23 ++++++++++++++++++-----
 3 files changed, 24 insertions(+), 5 deletions(-)

diff --git a/Changelog b/Changelog
index 3907f98..f80521c 100644
--- a/Changelog
+++ b/Changelog
@@ -16,6 +16,7 @@ ENHANCEMENTS
 FIXES
 * core: Plug some macro leaks triggered when sending notifications (Andreas Ericsson) #2109
 * core: mark services as executing only when we know we will actually run them (Andreas Ericsson) #2302
+* core: fix handling of allow_empty_hostgroup_assignment when hitting NULL'edhost_name attribute, now properly finishing #949
 
 * install: Fix notification template installation (Todd Zullinger) #2235
 
diff --git a/sample-config/icinga.cfg.in b/sample-config/icinga.cfg.in
index c4c2dc1..6c7196b 100644
--- a/sample-config/icinga.cfg.in
+++ b/sample-config/icinga.cfg.in
@@ -1004,6 +1004,11 @@ process_performance_data=0
 # This boolean option determines whether services assigned to empty
 # host groups (host groups with no host members) will cause Icinga to
 # exit with error on start up (or during a configuration check) or not.
+# 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 Icinga config is
+# automated, or when a set of services is slowly being phased out but
+# should be kept around.
 # The default behavior if the option is not present in the main
 # configuration file is for Icinga to exit with error if services are
 # associated with host groups that have no hosts associated with them.
diff --git a/xdata/xodtemplate.c b/xdata/xodtemplate.c
index 2ef1517..7b9d37f 100644
--- a/xdata/xodtemplate.c
+++ b/xdata/xodtemplate.c
@@ -4128,8 +4128,14 @@ int xodtemplate_duplicate_services(void) {
 		/* 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;
+			/* allow_empty_hostgroup_assignment is not set, so actually warn the user about missing hostname attribute */
+			if(allow_empty_hostgroup_assignment == 0) {
+				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);
+				return ERROR;
+			} else {
+				/* we can't let the object being added to skiplist and then erroring out with NULL'ed host_name in common/objects.c add_service() */
+				continue;
+			}
 		}
 
 		if (temp_service->service_description == NULL) {
@@ -4169,9 +4175,16 @@ int xodtemplate_duplicate_services(void) {
 		xodtemplate_unset_service_is_from_hostgroup(temp_service);
 
 		/* skip service definitions without enough data */
-		if (temp_service->host_name == NULL) {
-			logit(NSLOG_CONFIG_ERROR, TRUE, "Error: 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);
-			return ERROR;
+                /* make host_name optional for services, only warn */
+                if (temp_service->host_name == NULL) {
+                        /* allow_empty_hostgroup_assignment is not set, so actually warn the user about missing hostname attribute */
+                        if(allow_empty_hostgroup_assignment == 0) {
+                                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);
+                                return ERROR;
+                        } else {
+                                /* we can't let the object being added to skiplist and then erroring out with NULL'ed host_name in common/objects.c add_service() */
+				continue;
+                        }
 		}
 
 		if (temp_service->service_description == NULL) {





More information about the icinga-checkins mailing list