]> granicus.if.org Git - icinga2/commitdiff
API: Set zone attribute for local zone if not specified
authorMichael Friedrich <michael.friedrich@icinga.com>
Thu, 10 Nov 2016 16:16:08 +0000 (17:16 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Thu, 10 Nov 2016 16:16:08 +0000 (17:16 +0100)
This allows to sync the object to other nodes in the same
zone on reconnect.

refs #11684

lib/remote/createobjecthandler.cpp

index bcb0b256cfd191623758613574cc470243fdebe3..97f993bbc9b4e4b39bceee176b7915de397b5b1f 100644 (file)
@@ -22,6 +22,7 @@
 #include "remote/httputility.hpp"
 #include "remote/filterutility.hpp"
 #include "remote/apiaction.hpp"
+#include "remote/zone.hpp"
 #include "base/configtype.hpp"
 #include <boost/algorithm/string.hpp>
 #include <set>
@@ -51,6 +52,18 @@ bool CreateObjectHandler::HandleRequest(const ApiUser::Ptr& user, HttpRequest& r
        Array::Ptr templates = params->Get("templates");
        Dictionary::Ptr attrs = params->Get("attrs");
 
+       /* Put created objects into the local zone if not explicitely defined.
+        * This allows additional zone members to sync the
+        * configuration at some later point.
+        */
+       Zone::Ptr localZone = Zone::GetLocalZone();
+       String localZoneName;
+
+       if (localZone && !attrs->Contains("zone")) {
+               localZoneName = localZone->GetName();
+               attrs->Set("zone", localZoneName);
+       }
+
        Dictionary::Ptr result1 = new Dictionary();
        String status;
        Array::Ptr errors = new Array();