1
0
mirror of https://github.com/Icinga/icinga2.git synced 2025-04-08 17:05:25 +02:00

Add IcingaNodeName script variable, set as check source (WIP).

Fixes 
Fixes 
This commit is contained in:
Michael Friedrich 2014-02-06 15:27:50 +01:00
parent d22995657c
commit 1e0a11c7f2
8 changed files with 25 additions and 0 deletions

@ -11,6 +11,7 @@ IcingaPkgDataDir |**Read-only.** Contains the path of the package data
IcingaStatePath |**Read-write.** Contains the path of the Icinga 2 state file. Defaults to IcingaLocalStateDir + "/lib/icinga2/icinga2.state".
IcingaPidPath |**Read-write.** Contains the path of the Icinga 2 PID file. Defaults to IcingaLocalStateDir + "/run/icinga2/icinga2.pid".
IcingaMacros |**Read-write.** Contains a dictionary with global macros. Not set by default.
IcingaNodeName |**Read-write.** Contains the cluster node name. Set to the local hostname by default.
ApplicationType |**Read-write.** Contains the name of the Application type. Defaults to "icinga/IcingaApplication".
IcingaEnableNotifications |**Read-write.** Whether notifications are globally enabled. Defaults to true.
IcingaEnableEventHandlers |**Read-write.** Whether event handlers are globally enabled. Defaults to true.

@ -755,6 +755,16 @@ int Utility::CompareVersion(const String& v1, const String& v2)
return 0;
}
String Utility::GetHostName(void)
{
char name[255];
if (gethostname(name, sizeof(name)) < 0)
strcpy(name, "<unknown host>");
return String(name);
}
int Utility::Random(void)
{
#ifdef _WIN32

@ -108,6 +108,8 @@ public:
static int Random(void);
static String GetHostName(void);
static tm LocalTime(time_t ts);
private:

@ -42,6 +42,7 @@ void IcingaApplication::StaticInitialize(void)
ScriptVariable::Set("IcingaEnableFlapping", true);
ScriptVariable::Set("IcingaEnableChecks", true);
ScriptVariable::Set("IcingaEnablePerfdata", true);
ScriptVariable::Set("IcingaNodeName", Utility::GetHostName());
}
/**
@ -93,6 +94,11 @@ Dictionary::Ptr IcingaApplication::GetMacros(void) const
return ScriptVariable::Get("IcingaMacros");
}
String IcingaApplication::GetIcingaNodeName(void) const
{
return ScriptVariable::Get("IcingaNodeName");
}
bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
{
double now = Utility::GetTime();

@ -46,6 +46,7 @@ public:
String GetPidPath(void) const;
Dictionary::Ptr GetMacros(void) const;
String GetIcingaNodeName(void) const;
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;

@ -20,6 +20,7 @@
#include "methods/icingachecktask.h"
#include "icinga/cib.h"
#include "icinga/service.h"
#include "icinga/icingaapplication.h"
#include "base/application.h"
#include "base/utility.h"
#include "base/scriptfunction.h"
@ -64,6 +65,7 @@ CheckResult::Ptr IcingaCheckTask::ScriptFunc(const Service::Ptr&)
cr->SetOutput("Icinga 2 is running.");
cr->SetPerformanceData(perfdata);
cr->SetState(StateOK);
cr->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
return cr;
}

@ -79,6 +79,7 @@ CheckResult::Ptr PluginCheckTask::ScriptFunc(const Service::Ptr& service)
result->SetExitStatus(pr.ExitStatus);
result->SetExecutionStart(pr.ExecutionStart);
result->SetExecutionEnd(pr.ExecutionEnd);
result->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
return result;
}

@ -20,6 +20,7 @@
#ifndef _WIN32
# include <stdlib.h>
#endif /* _WIN32 */
#include "icinga/icingaapplication.h"
#include "methods/randomchecktask.h"
#include "base/utility.h"
#include "base/convert.h"
@ -47,6 +48,7 @@ CheckResult::Ptr RandomCheckTask::ScriptFunc(const Service::Ptr&)
cr->SetOutput(output);
cr->SetPerformanceData(perfdata);
cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
cr->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
return cr;
}