From aaeca533fc4d9a04888f77a419326772bf5ac9a7 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Tue, 15 Nov 2016 13:54:22 +0100 Subject: [PATCH 1/3] IcingaConfig/IcingaObject(Legacy): Render dummy notification settings So we avoid warnings about nothing configured. refs #13049 --- .../Director/IcingaConfig/IcingaConfig.php | 44 +++++++++++++++++++ library/Director/Objects/IcingaObject.php | 10 +++++ 2 files changed, 54 insertions(+) diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php index 19d902e4..1d1ffb8f 100644 --- a/library/Director/IcingaConfig/IcingaConfig.php +++ b/library/Director/IcingaConfig/IcingaConfig.php @@ -500,6 +500,15 @@ class IcingaConfig protected function prepareGlobalBasics() { if ($this->isLegacy()) { + $this->configFile( + sprintf( + 'director/%s/001-director-basics', + $this->connection->getDefaultGlobalZoneName() + ), '.cfg' + )->prepend( + $this->renderLegacyDefaultNotification() + ); + return $this; } @@ -781,4 +790,39 @@ apply Service for (title => params in host.vars["%s"]) { return $this->lastActivityChecksum; } + + protected function renderLegacyDefaultNotification() + { + return preg_replace('~^ {12}~m', '', ' + # + # Default objects to avoid warnings + # + + define contact { + contact_name icingaadmin + alias Icinga Admin + host_notifications_enabled 0 + host_notification_commands notify-never-default + host_notification_period notification_none + service_notifications_enabled 0 + service_notification_commands notify-never-default + service_notification_period notification_none + } + + define contactgroup { + contactgroup_name icingaadmins + members icingaadmin + } + + define timeperiod { + timeperiod_name notification_none + alias No Notifications + } + + define command { + command_name notify-never-default + command_line /bin/echo "NOOP" + } + '); + } } diff --git a/library/Director/Objects/IcingaObject.php b/library/Director/Objects/IcingaObject.php index 83994fd2..f84b066d 100644 --- a/library/Director/Objects/IcingaObject.php +++ b/library/Director/Objects/IcingaObject.php @@ -2054,6 +2054,16 @@ abstract class IcingaObject extends DbObject implements IcingaConfigRenderer { $str = ''; + // Set notification settings for the object to suppress warnings + if ( + array_key_exists('enable_notifications', $this->defaultProperties) + && $this->isTemplate() + ) { + $str .= c1::renderKeyValue('notification_period', 'notification_none'); + $str .= c1::renderKeyValue('notification_interval', '0'); + $str .= c1::renderKeyValue('contact_groups', 'icingaadmins'); + } + // force rendering of check_command when ARG1 is set if ($this->supportsCustomVars() && array_key_exists('check_command_id', $this->defaultProperties)) { if ( From c2734fd4d44e8cee10f48e79a93afc28a1c1dfd6 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Tue, 15 Nov 2016 14:39:41 +0100 Subject: [PATCH 2/3] IcingaHostGroup(Legacy): Render assigned groups to all zones So we still can support hosts with direct groups. refs #13049 --- library/Director/Objects/IcingaHostGroup.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/Director/Objects/IcingaHostGroup.php b/library/Director/Objects/IcingaHostGroup.php index 6eb7a3ae..be5f8552 100644 --- a/library/Director/Objects/IcingaHostGroup.php +++ b/library/Director/Objects/IcingaHostGroup.php @@ -59,6 +59,15 @@ class IcingaHostGroup extends IcingaObjectGroup } else { $allMembers = array(); + // make sure we write to all zones + // so host -> group relations are still possible + foreach (IcingaZone::loadAll($conn) as $zone) { + $zoneId = $zone->getAutoincId(); + if (! array_key_exists($zoneId, $zoneMap)) { + $zoneMap[$zoneId] = array(); + } + } + foreach ($zoneMap as $zoneId => $members) { $file = $this->legacyZoneHostgroupFile($config, $zoneId); $this->properties['members'] = $members; From 4a838ca277161632555a07a604124600ed420170 Mon Sep 17 00:00:00 2001 From: Markus Frosch Date: Tue, 15 Nov 2016 16:36:48 +0100 Subject: [PATCH 3/3] IcingaHostGroup(Legacy): Load zones prefetched refs #13049 --- library/Director/Objects/IcingaHostGroup.php | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/library/Director/Objects/IcingaHostGroup.php b/library/Director/Objects/IcingaHostGroup.php index be5f8552..148559e9 100644 --- a/library/Director/Objects/IcingaHostGroup.php +++ b/library/Director/Objects/IcingaHostGroup.php @@ -61,10 +61,9 @@ class IcingaHostGroup extends IcingaObjectGroup // make sure we write to all zones // so host -> group relations are still possible - foreach (IcingaZone::loadAll($conn) as $zone) { - $zoneId = $zone->getAutoincId(); - if (! array_key_exists($zoneId, $zoneMap)) { - $zoneMap[$zoneId] = array(); + foreach (IcingaObject::loadAllByType('zone', $conn) as $zone) { + if (! array_key_exists($zone->id, $zoneMap)) { + $zoneMap[$zone->id] = array(); } }