]> granicus.if.org Git - icinga2/commitdiff
Only send events to Redis when there is at least one subscriber
authorGunnar Beutner <gunnar.beutner@icinga.com>
Mon, 13 Mar 2017 09:56:16 +0000 (10:56 +0100)
committerMichael Friedrich <michael.friedrich@icinga.com>
Tue, 14 Mar 2017 14:19:02 +0000 (15:19 +0100)
refs #4991

lib/redis/rediswriter.cpp

index a04b53cb326abb28419d754c36b876bbc3aa8477..39124d15c033b85814fb418f63b25793a8faa221 100644 (file)
@@ -244,6 +244,21 @@ void RedisWriter::HandleEvent(const Dictionary::Ptr& event)
        if (!m_Context)
                return;
 
+       String type = event->Get("type");
+       bool atLeastOneSubscriber = false;
+
+       for (const std::pair<String, RedisSubscriptionInfo>& kv : m_Subscriptions) {
+               const auto& rsi = kv.second;
+
+               if (rsi.EventTypes.find(type) == rsi.EventTypes.end())
+                       continue;
+
+               atLeastOneSubscriber = true;
+       }
+
+       if (!atLeastOneSubscriber)
+               return;
+
        Log(LogInformation, "RedisWriter")
            << "Pushing event to Redis: '" << Value(event) << "'.";
 
@@ -318,8 +333,6 @@ void RedisWriter::HandleEvent(const Dictionary::Ptr& event)
 
        freeReplyObject(reply3);
 
-       String type = event->Get("type");
-
        for (const std::pair<String, RedisSubscriptionInfo>& kv : m_Subscriptions) {
                const auto& name = kv.first;
                const auto& rsi = kv.second;