]> granicus.if.org Git - icinga2/commitdiff
Add IcingaNodeName script variable, set as check source (WIP).
authorMichael Friedrich <michael.friedrich@netways.de>
Thu, 6 Feb 2014 14:27:50 +0000 (15:27 +0100)
committerMichael Friedrich <michael.friedrich@netways.de>
Thu, 6 Feb 2014 14:38:06 +0000 (15:38 +0100)
Fixes #5471
Fixes #5473

doc/4.2-global-variables.md
lib/base/utility.cpp
lib/base/utility.h
lib/icinga/icingaapplication.cpp
lib/icinga/icingaapplication.h
lib/methods/icingachecktask.cpp
lib/methods/pluginchecktask.cpp
lib/methods/randomchecktask.cpp

index d550b87432833b3eb4c9bb7434923c5bf4b0fbe7..98c82c856c0eac083be418fd2cd19deb6c102c57 100644 (file)
@@ -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.
index de010ac4dde4302bec9a3e3b48f1ca349255b297..d8025d6d0678a3a69f56d9d70c62a48384267ce6 100644 (file)
@@ -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
index 6ae981e1f8555f034192f67a01c44d85e31e0133..c0354f534a75422c08c8bbcb963f6df3a9a29936 100644 (file)
@@ -108,6 +108,8 @@ public:
 
        static int Random(void);
 
+       static String GetHostName(void);
+
        static tm LocalTime(time_t ts);
 
 private:
index 2a566091c1928b307310c3a2f2fbd32d42078764..cef46b7266267458fe51030c8bab630a020deb39 100644 (file)
@@ -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();
index 02e85c29f7f676d87feaa8d732243e3472ac8c24..c8b6be81c11d1e131b82c80b076b4f9895d8687b 100644 (file)
@@ -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;
 
index afee0ba3da1533341a82ea5bebaaf19c837f2115..a165d2133161fbc3a4e93fe5e08e6f83241a5402 100644 (file)
@@ -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;
 }
index 2bf0b03978efc46fc7527b25e9e2e45656ea5e7a..0456cc31c6945ce705398800a8cd4a8e67fe3ac3 100644 (file)
@@ -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;
 }
index 561d67cb7a85fddbdb762115bed55a4af7a20852..16e4f9eeef37a04139ba5d67c25efee51ee79aee 100644 (file)
@@ -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;
 }