Dispatch: support multiple targets for a key

tmp/79b4e7d7e0424f8155715d7c458859a1/head
Brian S. Stephan 10 years ago
parent f09a41bce0
commit 88e470183b

@ -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)

Loading…
Cancel
Save