From 88e470183b7eb3bff6cf90d8b781e1c5fc2fbf94 Mon Sep 17 00:00:00 2001 From: "Brian S. Stephan" Date: Fri, 3 May 2013 16:01:45 -0500 Subject: [PATCH] Dispatch: support multiple targets for a key --- modules/Dispatch.py | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/modules/Dispatch.py b/modules/Dispatch.py index 617d54b..00e89c1 100644 --- a/modules/Dispatch.py +++ b/modules/Dispatch.py @@ -88,17 +88,17 @@ class Dispatch(Module): message the message to send to the channel Returns: - tuple of strings: the destination channel, the string sent to it + list of all notified targets """ - key, dest = self._get_key_and_destination(key) - - if key is not None and dest is not None: + notified = [] + for key, dest in self._get_key_and_destination(key): msg = "[{0:s}] {1:s}".format(key, message.encode('utf-8', 'ignore')) self.sendmsg(dest, msg) + notified.append(dest) - return dest, msg + return notified def _get_key_and_destination(self, key): """Retrieve the configured channel for the given key. @@ -107,11 +107,11 @@ class Dispatch(Module): key the type of message. this will be converted uppercase Returns: - tuple of strings: the key (from the db), the destination channel + list of tuple of strings: (the key, the destination channel) """ - channel = None + targets = [] db = self.get_db() try: cur = db.cursor(mdb.cursors.DictCursor) @@ -120,11 +120,11 @@ class Dispatch(Module): WHERE key_ = %s ''' cur.execute(query, (key.upper(),)) - result = cur.fetchone() - if result: - return result['key_'], result['dest'] - else: - return None, None + results = cur.fetchall() + for result in results: + targets.append((result['key_'], result['dest'])) + + return targets except mdb.Error as e: self.log.error("database error while getting destination") self.log.exception(e)