From ac57ed6cb4a25c8196a7def840db385bcd7339ef Mon Sep 17 00:00:00 2001 From: "Alexander A. Klimov" Date: Wed, 10 Aug 2022 11:40:53 +0200 Subject: [PATCH] IcingaDB::SendCustomVarsChanged(): don't delete custom vars of not synced types not to surprise (and crash) the Icinga DB daemon with unknown types. --- lib/icingadb/icingadb-objects.cpp | 10 ++++++++++ lib/icingadb/icingadb.hpp | 3 +++ 2 files changed, 13 insertions(+) diff --git a/lib/icingadb/icingadb-objects.cpp b/lib/icingadb/icingadb-objects.cpp index cce9bda02..28bab8acf 100644 --- a/lib/icingadb/icingadb-objects.cpp +++ b/lib/icingadb/icingadb-objects.cpp @@ -44,6 +44,8 @@ using namespace icinga; using Prio = RedisConnection::QueryPriority; +std::unordered_set IcingaDB::m_IndexedTypes; + INITIALIZE_ONCE(&IcingaDB::ConfigStaticInitialize); std::vector IcingaDB::GetTypes() @@ -74,6 +76,10 @@ std::vector IcingaDB::GetTypes() void IcingaDB::ConfigStaticInitialize() { + for (auto& type : GetTypes()) { + m_IndexedTypes.emplace(type.get()); + } + /* triggered in ProcessCheckResult(), requires UpdateNextCheck() to be called before */ Checkable::OnStateChange.connect([](const Checkable::Ptr& checkable, const CheckResult::Ptr& cr, StateType type, const MessageOrigin::Ptr&) { IcingaDB::StateChangeHandler(checkable, cr, type); @@ -2511,6 +2517,10 @@ void IcingaDB::SendCommandArgumentsChanged(const ConfigObject::Ptr& command, con } void IcingaDB::SendCustomVarsChanged(const ConfigObject::Ptr& object, const Dictionary::Ptr& oldValues, const Dictionary::Ptr& newValues) { + if (m_IndexedTypes.find(object->GetReflectionType().get()) == m_IndexedTypes.end()) { + return; + } + if (!m_Rcon || !m_Rcon->IsConnected() || oldValues == newValues) { return; } diff --git a/lib/icingadb/icingadb.hpp b/lib/icingadb/icingadb.hpp index c08f36465..21311453e 100644 --- a/lib/icingadb/icingadb.hpp +++ b/lib/icingadb/icingadb.hpp @@ -21,6 +21,7 @@ #include #include #include +#include #include namespace icinga @@ -232,6 +233,8 @@ private: // initialization, the value is read-only and can be accessed without further synchronization. static String m_EnvironmentId; static std::mutex m_EnvironmentIdInitMutex; + + static std::unordered_set m_IndexedTypes; }; }