[icinga-checkins] icinga.org: icinga2/master: API: Set zone attribute for local zone if not specified

git at icinga.org git at icinga.org
Thu Nov 10 20:01:34 CET 2016


Module: icinga2
Branch: master
Commit: 72bf538c2984284a0c0c2e13a611b72accb241fa
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=72bf538c2984284a0c0c2e13a611b72accb241fa

Author: Michael Friedrich <michael.friedrich at icinga.com>
Date:   Thu Nov 10 17:16:08 2016 +0100

API: Set zone attribute for local zone if not specified

This allows to sync the object to other nodes in the same
zone on reconnect.

refs #11684

---

 lib/remote/createobjecthandler.cpp |   13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/lib/remote/createobjecthandler.cpp b/lib/remote/createobjecthandler.cpp
index bcb0b25..97f993b 100644
--- a/lib/remote/createobjecthandler.cpp
+++ b/lib/remote/createobjecthandler.cpp
@@ -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();



More information about the icinga-checkins mailing list