diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index e31988837..32cf7edc3 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -68,6 +68,9 @@ void IcingaDB::ConfigStaticInitialize() AcknowledgementClearedHandler(checkable, removedBy, changeTime); }); + Checkable::OnAcknowledgementSet.connect([](const Checkable::Ptr& checkable, const String& author, const String& comment, AcknowledgementType type, bool, bool persistent, double changeTime, double expiry, const MessageOrigin::Ptr&) { + IcingaDB::StateChangeHandler(checkable); + }); /* triggered when acknowledged host/service goes back to ok and when the acknowledgement gets deleted */ Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const String&, double, const MessageOrigin::Ptr&) { IcingaDB::StateChangeHandler(checkable); @@ -102,6 +105,7 @@ void IcingaDB::ConfigStaticInitialize() Checkable::OnNewCheckResult.connect([](const Checkable::Ptr& checkable, const CheckResult::Ptr&, const MessageOrigin::Ptr&) { IcingaDB::NewCheckResultHandler(checkable); }); + Checkable::OnNextCheckChanged.connect([](const Checkable::Ptr& checkable, const Value&) { IcingaDB::NextCheckChangedHandler(checkable); }); @@ -2044,6 +2048,7 @@ void IcingaDB::FlappingChangeHandler(const Checkable::Ptr& checkable, double cha void IcingaDB::NewCheckResultHandler(const Checkable::Ptr& checkable) { for (auto& rw : ConfigType::GetObjectsByType()) { + rw->UpdateState(checkable); rw->SendNextUpdate(checkable); } } diff --git a/lib/icingadb/icingadb.cpp b/lib/icingadb/icingadb.cpp index 96ddcb3fb..6e68084b7 100644 --- a/lib/icingadb/icingadb.cpp +++ b/lib/icingadb/icingadb.cpp @@ -81,9 +81,6 @@ void IcingaDB::Start(bool runtimeCreated) m_WorkQueue.SetName("IcingaDB"); - boost::thread thread(&IcingaDB::HandleEvents, this); - thread.detach(); - m_Rcon->SuppressQueryKind(Prio::CheckResult); m_Rcon->SuppressQueryKind(Prio::State); } @@ -156,86 +153,6 @@ void IcingaDB::PublishStats() m_Rcon->FireAndForgetQuery(std::move(eval), Prio::Heartbeat); } -void IcingaDB::HandleEvents() -{ - String queueName = Utility::NewUniqueID(); - EventQueue::Ptr queue = new EventQueue(queueName); - EventQueue::Register(queueName, queue); - - std::set types; - types.insert("CheckResult"); - types.insert("AcknowledgementSet"); - types.insert("AcknowledgementCleared"); - - queue->SetTypes(types); - - queue->AddClient(this); - - for (;;) { - Dictionary::Ptr event = queue->WaitForEvent(this); - - if (!event) - continue; - - m_WorkQueue.Enqueue([this, event]() { SendEvent(event); }); - } - - queue->RemoveClient(this); - EventQueue::UnregisterIfUnused(queueName, queue); -} - -void IcingaDB::SendEvent(const Dictionary::Ptr& event) -{ - AssertOnWorkQueue(); - - if (!m_Rcon || !m_Rcon->IsConnected()) - return; - - String type = event->Get("type"); - - if (type == "CheckResult") { - Checkable::Ptr checkable; - - if (event->Contains("service")) { - checkable = Service::GetByNamePair(event->Get("host"), event->Get("service")); - } else { - checkable = Host::GetByName(event->Get("host")); - } - - // Update State for icingaweb - m_WorkQueue.Enqueue([this, checkable]() { UpdateState(checkable); }); - } - - if (type.Contains("Acknowledgement")) { - Checkable::Ptr checkable; - - if (event->Contains("service")) { - checkable = Service::GetByNamePair(event->Get("host"), event->Get("service")); - event->Set("service_id", GetObjectIdentifier(checkable)); - } else { - checkable = Host::GetByName(event->Get("host")); - event->Set("host_id", GetObjectIdentifier(checkable)); - } - - if (type == "AcknowledgementSet") { - Timestamp entry = 0; - Comment::Ptr AckComment; - - for (const Comment::Ptr& c : checkable->GetComments()) { - if (c->GetEntryType() == CommentAcknowledgement) { - if (c->GetEntryTime() > entry) { - entry = c->GetEntryTime(); - AckComment = c; - StateChangeHandler(checkable); - } - } - } - - event->Set("comment_id", GetObjectIdentifier(AckComment)); - } - } -} - void IcingaDB::Stop(bool runtimeRemoved) { Log(LogInformation, "IcingaDB") diff --git a/lib/icingadb/icingadb.hpp b/lib/icingadb/icingadb.hpp index 8f40a273e..41fd0963c 100644 --- a/lib/icingadb/icingadb.hpp +++ b/lib/icingadb/icingadb.hpp @@ -37,8 +37,6 @@ public: private: void ReconnectTimerHandler(); void TryToReconnect(); - void HandleEvents(); - void SendEvent(const Dictionary::Ptr& event); void PublishStatsTimerHandler(); void PublishStats();