feat: mailer pickable sevs ()

* add default option & use it

* update readme
This commit is contained in:
Matthew Jenkins 2021-01-06 17:18:29 -05:00 committed by GitHub
parent 614aa32efe
commit 2a8f448a65
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions
integrations/mailer

View file

@ -13,7 +13,7 @@ ensuring that alerts meet the following criteria:
* must not be a duplicate alert (ie. ``repeat != True``)
* must have status of ``open`` or ``closed``
* must have a current severity *OR* previous severity of ``critical`` or ``major``
* must have a current severity *OR* previous severity of ``critical`` or ``major`` by default
* must not have been cleared down within 30 seconds (to prevent flapping alerts spamming)
To achieve the above, alerts are actually held for a minimum of 30 seconds

View file

@ -9,6 +9,7 @@ import re
import signal
import smtplib
import socket
from configparser import RawConfigParser
from functools import reduce
import six
@ -35,11 +36,6 @@ try:
except:
sys.stdout.write('Python dns.resolver unavailable. The skip_mta option will be forced to False\n') # nopep8
try:
import configparser
except ImportError:
import ConfigParser as configparser
logging.basicConfig(level=logging.DEBUG)
LOG = logging.getLogger(__name__)
@ -73,7 +69,8 @@ DEFAULT_OPTIONS = {
'dashboard_url': 'http://try.alerta.io',
'debug': False,
'skip_mta': False,
'email_type': 'text' # options are: text, html
'email_type': 'text', # options are: text, html
'severities': []
}
OPTIONS = {}
@ -116,6 +113,9 @@ class FanoutConsumer(ConsumerMixin):
]
def on_message(self, body, message):
sevs = list(OPTIONS['severities'])
if not sevs:
sevs = ['critical', 'major']
try:
alert = Alert.parse(body)
@ -133,8 +133,8 @@ class FanoutConsumer(ConsumerMixin):
return
if (
alert.severity not in ['critical', 'major'] and
alert.previous_severity not in ['critical', 'major']
alert.severity not in sevs and
alert.previous_severity not in sevs
):
message.ack()
return
@ -432,9 +432,11 @@ def parse_group_rules(config_file):
return rules_d
return ()
def on_sigterm(x, y):
raise SystemExit
def main():
global OPTIONS
@ -443,7 +445,7 @@ def main():
# Convert default booleans to its string type, otherwise config.getboolean fails # nopep8
defopts = {k: str(v) if type(v) is bool else v for k, v in DEFAULT_OPTIONS.items()} # nopep8
config = configparser.RawConfigParser(defaults=defopts)
config = RawConfigParser(defaults=defopts)
if os.path.exists("{}.d".format(config_file)):
config_path = "{}.d".format(config_file)