[icinga-checkins] icinga.org: icinga2/master: Report failed reload attempts for the icinga check

git at icinga.org git at icinga.org
Tue May 17 11:44:11 CEST 2016


Module: icinga2
Branch: master
Commit: ff24863a72bba0d136995c48c423e90427322772
URL:    https://git.icinga.org/?p=icinga2.git;a=commit;h=ff24863a72bba0d136995c48c423e90427322772

Author: Gunnar Beutner <gunnar.beutner at netways.de>
Date:   Wed May 11 16:07:28 2016 +0200

Report failed reload attempts for the icinga check

fixes #9060
fixes #9997
fixes #11129

---

 lib/base/application.cpp        |   15 ++++++++++++++-
 lib/base/application.hpp        |    4 ++++
 lib/methods/icingachecktask.cpp |    9 ++++++++-
 3 files changed, 26 insertions(+), 2 deletions(-)

diff --git a/lib/base/application.cpp b/lib/base/application.cpp
index c9e2c7c..77c6102 100644
--- a/lib/base/application.cpp
+++ b/lib/base/application.cpp
@@ -62,6 +62,7 @@ char **Application::m_ArgV;
 double Application::m_StartTime;
 double Application::m_MainTime;
 bool Application::m_ScriptDebuggerEnabled = false;
+double Application::m_LastReloadFailed;
 
 /**
  * Constructor for the Application class.
@@ -330,8 +331,10 @@ void Application::OnShutdown(void)
 
 static void ReloadProcessCallbackInternal(const ProcessResult& pr)
 {
-	if (pr.ExitStatus != 0)
+	if (pr.ExitStatus != 0) {
+		Application::SetLastReloadFailed(Utility::GetTime());
 		Log(LogCritical, "Application", "Found error in config: reloading aborted");
+	}
 #ifdef _WIN32
 	else
 		Application::Exit(7); /* keep this exit code in sync with icinga-app */
@@ -1387,6 +1390,16 @@ void Application::SetScriptDebuggerEnabled(bool enabled)
 	m_ScriptDebuggerEnabled = enabled;
 }
 
+double Application::GetLastReloadFailed(void)
+{
+	return m_LastReloadFailed;
+}
+
+void Application::SetLastReloadFailed(double ts)
+{
+	m_LastReloadFailed = ts;
+}
+
 void Application::ValidateName(const String& value, const ValidationUtils& utils)
 {
 	ObjectImpl<Application>::ValidateName(value, utils);
diff --git a/lib/base/application.hpp b/lib/base/application.hpp
index 2174d3e..9e5bb3d 100644
--- a/lib/base/application.hpp
+++ b/lib/base/application.hpp
@@ -140,6 +140,9 @@ public:
 	static bool GetScriptDebuggerEnabled(void);
 	static void SetScriptDebuggerEnabled(bool enabled);
 
+	static double GetLastReloadFailed(void);
+	static void SetLastReloadFailed(double ts);
+
 	static void DisplayInfoMessage(std::ostream& os, bool skipVersion = false);
 
 protected:
@@ -172,6 +175,7 @@ private:
 	static double m_StartTime;
 	static double m_MainTime;
 	static bool m_ScriptDebuggerEnabled;
+	static double m_LastReloadFailed;
 
 #ifndef _WIN32
 	static void SigIntTermHandler(int signum);
diff --git a/lib/methods/icingachecktask.cpp b/lib/methods/icingachecktask.cpp
index 9ce8797..89642a3 100644
--- a/lib/methods/icingachecktask.cpp
+++ b/lib/methods/icingachecktask.cpp
@@ -100,7 +100,14 @@ void IcingaCheckTask::ScriptFunc(const Checkable::Ptr& service, const CheckResul
 	cr->SetOutput("Icinga 2 has been running for " + Utility::FormatDuration(uptime) +
 	    ". Version: " + Application::GetAppVersion());
 	cr->SetPerformanceData(perfdata);
-	cr->SetState(ServiceOK);
+
+	double lastReloadFailed = Application::GetLastReloadFailed();
+
+	if (lastReloadFailed > 0) {
+		cr->SetOutput(cr->GetOutput() + "; Last reload attempt failed at " + Utility::FormatDateTime("%Y-%m-%d %H:%M:%S %z", lastReloadFailed));
+		cr->SetState(ServiceWarning);
+	} else
+		cr->SetState(ServiceOK);
 
 	service->ProcessCheckResult(cr);
 }



More information about the icinga-checkins mailing list