diff --git a/etc/icinga2/features-available/redis.conf b/etc/icinga2/features-available/redis.conf index bcf781ad2..4be873ef3 100644 --- a/etc/icinga2/features-available/redis.conf +++ b/etc/icinga2/features-available/redis.conf @@ -7,7 +7,7 @@ library "redis" -object RedisWriter "redis" { +object IcingaDB "redis" { //host = "127.0.0.1" //port = 6379 //password = "xxx" diff --git a/lib/icinga/compatutility.cpp b/lib/icinga/compatutility.cpp index 5945ebfaf..40c01f397 100644 --- a/lib/icinga/compatutility.cpp +++ b/lib/icinga/compatutility.cpp @@ -249,7 +249,7 @@ std::set CompatUtility::GetCheckableNotificationUserGroups(const return usergroups; } -/* Used in DB IDO, StatusDataWriter, Livestatus, CompatLogger, GelfWriter, RedisWriter. */ +/* Used in DB IDO, StatusDataWriter, Livestatus, CompatLogger, GelfWriter, IcingaDB. */ String CompatUtility::GetCheckResultOutput(const CheckResult::Ptr& cr) { if (!cr) @@ -264,7 +264,7 @@ String CompatUtility::GetCheckResultOutput(const CheckResult::Ptr& cr) return raw_output.SubStr(0, line_end); } -/* Used in DB IDO, StatusDataWriter and Livestatus, RedisWriter. */ +/* Used in DB IDO, StatusDataWriter and Livestatus, IcingaDB. */ String CompatUtility::GetCheckResultLongOutput(const CheckResult::Ptr& cr) { if (!cr) diff --git a/lib/redis/redisconnection.cpp b/lib/redis/redisconnection.cpp index a3248c8c0..7445a2a8b 100644 --- a/lib/redis/redisconnection.cpp +++ b/lib/redis/redisconnection.cpp @@ -88,7 +88,7 @@ void LogQuery(RedisConnection::Query& query, Log& msg) void RedisConnection::FireAndForgetQuery(RedisConnection::Query query) { { - Log msg (LogNotice, "RedisWriter", "Firing and forgetting query:"); + Log msg (LogNotice, "IcingaDB", "Firing and forgetting query:"); LogQuery(query, msg); } @@ -103,7 +103,7 @@ void RedisConnection::FireAndForgetQuery(RedisConnection::Query query) void RedisConnection::FireAndForgetQueries(RedisConnection::Queries queries) { for (auto& query : queries) { - Log msg (LogNotice, "RedisWriter", "Firing and forgetting query:"); + Log msg (LogNotice, "IcingaDB", "Firing and forgetting query:"); LogQuery(query, msg); } @@ -118,7 +118,7 @@ void RedisConnection::FireAndForgetQueries(RedisConnection::Queries queries) RedisConnection::Reply RedisConnection::GetResultOfQuery(RedisConnection::Query query) { { - Log msg (LogNotice, "RedisWriter", "Executing query:"); + Log msg (LogNotice, "IcingaDB", "Executing query:"); LogQuery(query, msg); } @@ -139,7 +139,7 @@ RedisConnection::Reply RedisConnection::GetResultOfQuery(RedisConnection::Query RedisConnection::Replies RedisConnection::GetResultsOfQueries(RedisConnection::Queries queries) { for (auto& query : queries) { - Log msg (LogNotice, "RedisWriter", "Executing query:"); + Log msg (LogNotice, "IcingaDB", "Executing query:"); LogQuery(query, msg); } @@ -161,7 +161,7 @@ void RedisConnection::Connect(asio::yield_context& yc) { Defer notConnecting ([this]() { m_Connecting.store(m_Connected.load()); }); - Log(LogInformation, "RedisWriter", "Trying to connect to Redis server (async)"); + Log(LogInformation, "IcingaDB", "Trying to connect to Redis server (async)"); try { if (m_Path.IsEmpty()) { @@ -176,11 +176,11 @@ void RedisConnection::Connect(asio::yield_context& yc) m_Connected.store(true); - Log(LogInformation, "RedisWriter", "Connected to Redis server"); + Log(LogInformation, "IcingaDB", "Connected to Redis server"); } catch (const boost::coroutines::detail::forced_unwind&) { throw; } catch (const std::exception& ex) { - Log(LogCritical, "RedisWriter") + Log(LogCritical, "IcingaDB") << "Cannot connect to " << m_Host << ":" << m_Port << ": " << ex.what(); } } @@ -203,11 +203,11 @@ void RedisConnection::ReadLoop(asio::yield_context& yc) } catch (const boost::coroutines::detail::forced_unwind&) { throw; } catch (const std::exception& ex) { - Log(LogCritical, "RedisWriter") + Log(LogCritical, "IcingaDB") << "Error during receiving the response to a query which has been fired and forgotten: " << ex.what(); continue; } catch (...) { - Log(LogCritical, "RedisWriter") + Log(LogCritical, "IcingaDB") << "Error during receiving the response to a query which has been fired and forgotten"; continue; } @@ -276,12 +276,12 @@ void RedisConnection::WriteLoop(asio::yield_context& yc) } catch (const boost::coroutines::detail::forced_unwind&) { throw; } catch (const std::exception& ex) { - Log msg (LogCritical, "RedisWriter", "Error during sending query"); + Log msg (LogCritical, "IcingaDB", "Error during sending query"); LogQuery(item, msg); msg << " which has been fired and forgotten: " << ex.what(); continue; } catch (...) { - Log msg (LogCritical, "RedisWriter", "Error during sending query"); + Log msg (LogCritical, "IcingaDB", "Error during sending query"); LogQuery(item, msg); msg << " which has been fired and forgotten"; continue; @@ -308,12 +308,12 @@ void RedisConnection::WriteLoop(asio::yield_context& yc) } catch (const boost::coroutines::detail::forced_unwind&) { throw; } catch (const std::exception& ex) { - Log msg (LogCritical, "RedisWriter", "Error during sending query"); + Log msg (LogCritical, "IcingaDB", "Error during sending query"); LogQuery(item[i], msg); msg << " which has been fired and forgotten: " << ex.what(); continue; } catch (...) { - Log msg (LogCritical, "RedisWriter", "Error during sending query"); + Log msg (LogCritical, "IcingaDB", "Error during sending query"); LogQuery(item[i], msg); msg << " which has been fired and forgotten"; continue; diff --git a/lib/redis/rediswriter-objects.cpp b/lib/redis/rediswriter-objects.cpp index 6cb41a5e3..b6f9424f4 100644 --- a/lib/redis/rediswriter-objects.cpp +++ b/lib/redis/rediswriter-objects.cpp @@ -65,49 +65,49 @@ return id )EOF"; -INITIALIZE_ONCE(&RedisWriter::ConfigStaticInitialize); +INITIALIZE_ONCE(&IcingaDB::ConfigStaticInitialize); -void RedisWriter::ConfigStaticInitialize() +void IcingaDB::ConfigStaticInitialize() { /* 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&) { - RedisWriter::StateChangeHandler(checkable, cr, type); + IcingaDB::StateChangeHandler(checkable, cr, type); }); /* triggered when acknowledged host/service goes back to ok and when the acknowledgement gets deleted */ Checkable::OnAcknowledgementCleared.connect([](const Checkable::Ptr& checkable, const MessageOrigin::Ptr&) { - RedisWriter::StateChangeHandler(checkable); + IcingaDB::StateChangeHandler(checkable); }); /* triggered on create, update and delete objects */ ConfigObject::OnActiveChanged.connect([](const ConfigObject::Ptr& object, const Value&) { - RedisWriter::VersionChangedHandler(object); + IcingaDB::VersionChangedHandler(object); }); ConfigObject::OnVersionChanged.connect([](const ConfigObject::Ptr& object, const Value&) { - RedisWriter::VersionChangedHandler(object); + IcingaDB::VersionChangedHandler(object); }); /* fixed/flexible downtime add */ - Downtime::OnDowntimeAdded.connect(&RedisWriter::DowntimeAddedHandler); + Downtime::OnDowntimeAdded.connect(&IcingaDB::DowntimeAddedHandler); /* fixed downtime start */ - Downtime::OnDowntimeStarted.connect(&RedisWriter::DowntimeStartedHandler); + Downtime::OnDowntimeStarted.connect(&IcingaDB::DowntimeStartedHandler); /* flexible downtime start */ - Downtime::OnDowntimeTriggered.connect(&RedisWriter::DowntimeStartedHandler); + Downtime::OnDowntimeTriggered.connect(&IcingaDB::DowntimeStartedHandler); /* fixed/flexible downtime end or remove */ - Downtime::OnDowntimeRemoved.connect(&RedisWriter::DowntimeRemovedHandler); + Downtime::OnDowntimeRemoved.connect(&IcingaDB::DowntimeRemovedHandler); Checkable::OnNotificationSentToAllUsers.connect([]( const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set& users, const NotificationType& type, const CheckResult::Ptr& cr, const String& author, const String& text, const MessageOrigin::Ptr& ) { - RedisWriter::NotificationSentToAllUsersHandler(notification, checkable, users, type, cr, author, text); + IcingaDB::NotificationSentToAllUsersHandler(notification, checkable, users, type, cr, author, text); }); - Comment::OnCommentAdded.connect(&RedisWriter::CommentAddedHandler); - Comment::OnCommentRemoved.connect(&RedisWriter::CommentRemovedHandler); + Comment::OnCommentAdded.connect(&IcingaDB::CommentAddedHandler); + Comment::OnCommentRemoved.connect(&IcingaDB::CommentRemovedHandler); - Checkable::OnFlappingChanged.connect(&RedisWriter::FlappingChangedHandler); + Checkable::OnFlappingChanged.connect(&IcingaDB::FlappingChangedHandler); } static std::pair SplitOutput(String output) @@ -123,13 +123,13 @@ static std::pair SplitOutput(String output) return {std::move(output), std::move(longOutput)}; } -void RedisWriter::UpdateAllConfigObjects() +void IcingaDB::UpdateAllConfigObjects() { double startTime = Utility::GetTime(); // Use a Workqueue to pack objects in parallel WorkQueue upq(25000, Configuration::Concurrency); - upq.SetName("RedisWriter:ConfigDump"); + upq.SetName("IcingaDB:ConfigDump"); typedef std::pair TypePair; std::vector types; @@ -162,7 +162,7 @@ void RedisWriter::UpdateAllConfigObjects() auto objectChunks (ChunkObjects(type.first->GetObjects(), 500)); WorkQueue upqObjectType(25000, Configuration::Concurrency); - upqObjectType.SetName("RedisWriter:ConfigDump:" + lcType); + upqObjectType.SetName("IcingaDB:ConfigDump:" + lcType); upqObjectType.ParallelFor(objectChunks, [this, &type, &lcType](decltype(objectChunks)::const_reference chunk) { std::map> hMSets, publishes; @@ -250,7 +250,7 @@ void RedisWriter::UpdateAllConfigObjects() m_Rcon->FireAndForgetQueries(std::move(transaction)); } - Log(LogNotice, "RedisWriter") + Log(LogNotice, "IcingaDB") << "Dumped " << bulkCounter << " objects of type " << type.second; }); @@ -276,7 +276,7 @@ void RedisWriter::UpdateAllConfigObjects() boost::rethrow_exception(exc); } } catch(const std::exception& e) { - Log(LogCritical, "RedisWriter") + Log(LogCritical, "IcingaDB") << "Exception during ConfigDump: " << e.what(); } } @@ -284,11 +284,11 @@ void RedisWriter::UpdateAllConfigObjects() m_Rcon->FireAndForgetQuery({"XADD", "icinga:dump", "*", "type", "*", "state", "done"}); - Log(LogInformation, "RedisWriter") + Log(LogInformation, "IcingaDB") << "Initial config/status dump finished in " << Utility::GetTime() - startTime << " seconds."; } -std::vector>> RedisWriter::ChunkObjects(std::vector> objects, size_t chunkSize) { +std::vector>> IcingaDB::ChunkObjects(std::vector> objects, size_t chunkSize) { std::vector>> chunks; auto offset (objects.begin()); auto end (objects.end()); @@ -308,7 +308,7 @@ std::vector>> RedisWriter::ChunkObjects( return std::move(chunks); } -void RedisWriter::DeleteKeys(const std::vector& keys) { +void IcingaDB::DeleteKeys(const std::vector& keys) { std::vector query = {"DEL"}; for (auto& key : keys) { query.emplace_back(key); @@ -317,7 +317,7 @@ void RedisWriter::DeleteKeys(const std::vector& keys) { m_Rcon->FireAndForgetQuery(std::move(query)); } -std::vector RedisWriter::GetTypeObjectKeys(const String& type) +std::vector IcingaDB::GetTypeObjectKeys(const String& type) { std::vector keys = { m_PrefixConfigObject + type, @@ -361,7 +361,7 @@ static ConfigObject::Ptr GetObjectByName(const String& name) return ConfigObject::GetObject(name); } -void RedisWriter::InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map>& hMSets, +void IcingaDB::InsertObjectDependencies(const ConfigObject::Ptr& object, const String typeName, std::map>& hMSets, std::map>& publishes, bool runtimeUpdate) { String objectKey = GetObjectIdentifier(object); @@ -780,7 +780,7 @@ void RedisWriter::InsertObjectDependencies(const ConfigObject::Ptr& object, cons } } -void RedisWriter::UpdateState(const Checkable::Ptr& checkable) +void IcingaDB::UpdateState(const Checkable::Ptr& checkable) { Dictionary::Ptr stateAttrs = SerializeState(checkable); @@ -788,7 +788,7 @@ void RedisWriter::UpdateState(const Checkable::Ptr& checkable) } // Used to update a single object, used for runtime updates -void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool runtimeUpdate) +void IcingaDB::SendConfigUpdate(const ConfigObject::Ptr& object, bool runtimeUpdate) { if (!m_Rcon || !m_Rcon->IsConnected()) return; @@ -836,7 +836,7 @@ void RedisWriter::SendConfigUpdate(const ConfigObject::Ptr& object, bool runtime // Takes object and collects IcingaDB relevant attributes and computes checksums. Returns whether the object is relevant // for IcingaDB. -bool RedisWriter::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& attributes, Dictionary::Ptr& checksums) +bool IcingaDB::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr& attributes, Dictionary::Ptr& checksums) { attributes->Set("name_checksum", CalculateCheckSumString(object->GetName())); attributes->Set("environment_id", CalculateCheckSumString(GetEnvironment())); @@ -1093,7 +1093,7 @@ bool RedisWriter::PrepareObject(const ConfigObject::Ptr& object, Dictionary::Ptr * icinga:config:object:downtime) need to be prepended. There is nothing to indicate success or failure. */ void -RedisWriter::CreateConfigUpdate(const ConfigObject::Ptr& object, const String typeName, std::map>& hMSets, +IcingaDB::CreateConfigUpdate(const ConfigObject::Ptr& object, const String typeName, std::map>& hMSets, std::map>& publishes, bool runtimeUpdate) { /* TODO: This isn't essentially correct as we don't keep track of config objects ourselves. This would avoid duplicated config updates at startup. @@ -1128,7 +1128,7 @@ RedisWriter::CreateConfigUpdate(const ConfigObject::Ptr& object, const String ty } } -void RedisWriter::SendConfigDelete(const ConfigObject::Ptr& object) +void IcingaDB::SendConfigDelete(const ConfigObject::Ptr& object) { String typeName = object->GetReflectionType()->GetName().ToLower(); String objectKey = GetObjectIdentifier(object); @@ -1152,7 +1152,7 @@ unsigned short GetPreviousHardState(const Checkable::Ptr& checkable, const Servi } } -void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type) +void IcingaDB::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type) { if (!m_Rcon || !m_Rcon->IsConnected()) return; @@ -1228,7 +1228,7 @@ void RedisWriter::SendStatusUpdate(const ConfigObject::Ptr& object, const CheckR m_Rcon->FireAndForgetQuery(std::move(xAdd)); } -void RedisWriter::SendSentNotification( +void IcingaDB::SendSentNotification( const Notification::Ptr& notification, const Checkable::Ptr& checkable, size_t users, NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text ) @@ -1276,7 +1276,7 @@ void RedisWriter::SendSentNotification( m_Rcon->FireAndForgetQuery(std::move(xAdd)); } -void RedisWriter::SendAddedDowntime(const Downtime::Ptr& downtime) +void IcingaDB::SendAddedDowntime(const Downtime::Ptr& downtime) { if (!m_Rcon || !m_Rcon->IsConnected()) return; @@ -1343,7 +1343,7 @@ void RedisWriter::SendAddedDowntime(const Downtime::Ptr& downtime) m_Rcon->FireAndForgetQuery(std::move(xAdd)); } -void RedisWriter::SendStartedDowntime(const Downtime::Ptr& downtime) +void IcingaDB::SendStartedDowntime(const Downtime::Ptr& downtime) { if (!m_Rcon || !m_Rcon->IsConnected()) return; @@ -1412,7 +1412,7 @@ void RedisWriter::SendStartedDowntime(const Downtime::Ptr& downtime) m_Rcon->FireAndForgetQuery(std::move(xAdd)); } -void RedisWriter::SendRemovedDowntime(const Downtime::Ptr& downtime) +void IcingaDB::SendRemovedDowntime(const Downtime::Ptr& downtime) { if (!m_Rcon || !m_Rcon->IsConnected()) return; @@ -1480,7 +1480,7 @@ void RedisWriter::SendRemovedDowntime(const Downtime::Ptr& downtime) m_Rcon->FireAndForgetQuery(std::move(xAdd)); } -void RedisWriter::SendAddedComment(const Comment::Ptr& comment) +void IcingaDB::SendAddedComment(const Comment::Ptr& comment) { if (!m_Rcon || !m_Rcon->IsConnected()) return; @@ -1524,7 +1524,7 @@ void RedisWriter::SendAddedComment(const Comment::Ptr& comment) m_Rcon->FireAndForgetQuery(std::move(xAdd)); } -void RedisWriter::SendRemovedComment(const Comment::Ptr& comment) +void IcingaDB::SendRemovedComment(const Comment::Ptr& comment) { if (!m_Rcon || !m_Rcon->IsConnected()) return; @@ -1569,7 +1569,7 @@ void RedisWriter::SendRemovedComment(const Comment::Ptr& comment) m_Rcon->FireAndForgetQuery(std::move(xAdd)); } -void RedisWriter::SendFlappingChanged(const Checkable::Ptr& checkable, const Value& value) +void IcingaDB::SendFlappingChanged(const Checkable::Ptr& checkable, const Value& value) { if (!m_Rcon || !m_Rcon->IsConnected()) return; @@ -1611,7 +1611,7 @@ void RedisWriter::SendFlappingChanged(const Checkable::Ptr& checkable, const Val m_Rcon->FireAndForgetQuery(std::move(xAdd)); } -Dictionary::Ptr RedisWriter::SerializeState(const Checkable::Ptr& checkable) +Dictionary::Ptr IcingaDB::SerializeState(const Checkable::Ptr& checkable) { Dictionary::Ptr attrs = new Dictionary(); @@ -1709,7 +1709,7 @@ Dictionary::Ptr RedisWriter::SerializeState(const Checkable::Ptr& checkable) } std::vector -RedisWriter::UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType, +IcingaDB::UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType, const String& typeNameOverride) { Type::Ptr type = object->GetReflectionType(); @@ -1751,73 +1751,73 @@ RedisWriter::UpdateObjectAttrs(const ConfigObject::Ptr& object, int fieldType, //m_Rcon->FireAndForgetQuery({"HSET", keyPrefix + typeName, GetObjectIdentifier(object), JsonEncode(attrs)}); } -void RedisWriter::StateChangeHandler(const ConfigObject::Ptr& object) +void IcingaDB::StateChangeHandler(const ConfigObject::Ptr& object) { auto checkable (dynamic_pointer_cast(object)); if (checkable) { - RedisWriter::StateChangeHandler(object, checkable->GetLastCheckResult(), checkable->GetStateType()); + IcingaDB::StateChangeHandler(object, checkable->GetLastCheckResult(), checkable->GetStateType()); } } -void RedisWriter::StateChangeHandler(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type) +void IcingaDB::StateChangeHandler(const ConfigObject::Ptr& object, const CheckResult::Ptr& cr, StateType type) { - for (const RedisWriter::Ptr& rw : ConfigType::GetObjectsByType()) { + for (const IcingaDB::Ptr& rw : ConfigType::GetObjectsByType()) { rw->m_WorkQueue.Enqueue([rw, object, cr, type]() { rw->SendStatusUpdate(object, cr, type); }); } } -void RedisWriter::VersionChangedHandler(const ConfigObject::Ptr& object) +void IcingaDB::VersionChangedHandler(const ConfigObject::Ptr& object) { Type::Ptr type = object->GetReflectionType(); if (object->IsActive()) { // Create or update the object config - for (const RedisWriter::Ptr& rw : ConfigType::GetObjectsByType()) { + for (const IcingaDB::Ptr& rw : ConfigType::GetObjectsByType()) { if (rw) rw->m_WorkQueue.Enqueue([rw, object]() { rw->SendConfigUpdate(object, true); }); } } else if (!object->IsActive() && object->GetExtension("ConfigObjectDeleted")) { // same as in apilistener-configsync.cpp // Delete object config - for (const RedisWriter::Ptr& rw : ConfigType::GetObjectsByType()) { + for (const IcingaDB::Ptr& rw : ConfigType::GetObjectsByType()) { if (rw) rw->m_WorkQueue.Enqueue([rw, object]() { rw->SendConfigDelete(object); }); } } } -void RedisWriter::DowntimeAddedHandler(const Downtime::Ptr& downtime) +void IcingaDB::DowntimeAddedHandler(const Downtime::Ptr& downtime) { - for (auto& rw : ConfigType::GetObjectsByType()) { + for (auto& rw : ConfigType::GetObjectsByType()) { rw->m_WorkQueue.Enqueue([rw, downtime]() { rw->SendAddedDowntime(downtime); }); } } -void RedisWriter::DowntimeStartedHandler(const Downtime::Ptr& downtime) +void IcingaDB::DowntimeStartedHandler(const Downtime::Ptr& downtime) { StateChangeHandler(downtime->GetCheckable()); - for (auto& rw : ConfigType::GetObjectsByType()) { + for (auto& rw : ConfigType::GetObjectsByType()) { rw->m_WorkQueue.Enqueue([rw, downtime]() { rw->SendStartedDowntime(downtime); }); } } -void RedisWriter::DowntimeRemovedHandler(const Downtime::Ptr& downtime) +void IcingaDB::DowntimeRemovedHandler(const Downtime::Ptr& downtime) { StateChangeHandler(downtime->GetCheckable()); - for (auto& rw : ConfigType::GetObjectsByType()) { + for (auto& rw : ConfigType::GetObjectsByType()) { rw->m_WorkQueue.Enqueue([rw, downtime]() { rw->SendRemovedDowntime(downtime); }); } } -void RedisWriter::NotificationSentToAllUsersHandler( +void IcingaDB::NotificationSentToAllUsersHandler( const Notification::Ptr& notification, const Checkable::Ptr& checkable, const std::set& users, NotificationType type, const CheckResult::Ptr& cr, const String& author, const String& text ) { - auto rws (ConfigType::GetObjectsByType()); + auto rws (ConfigType::GetObjectsByType()); if (!rws.empty()) { auto usersAmount (users.size()); @@ -1831,23 +1831,23 @@ void RedisWriter::NotificationSentToAllUsersHandler( } } -void RedisWriter::CommentAddedHandler(const Comment::Ptr& comment) +void IcingaDB::CommentAddedHandler(const Comment::Ptr& comment) { - for (auto& rw : ConfigType::GetObjectsByType()) { + for (auto& rw : ConfigType::GetObjectsByType()) { rw->m_WorkQueue.Enqueue([rw, comment]() { rw->SendAddedComment(comment); }); } } -void RedisWriter::CommentRemovedHandler(const Comment::Ptr& comment) +void IcingaDB::CommentRemovedHandler(const Comment::Ptr& comment) { - for (auto& rw : ConfigType::GetObjectsByType()) { + for (auto& rw : ConfigType::GetObjectsByType()) { rw->m_WorkQueue.Enqueue([rw, comment]() { rw->SendRemovedComment(comment); }); } } -void RedisWriter::FlappingChangedHandler(const Checkable::Ptr& checkable, const Value& value) +void IcingaDB::FlappingChangedHandler(const Checkable::Ptr& checkable, const Value& value) { - for (auto& rw : ConfigType::GetObjectsByType()) { + for (auto& rw : ConfigType::GetObjectsByType()) { rw->m_WorkQueue.Enqueue([rw, checkable, value]() { rw->SendFlappingChanged(checkable, value); }); } } diff --git a/lib/redis/rediswriter-stats.cpp b/lib/redis/rediswriter-stats.cpp index 8ed024cf2..d007aeb66 100644 --- a/lib/redis/rediswriter-stats.cpp +++ b/lib/redis/rediswriter-stats.cpp @@ -26,7 +26,7 @@ using namespace icinga; -Dictionary::Ptr RedisWriter::GetStats() +Dictionary::Ptr IcingaDB::GetStats() { Dictionary::Ptr stats = new Dictionary(); diff --git a/lib/redis/rediswriter-utility.cpp b/lib/redis/rediswriter-utility.cpp index f2a4a5281..0a687f772 100644 --- a/lib/redis/rediswriter-utility.cpp +++ b/lib/redis/rediswriter-utility.cpp @@ -41,7 +41,7 @@ using namespace icinga; -String RedisWriter::FormatCheckSumBinary(const String& str) +String IcingaDB::FormatCheckSumBinary(const String& str) { char output[20*2+1]; for (int i = 0; i < 20; i++) @@ -50,7 +50,7 @@ String RedisWriter::FormatCheckSumBinary(const String& str) return output; } -String RedisWriter::FormatCommandLine(const Value& commandLine) +String IcingaDB::FormatCommandLine(const Value& commandLine) { String result; if (commandLine.IsObjectType()) { @@ -77,12 +77,12 @@ String RedisWriter::FormatCommandLine(const Value& commandLine) return result; } -String RedisWriter::GetEnvironment() +String IcingaDB::GetEnvironment() { return ConfigType::GetObjectsByType()[0]->GetEnvironment(); } -String RedisWriter::GetObjectIdentifier(const ConfigObject::Ptr& object) +String IcingaDB::GetObjectIdentifier(const ConfigObject::Ptr& object) { Type::Ptr type = object->GetReflectionType(); @@ -92,12 +92,12 @@ String RedisWriter::GetObjectIdentifier(const ConfigObject::Ptr& object) return HashValue((Array::Ptr)new Array({GetEnvironment(), object->GetName()})); } -String RedisWriter::CalculateCheckSumString(const String& str) +String IcingaDB::CalculateCheckSumString(const String& str) { return SHA1(str); } -String RedisWriter::CalculateCheckSumArray(const Array::Ptr& arr) +String IcingaDB::CalculateCheckSumArray(const Array::Ptr& arr) { /* Ensure that checksums happen in a defined order. */ Array::Ptr tmpArr = arr->ShallowClone(); @@ -107,7 +107,7 @@ String RedisWriter::CalculateCheckSumArray(const Array::Ptr& arr) return SHA1(PackObject(tmpArr)); } -String RedisWriter::CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set& propertiesBlacklist) +String IcingaDB::CalculateCheckSumProperties(const ConfigObject::Ptr& object, const std::set& propertiesBlacklist) { //TODO: consider precision of 6 for double values; use specific config fields for hashing? return HashValue(object, propertiesBlacklist); @@ -115,12 +115,12 @@ String RedisWriter::CalculateCheckSumProperties(const ConfigObject::Ptr& object, static const std::set metadataWhitelist ({"package", "source_location", "templates"}); -String RedisWriter::CalculateCheckSumMetadata(const ConfigObject::Ptr& object) +String IcingaDB::CalculateCheckSumMetadata(const ConfigObject::Ptr& object) { return HashValue(object, metadataWhitelist, true); } -String RedisWriter::CalculateCheckSumVars(const CustomVarObject::Ptr& object) +String IcingaDB::CalculateCheckSumVars(const CustomVarObject::Ptr& object) { Dictionary::Ptr vars = object->GetVars(); @@ -169,7 +169,7 @@ String RedisWriter::CalculateCheckSumVars(const CustomVarObject::Ptr& object) * * @return JSON-like data structure for Redis */ -Dictionary::Ptr RedisWriter::SerializeVars(const CustomVarObject::Ptr& object) +Dictionary::Ptr IcingaDB::SerializeVars(const CustomVarObject::Ptr& object) { Dictionary::Ptr vars = object->GetVars(); @@ -199,12 +199,12 @@ Dictionary::Ptr RedisWriter::SerializeVars(const CustomVarObject::Ptr& object) static const std::set propertiesBlacklistEmpty; -String RedisWriter::HashValue(const Value& value) +String IcingaDB::HashValue(const Value& value) { return HashValue(value, propertiesBlacklistEmpty); } -String RedisWriter::HashValue(const Value& value, const std::set& propertiesBlacklist, bool propertiesWhitelist) +String IcingaDB::HashValue(const Value& value, const std::set& propertiesBlacklist, bool propertiesWhitelist) { Value temp; bool mutabl; @@ -252,11 +252,11 @@ String RedisWriter::HashValue(const Value& value, const std::set& proper return SHA1(PackObject(temp)); } -String RedisWriter::GetLowerCaseTypeNameDB(const ConfigObject::Ptr& obj) +String IcingaDB::GetLowerCaseTypeNameDB(const ConfigObject::Ptr& obj) { return obj->GetReflectionType()->GetName().ToLower(); } -long long RedisWriter::TimestampToMilliseconds(double timestamp) { +long long IcingaDB::TimestampToMilliseconds(double timestamp) { return static_cast(timestamp * 1000); } diff --git a/lib/redis/rediswriter.cpp b/lib/redis/rediswriter.cpp index eaa2609a9..6b3677cdd 100644 --- a/lib/redis/rediswriter.cpp +++ b/lib/redis/rediswriter.cpp @@ -35,14 +35,14 @@ using namespace icinga; //TODO Make configurable and figure out a sane default #define MAX_EVENTS_DEFAULT 5000 -REGISTER_TYPE(RedisWriter); +REGISTER_TYPE(IcingaDB); -RedisWriter::RedisWriter() +IcingaDB::IcingaDB() : m_Rcon(nullptr) { m_Rcon = nullptr; - m_WorkQueue.SetName("RedisWriter"); + m_WorkQueue.SetName("IcingaDB"); m_PrefixConfigObject = "icinga:config:"; m_PrefixConfigCheckSum = "icinga:checksum:"; @@ -52,11 +52,11 @@ RedisWriter::RedisWriter() /** * Starts the component. */ -void RedisWriter::Start(bool runtimeCreated) +void IcingaDB::Start(bool runtimeCreated) { - ObjectImpl::Start(runtimeCreated); + ObjectImpl::Start(runtimeCreated); - Log(LogInformation, "RedisWriter") + Log(LogInformation, "IcingaDB") << "'" << GetName() << "' started."; m_ConfigDumpInProgress = false; @@ -83,27 +83,27 @@ void RedisWriter::Start(bool runtimeCreated) m_StatsTimer->OnTimerExpired.connect([this](const Timer * const&) { PublishStatsTimerHandler(); }); m_StatsTimer->Start(); - m_WorkQueue.SetName("RedisWriter"); + m_WorkQueue.SetName("IcingaDB"); - boost::thread thread(&RedisWriter::HandleEvents, this); + boost::thread thread(&IcingaDB::HandleEvents, this); thread.detach(); } -void RedisWriter::ExceptionHandler(boost::exception_ptr exp) +void IcingaDB::ExceptionHandler(boost::exception_ptr exp) { - Log(LogCritical, "RedisWriter", "Exception during redis query. Verify that Redis is operational."); + Log(LogCritical, "IcingaDB", "Exception during redis query. Verify that Redis is operational."); - Log(LogDebug, "RedisWriter") + Log(LogDebug, "IcingaDB") << "Exception during redis operation: " << DiagnosticInformation(exp); } -void RedisWriter::ReconnectTimerHandler() +void IcingaDB::ReconnectTimerHandler() { m_WorkQueue.Enqueue([this]() { TryToReconnect(); }); } -void RedisWriter::TryToReconnect() +void IcingaDB::TryToReconnect() { AssertOnWorkQueue(); @@ -131,16 +131,16 @@ void RedisWriter::TryToReconnect() m_ConfigDumpInProgress = false; } -void RedisWriter::UpdateSubscriptionsTimerHandler() +void IcingaDB::UpdateSubscriptionsTimerHandler() { m_WorkQueue.Enqueue([this]() { UpdateSubscriptions(); }); } -void RedisWriter::UpdateSubscriptions() +void IcingaDB::UpdateSubscriptions() { AssertOnWorkQueue(); - Log(LogInformation, "RedisWriter", "Updating Redis subscriptions"); + Log(LogInformation, "IcingaDB", "Updating Redis subscriptions"); /* TODO: * Silently return in this case. Usually the RedisConnection checks for connectivity and logs in failure case. @@ -168,8 +168,8 @@ void RedisWriter::UpdateSubscriptions() RedisSubscriptionInfo rsi; - if (!RedisWriter::GetSubscriptionTypes(key, rsi)) { - Log(LogInformation, "RedisWriter") + if (!IcingaDB::GetSubscriptionTypes(key, rsi)) { + Log(LogInformation, "IcingaDB") << "Subscription \"" << key << "\" has no types listed."; } else { m_Subscriptions[key.SubStr(keyPrefix.GetLength())] = rsi; @@ -177,11 +177,11 @@ void RedisWriter::UpdateSubscriptions() } } while (cursor != "0"); - Log(LogInformation, "RedisWriter") + Log(LogInformation, "IcingaDB") << "Current Redis event subscriptions: " << m_Subscriptions.size(); } -bool RedisWriter::GetSubscriptionTypes(String key, RedisSubscriptionInfo& rsi) +bool IcingaDB::GetSubscriptionTypes(String key, RedisSubscriptionInfo& rsi) { try { Array::Ptr redisReply = m_Rcon->GetResultOfQuery({ "SMEMBERS", key }); @@ -197,11 +197,11 @@ bool RedisWriter::GetSubscriptionTypes(String key, RedisSubscriptionInfo& rsi) } } - Log(LogInformation, "RedisWriter") + Log(LogInformation, "IcingaDB") << "Subscriber Info - Key: " << key << " Value: " << Value(Array::FromSet(rsi.EventTypes)); } catch (const std::exception& ex) { - Log(LogWarning, "RedisWriter") + Log(LogWarning, "IcingaDB") << "Invalid Redis subscriber info for subscriber '" << key << "': " << DiagnosticInformation(ex); return false; @@ -210,12 +210,12 @@ bool RedisWriter::GetSubscriptionTypes(String key, RedisSubscriptionInfo& rsi) return true; } -void RedisWriter::PublishStatsTimerHandler(void) +void IcingaDB::PublishStatsTimerHandler(void) { m_WorkQueue.Enqueue([this]() { PublishStats(); }); } -void RedisWriter::PublishStats() +void IcingaDB::PublishStats() { AssertOnWorkQueue(); @@ -229,7 +229,7 @@ void RedisWriter::PublishStats() m_Rcon->FireAndForgetQuery({ "PUBLISH", "icinga:stats", jsonStats }); } -void RedisWriter::HandleEvents() +void IcingaDB::HandleEvents() { String queueName = Utility::NewUniqueID(); EventQueue::Ptr queue = new EventQueue(queueName); @@ -265,7 +265,7 @@ void RedisWriter::HandleEvents() EventQueue::UnregisterIfUnused(queueName, queue); } -void RedisWriter::HandleEvent(const Dictionary::Ptr& event) +void IcingaDB::HandleEvent(const Dictionary::Ptr& event) { AssertOnWorkQueue(); @@ -284,7 +284,7 @@ void RedisWriter::HandleEvent(const Dictionary::Ptr& event) if (maxExists != 0) { String redisReply = m_Rcon->GetResultOfQuery({ "GET", "icinga:subscription:" + name + ":limit"}); - Log(LogInformation, "RedisWriter") + Log(LogInformation, "IcingaDB") << "Got limit " << redisReply << " for " << name; maxEvents = Convert::ToLong(redisReply); @@ -298,7 +298,7 @@ void RedisWriter::HandleEvent(const Dictionary::Ptr& event) } } -void RedisWriter::SendEvent(const Dictionary::Ptr& event) +void IcingaDB::SendEvent(const Dictionary::Ptr& event) { AssertOnWorkQueue(); @@ -347,7 +347,7 @@ void RedisWriter::SendEvent(const Dictionary::Ptr& event) String body = JsonEncode(event); -// Log(LogInformation, "RedisWriter") +// Log(LogInformation, "IcingaDB") // << "Sending event \"" << body << "\""; m_Rcon->FireAndForgetQueries({ @@ -355,15 +355,15 @@ void RedisWriter::SendEvent(const Dictionary::Ptr& event) { "PUBLISH", "icinga:event:" + event->Get("type"), body }}); } -void RedisWriter::Stop(bool runtimeRemoved) +void IcingaDB::Stop(bool runtimeRemoved) { - Log(LogInformation, "RedisWriter") + Log(LogInformation, "IcingaDB") << "'" << GetName() << "' stopped."; - ObjectImpl::Stop(runtimeRemoved); + ObjectImpl::Stop(runtimeRemoved); } -void RedisWriter::AssertOnWorkQueue() +void IcingaDB::AssertOnWorkQueue() { ASSERT(m_WorkQueue.IsWorkerThread()); } diff --git a/lib/redis/rediswriter.hpp b/lib/redis/rediswriter.hpp index 666f9b1b7..597d2fcc6 100644 --- a/lib/redis/rediswriter.hpp +++ b/lib/redis/rediswriter.hpp @@ -42,13 +42,13 @@ struct RedisSubscriptionInfo /** * @ingroup redis */ -class RedisWriter : public ObjectImpl +class IcingaDB : public ObjectImpl { public: - DECLARE_OBJECT(RedisWriter); - DECLARE_OBJECTNAME(RedisWriter); + DECLARE_OBJECT(IcingaDB); + DECLARE_OBJECTNAME(IcingaDB); - RedisWriter(); + IcingaDB(); static void ConfigStaticInitialize(); diff --git a/lib/redis/rediswriter.ti b/lib/redis/rediswriter.ti index db3df0ab5..07572eba2 100644 --- a/lib/redis/rediswriter.ti +++ b/lib/redis/rediswriter.ti @@ -24,7 +24,7 @@ library redis; namespace icinga { -class RedisWriter : ConfigObject +class IcingaDB : ConfigObject { [config] String host { default {{{ return "127.0.0.1"; }}}