set(base_SOURCES
i2-base.hpp
- application.cpp application.hpp application-ti.hpp application-version.cpp
+ application.cpp application.hpp application-ti.hpp application-version.cpp application-environment.cpp
array.cpp array.hpp array-script.cpp
base64.cpp base64.hpp
boolean.cpp boolean.hpp boolean-script.cpp
--- /dev/null
+/******************************************************************************
+ * Icinga 2 *
+ * Copyright (C) 2012-2018 Icinga Development Team (https://www.icinga.com/) *
+ * *
+ * This program is free software; you can redistribute it and/or *
+ * modify it under the terms of the GNU General Public License *
+ * as published by the Free Software Foundation; either version 2 *
+ * of the License, or (at your option) any later version. *
+ * *
+ * This program is distributed in the hope that it will be useful, *
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of *
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
+ * GNU General Public License for more details. *
+ * *
+ * You should have received a copy of the GNU General Public License *
+ * along with this program; if not, write to the Free Software Foundation *
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA. *
+ ******************************************************************************/
+
+#include "base/application.hpp"
+#include "base/scriptglobal.hpp"
+
+using namespace icinga;
+
+String Application::GetAppEnvironment()
+{
+ Value defaultValue = Empty;
+ return ScriptGlobal::Get("Environment", &defaultValue);
+}
+
+void Application::SetAppEnvironment(const String& name)
+{
+ ScriptGlobal::Set("Environment", name);
+}
static String GetAppVersion();
static String GetAppSpecVersion();
+ static String GetAppEnvironment();
+ static void SetAppEnvironment(const String& name);
+
static double GetStartTime();
static void SetStartTime(double ts);
return ScriptGlobal::Get("NodeName");
}
+String IcingaApplication::GetEnvironment() const
+{
+ return Application::GetAppEnvironment();
+}
+
+void IcingaApplication::SetEnvironment(const String& value, bool suppress_events, const Value& cookie)
+{
+ Application::SetAppEnvironment(value);
+}
+
void IcingaApplication::ValidateVars(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils)
{
MacroProcessor::ValidateCustomVars(this, lvalue());
String GetNodeName() const;
+ String GetEnvironment() const override;
+ void SetEnvironment(const String& value, bool suppress_events = false, const Value& cookie = Empty) override;
+
void ValidateVars(const Lazy<Dictionary::Ptr>& lvalue, const ValidationUtils& utils) override;
private:
class IcingaApplication : Application
{
+ [config, no_storage, virtual] String environment {
+ get;
+ set;
+ default {{{ return Application::GetAppEnvironment(); }}}
+ };
+
[config] bool enable_notifications {
default {{{ return true; }}}
};
TlsStream::Ptr tlsStream;
- String environmentName = GetEnvironment();
+ String environmentName = Application::GetAppEnvironment();
+
String serverName = hostname;
- if (!environmentName.IsEmpty() && environmentName != "")
+ if (!environmentName.IsEmpty())
serverName += ":" + environmentName;
{
default {{{ return Application::GetConst("ApiBindPort", "5665"); }}}
};
- [config] String environment {
- default {{{ return Application::GetConst("Environment"); }}}
- };
-
[config] bool accept_config;
[config] bool accept_commands;