Merge pull request #6305 from gunnarbeutner/feature/environment-variable

Introduce the 'Environment' variable
This commit is contained in:
Michael Friedrich 2018-05-15 14:04:50 +02:00 committed by GitHub
commit 7f579db9af
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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);