mirror of
https://github.com/Icinga/icinga2.git
synced 2025-07-30 17:14:25 +02:00
Add IcingaNodeName script variable, set as check source (WIP).
Fixes #5471 Fixes #5473
This commit is contained in:
parent
d22995657c
commit
1e0a11c7f2
@ -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".
|
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".
|
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.
|
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".
|
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.
|
IcingaEnableNotifications |**Read-write.** Whether notifications are globally enabled. Defaults to true.
|
||||||
IcingaEnableEventHandlers |**Read-write.** Whether event handlers 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;
|
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)
|
int Utility::Random(void)
|
||||||
{
|
{
|
||||||
#ifdef _WIN32
|
#ifdef _WIN32
|
||||||
|
@ -108,6 +108,8 @@ public:
|
|||||||
|
|
||||||
static int Random(void);
|
static int Random(void);
|
||||||
|
|
||||||
|
static String GetHostName(void);
|
||||||
|
|
||||||
static tm LocalTime(time_t ts);
|
static tm LocalTime(time_t ts);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
@ -42,6 +42,7 @@ void IcingaApplication::StaticInitialize(void)
|
|||||||
ScriptVariable::Set("IcingaEnableFlapping", true);
|
ScriptVariable::Set("IcingaEnableFlapping", true);
|
||||||
ScriptVariable::Set("IcingaEnableChecks", true);
|
ScriptVariable::Set("IcingaEnableChecks", true);
|
||||||
ScriptVariable::Set("IcingaEnablePerfdata", true);
|
ScriptVariable::Set("IcingaEnablePerfdata", true);
|
||||||
|
ScriptVariable::Set("IcingaNodeName", Utility::GetHostName());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -93,6 +94,11 @@ Dictionary::Ptr IcingaApplication::GetMacros(void) const
|
|||||||
return ScriptVariable::Get("IcingaMacros");
|
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
|
bool IcingaApplication::ResolveMacro(const String& macro, const CheckResult::Ptr&, String *result) const
|
||||||
{
|
{
|
||||||
double now = Utility::GetTime();
|
double now = Utility::GetTime();
|
||||||
|
@ -46,6 +46,7 @@ public:
|
|||||||
|
|
||||||
String GetPidPath(void) const;
|
String GetPidPath(void) const;
|
||||||
Dictionary::Ptr GetMacros(void) const;
|
Dictionary::Ptr GetMacros(void) const;
|
||||||
|
String GetIcingaNodeName(void) const;
|
||||||
|
|
||||||
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
|
virtual bool ResolveMacro(const String& macro, const CheckResult::Ptr& cr, String *result) const;
|
||||||
|
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#include "methods/icingachecktask.h"
|
#include "methods/icingachecktask.h"
|
||||||
#include "icinga/cib.h"
|
#include "icinga/cib.h"
|
||||||
#include "icinga/service.h"
|
#include "icinga/service.h"
|
||||||
|
#include "icinga/icingaapplication.h"
|
||||||
#include "base/application.h"
|
#include "base/application.h"
|
||||||
#include "base/utility.h"
|
#include "base/utility.h"
|
||||||
#include "base/scriptfunction.h"
|
#include "base/scriptfunction.h"
|
||||||
@ -64,6 +65,7 @@ CheckResult::Ptr IcingaCheckTask::ScriptFunc(const Service::Ptr&)
|
|||||||
cr->SetOutput("Icinga 2 is running.");
|
cr->SetOutput("Icinga 2 is running.");
|
||||||
cr->SetPerformanceData(perfdata);
|
cr->SetPerformanceData(perfdata);
|
||||||
cr->SetState(StateOK);
|
cr->SetState(StateOK);
|
||||||
|
cr->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
|
||||||
|
|
||||||
return cr;
|
return cr;
|
||||||
}
|
}
|
||||||
|
@ -79,6 +79,7 @@ CheckResult::Ptr PluginCheckTask::ScriptFunc(const Service::Ptr& service)
|
|||||||
result->SetExitStatus(pr.ExitStatus);
|
result->SetExitStatus(pr.ExitStatus);
|
||||||
result->SetExecutionStart(pr.ExecutionStart);
|
result->SetExecutionStart(pr.ExecutionStart);
|
||||||
result->SetExecutionEnd(pr.ExecutionEnd);
|
result->SetExecutionEnd(pr.ExecutionEnd);
|
||||||
|
result->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
@ -20,6 +20,7 @@
|
|||||||
#ifndef _WIN32
|
#ifndef _WIN32
|
||||||
# include <stdlib.h>
|
# include <stdlib.h>
|
||||||
#endif /* _WIN32 */
|
#endif /* _WIN32 */
|
||||||
|
#include "icinga/icingaapplication.h"
|
||||||
#include "methods/randomchecktask.h"
|
#include "methods/randomchecktask.h"
|
||||||
#include "base/utility.h"
|
#include "base/utility.h"
|
||||||
#include "base/convert.h"
|
#include "base/convert.h"
|
||||||
@ -47,6 +48,7 @@ CheckResult::Ptr RandomCheckTask::ScriptFunc(const Service::Ptr&)
|
|||||||
cr->SetOutput(output);
|
cr->SetOutput(output);
|
||||||
cr->SetPerformanceData(perfdata);
|
cr->SetPerformanceData(perfdata);
|
||||||
cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
|
cr->SetState(static_cast<ServiceState>(Utility::Random() % 4));
|
||||||
|
cr->SetCheckSource(IcingaApplication::GetInstance()->GetIcingaNodeName());
|
||||||
|
|
||||||
return cr;
|
return cr;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user