]> granicus.if.org Git - icinga2/commitdiff
Report failed reload attempts for the icinga check
authorGunnar Beutner <gunnar.beutner@netways.de>
Wed, 11 May 2016 14:07:28 +0000 (16:07 +0200)
committerGunnar Beutner <gunnar.beutner@netways.de>
Wed, 11 May 2016 14:07:28 +0000 (16:07 +0200)
fixes #9060
fixes #9997
fixes #11129

lib/base/application.cpp
lib/base/application.hpp
lib/methods/icingachecktask.cpp

index c9e2c7c334d54f9fc8109a92de3073418f9ce299..77c610216e63bbd54076d82653f7ff723c1130d2 100644 (file)
@@ -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);
index 2174d3e03dede0f9fcfa8328ea56c2c7006ae98a..9e5bb3d141c83befa689bc87bf79b7c923b2c1a7 100644 (file)
@@ -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);
index 9ce8797f0eb98b92fd79019738b725733064be05..89642a39dfb1f7dea1085ce258e14ada40b96504 100644 (file)
@@ -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);
 }