[icinga-checkins] icinga.org: icingaweb2-module-director/feature/icinga-legacy-config-13049: IcingaConfig/IcingaObject(Legacy): Render dummy notification settings

git at icinga.org git at icinga.org
Tue Nov 15 14:05:14 CET 2016


Module: icingaweb2-module-director
Branch: feature/icinga-legacy-config-13049
Commit: a04f25167aa35b614b65e687db13e4dccb189ddd
URL:    https://git.icinga.org/?p=icingaweb2-module-director.git;a=commit;h=a04f25167aa35b614b65e687db13e4dccb189ddd

Author: Markus Frosch <markus.frosch at icinga.com>
Date:   Tue Nov 15 13:54:22 2016 +0100

IcingaConfig/IcingaObject(Legacy): Render dummy notification settings

So we avoid warnings about nothing configured.

refs #13049

---

 library/Director/IcingaConfig/IcingaConfig.php |   40 ++++++++++++++++++++++++
 library/Director/Objects/IcingaObject.php      |   10 ++++++
 2 files changed, 50 insertions(+)

diff --git a/library/Director/IcingaConfig/IcingaConfig.php b/library/Director/IcingaConfig/IcingaConfig.php
index 19d902e..129d222 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,35 @@ apply Service for (title => params in host.vars["%s"]) {
 
         return $this->lastActivityChecksum;
     }
+
+    protected function renderLegacyDefaultNotification()
+    {
+        return preg_replace('~\s[12]~', '', '
+            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 83994fd..f84b066 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 (



More information about the icinga-checkins mailing list