]> granicus.if.org Git - icinga2/blobdiff - lib/icinga/checkable.cpp
Re-send suppressed notifications
[icinga2] / lib / icinga / checkable.cpp
index c577848d59ed34ba93e08ec7be6e5d5f40a7f24b..c4265d05f266ecb766577e6da45bc24488d7f9c1 100644 (file)
@@ -1,21 +1,4 @@
-/******************************************************************************
- * Icinga 2                                                                   *
- * Copyright (C) 2012-2018 Icinga Development Team (https://icinga.com/)      *
- *                                                                            *
- * This program is free software; you can redistribute it and/or              *
- * modify it under the terms of the GNU General Public License                *
- * as published by the Free Software Foundation; either version 2             *
- * of the License, or (at your option) any later version.                     *
- *                                                                            *
- * This program is distributed in the hope that it will be useful,            *
- * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the              *
- * GNU General Public License for more details.                               *
- *                                                                            *
- * You should have received a copy of the GNU General Public License          *
- * along with this program; if not, write to the Free Software Foundation     *
- * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.             *
- ******************************************************************************/
+/* Icinga 2 | (c) 2012 Icinga GmbH | GPLv2+ */
 
 #include "icinga/checkable.hpp"
 #include "icinga/checkable-ti.cpp"
@@ -24,6 +7,8 @@
 #include "base/objectlock.hpp"
 #include "base/utility.hpp"
 #include "base/exception.hpp"
+#include "base/timer.hpp"
+#include <boost/thread/once.hpp>
 
 using namespace icinga;
 
@@ -33,6 +18,8 @@ INITIALIZE_ONCE(&Checkable::StaticInitialize);
 boost::signals2::signal<void (const Checkable::Ptr&, const String&, const String&, AcknowledgementType, bool, bool, double, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementSet;
 boost::signals2::signal<void (const Checkable::Ptr&, const MessageOrigin::Ptr&)> Checkable::OnAcknowledgementCleared;
 
+static Timer::Ptr l_CheckablesFireSuppressedNotifications;
+
 void Checkable::StaticInitialize()
 {
        /* fixed downtime start */
@@ -82,6 +69,15 @@ void Checkable::Start(bool runtimeCreated)
        }
 
        ObjectImpl<Checkable>::Start(runtimeCreated);
+
+       static boost::once_flag once = BOOST_ONCE_INIT;
+
+       boost::call_once(once, []() {
+               l_CheckablesFireSuppressedNotifications = new Timer();
+               l_CheckablesFireSuppressedNotifications->SetInterval(5);
+               l_CheckablesFireSuppressedNotifications->OnTimerExpired.connect(&Checkable::FireSuppressedNotifications);
+               l_CheckablesFireSuppressedNotifications->Start();
+       });
 }
 
 void Checkable::AddGroup(const String& name)
@@ -156,6 +152,16 @@ int Checkable::GetSeverity() const
        return 0;
 }
 
+bool Checkable::GetProblem() const
+{
+       return !IsStateOK(GetStateRaw());
+}
+
+bool Checkable::GetHandled() const
+{
+       return GetProblem() && (IsInDowntime() || IsAcknowledged());
+}
+
 void Checkable::NotifyFixedDowntimeStart(const Downtime::Ptr& downtime)
 {
        if (!downtime->GetFixed())