Merge pull request from alerta/master

Merge from upstream
This commit is contained in:
Yann Cézard 2019-07-31 10:35:00 +02:00 committed by GitHub
commit 7256694722
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 2 deletions
integrations/mailer
plugins/amqp

View file

@ -6,6 +6,7 @@ import logging
import os
import platform
import re
import signal
import smtplib
import socket
import sys
@ -256,6 +257,10 @@ class MailSender(threading.Thread):
' adding for this rule only')
del contacts[:]
contacts.extend(new_contacts)
# Don't loose time (and try to send an email) if there is no contact...
if not contacts:
return
template_vars = {
'alert': alert,
@ -424,6 +429,8 @@ def parse_group_rules(config_file):
return rules_d
return ()
def on_sigterm(x, y):
raise SystemExit
def main():
global OPTIONS
@ -464,7 +471,7 @@ def main():
int: config.getint,
float: config.getfloat,
bool: config.getboolean,
list: lambda s, o: [e.strip() for e in config.get(s, o).split(',')]
list: lambda s, o: [e.strip() for e in config.get(s, o).split(',')] if len(config.get(s, o)) else []
}
for opt in DEFAULT_OPTIONS:
# Convert the options to the expected type
@ -490,6 +497,9 @@ def main():
if group_rules is not None:
OPTIONS['group_rules'] = group_rules
# Registering action for SIGTERM signal handling
signal.signal(signal.SIGTERM, on_sigterm)
try:
mailer = MailSender()
mailer.start()

View file

@ -15,9 +15,11 @@ LOG = logging.getLogger('alerta.plugins.amqp')
DEFAULT_AMQP_URL = 'mongodb://localhost:27017/kombu'
DEFAULT_AMQP_TOPIC = 'notify'
DEFAULT_AMQP_SEND_ALERT_HISTORY = True
AMQP_URL = os.environ.get('REDIS_URL') or os.environ.get('AMQP_URL') or app.config.get('AMQP_URL', DEFAULT_AMQP_URL)
AMQP_TOPIC = os.environ.get('AMQP_TOPIC') or app.config.get('AMQP_TOPIC', DEFAULT_AMQP_TOPIC)
AMQP_SEND_ALERT_HISTORY = os.environ.get('AMQP_SEND_ALERT_HISTORY') or app.config.get('AMQP_SEND_ALERT_HISTORY', DEFAULT_AMQP_SEND_ALERT_HISTORY)
class FanoutPublisher(PluginBase):
@ -48,7 +50,7 @@ class FanoutPublisher(PluginBase):
def post_receive(self, alert):
LOG.info('Sending message %s to AMQP topic "%s"', alert.get_id(), AMQP_TOPIC)
body = alert.get_body()
body = alert.get_body(history=AMQP_SEND_ALERT_HISTORY)
LOG.debug('Message: %s', body)
self.producer.publish(body, declare=[self.exchange], retry=True)