Publish events to one enpoint

This commit is contained in:
Jean Flach 2017-10-16 12:03:49 +02:00 committed by Michael Friedrich
parent 26a758b941
commit 5eab856673
2 changed files with 21 additions and 1 deletions

View File

@ -147,6 +147,7 @@ void RedisWriter::TryToReconnect(void)
m_ConfigDumpInProgress = false; m_ConfigDumpInProgress = false;
} }
/*
void RedisWriter::UpdateSubscriptionsTimerHandler(void) void RedisWriter::UpdateSubscriptionsTimerHandler(void)
{ {
m_WorkQueue.Enqueue(boost::bind(&RedisWriter::UpdateSubscriptions, this)); m_WorkQueue.Enqueue(boost::bind(&RedisWriter::UpdateSubscriptions, this));
@ -218,6 +219,7 @@ int RedisWriter::GetSubscriptionTypes(String key, RedisSubscriptionInfo& rsi)
<< "Invalid Redis subscriber info for subscriber '" << key << "': " << DiagnosticInformation(ex); << "Invalid Redis subscriber info for subscriber '" << key << "': " << DiagnosticInformation(ex);
} }
} }
*/
void RedisWriter::PublishStatsTimerHandler(void) void RedisWriter::PublishStatsTimerHandler(void)
{ {
@ -270,13 +272,14 @@ void RedisWriter::HandleEvents(void)
if (!event) if (!event)
continue; continue;
m_WorkQueue.Enqueue(boost::bind(&RedisWriter::HandleEvent, this, event)); m_WorkQueue.Enqueue(boost::bind(&RedisWriter::SendEvent, this, event));
} }
queue->RemoveClient(this); queue->RemoveClient(this);
EventQueue::UnregisterIfUnused(queueName, queue); EventQueue::UnregisterIfUnused(queueName, queue);
} }
/*
void RedisWriter::HandleEvent(const Dictionary::Ptr& event) void RedisWriter::HandleEvent(const Dictionary::Ptr& event)
{ {
AssertOnWorkQueue(); AssertOnWorkQueue();
@ -309,6 +312,22 @@ void RedisWriter::HandleEvent(const Dictionary::Ptr& event)
ExecuteQuery({ "EXEC" }); ExecuteQuery({ "EXEC" });
} }
} }
*/
void RedisWriter::HandleEvent(const Dictionary::Ptr& event)
{
AssertOnWorkQueue();
if (!m_Context)
return;
String body = JsonEncode(event);
Log(LogInformation, "RedisWriter")
<< "Sending event \"" << body << "\"";
ExecuteQuery({ "PUBLISH", "icinga:event:all", body });
ExecuteQuery({ "PUBLISH", "icinga:event:" + event->Get("type"), body });
}
void RedisWriter::Stop(bool runtimeRemoved) void RedisWriter::Stop(bool runtimeRemoved)
{ {

View File

@ -56,6 +56,7 @@ private:
void TryToReconnect(void); void TryToReconnect(void);
void HandleEvents(void); void HandleEvents(void);
void HandleEvent(const Dictionary::Ptr& event); void HandleEvent(const Dictionary::Ptr& event);
void SendEvent(const Dictionary::Ptr& event);
void UpdateSubscriptionsTimerHandler(void); void UpdateSubscriptionsTimerHandler(void);
void UpdateSubscriptions(void); void UpdateSubscriptions(void);