Introduce the 'Environment' variable

This commit is contained in:
Gunnar Beutner 2018-05-15 10:27:13 +02:00
parent 303d9c61c8
commit 9c1e00eb94
4 changed files with 12 additions and 2 deletions

View File

@ -400,6 +400,7 @@ BuildCompilerVersion|**Read-only.** The version of the compiler Icinga was built
BuildHostName |**Read-only.** The name of the host Icinga was built on, e.g. "acheron".
ApplicationVersion |**Read-only.** The application version, e.g. "2.9.0".
MaxConcurrentChecks |**Read-write**. The number of max checks run simultaneously. Defaults to 512.
Environment |**Read-write**. The name of the Icinga environment. Included in the SNI host name when making outbound connections. Defaults to "production".
Advanced runtime constants. Please only use them if advised by support or developers.

View File

@ -221,6 +221,8 @@ static int Main()
Application::DeclareConcurrency(std::thread::hardware_concurrency());
Application::DeclareMaxConcurrentChecks(Application::GetDefaultMaxConcurrentChecks());
ScriptGlobal::Set("Environment", "production");
ScriptGlobal::Set("AttachDebugger", false);
ScriptGlobal::Set("PlatformKernel", Utility::GetPlatformKernel());

View File

@ -81,7 +81,8 @@ void IcingaApplication::StatsFunc(const Dictionary::Ptr& status, const Array::Pt
{ "enable_perfdata", icingaapplication->GetEnablePerfdata() },
{ "pid", Utility::GetPid() },
{ "program_start", Application::GetStartTime() },
{ "version", Application::GetAppVersion() }
{ "version", Application::GetAppVersion() },
{ "environment", ScriptGlobal::Get("Environment", &Empty) }
}));
}

View File

@ -382,10 +382,16 @@ void ApiListener::AddConnection(const Endpoint::Ptr& endpoint)
TcpSocket::Ptr client = new TcpSocket();
String serverName = endpoint->GetName();
String env = ScriptGlobal::Get("Environment", &Empty);
if (env != "" && env != "production")
serverName += ":" + env;
try {
endpoint->SetConnecting(true);
client->Connect(host, port);
NewClientHandler(client, endpoint->GetName(), RoleClient);
NewClientHandler(client, serverName, RoleClient);
endpoint->SetConnecting(false);
} catch (const std::exception& ex) {
endpoint->SetConnecting(false);