0
0
Fork 0
mirror of https://github.com/alerta/alerta-contrib.git synced 2025-03-17 22:12:38 +00:00
alerta_alerta-contrib/integrations/mailer/README.md

165 lines
4.7 KiB
Markdown
Raw Normal View History

2016-12-10 15:00:42 +00:00
Mailer Integration
==================
2015-11-03 20:24:06 +00:00
2016-12-10 15:00:42 +00:00
Send emails for alerts received by Alerta.
2015-11-03 20:24:06 +00:00
2016-12-10 15:00:42 +00:00
For help, join [![Gitter chat](https://badges.gitter.im/alerta/chat.png)](https://gitter.im/alerta/chat)
Overview
--------
It is specifically designed to reduce the number of unnecessary emails by
ensuring that alerts meet the following criteria:
2015-11-03 20:24:06 +00:00
* 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 not have been cleared down within 30 seconds (to prevent flapping alerts spamming)
2016-12-10 15:00:42 +00:00
To achieve the above, alerts are actually held for a minimum of 30 seconds
before they generate emails.
2015-11-03 20:24:06 +00:00
Installation
------------
2016-12-10 15:00:42 +00:00
Clone the GitHub repo and run:
2015-11-03 20:24:06 +00:00
$ python setup.py install
2016-12-10 15:00:42 +00:00
Or, to install remotely from GitHub run:
$ pip install git+https://github.com/alerta/alerta-contrib.git#subdirectory=integrations/mailer
2015-11-03 20:24:06 +00:00
Configuration
-------------
2016-12-10 15:00:42 +00:00
Settings are changed using an ini-style configuration file that is also
used for the ``alerta`` cli.
2015-11-03 20:24:06 +00:00
2016-12-10 15:00:42 +00:00
A section called ``[alerta-mailer]`` is used to clearly define which
settings apply to the mailer script.
2015-11-03 20:24:06 +00:00
```
[alerta-mailer]
key = demo-key
mail_to = john.doe@gmail.com,jane.doe@gmail.com
mail_from = your.email@gmail.com
amqp_url = redis://localhost:6379/
dashboard_url = http://localhost:8000
smtp_password = okvqhitqomebufyv
2016-10-12 06:54:01 +00:00
smtp_use_ssl = False
2015-11-03 20:24:06 +00:00
debug = True
skip_mta = False
email_type = text
2015-11-03 20:24:06 +00:00
```
2016-12-10 15:00:42 +00:00
If you are using Google Gmail as the SMTP server. You will need to create
an application-specific password.
You can skip the use of an SMTP server using the option 'skip_mta'. Note
that in most cases is recommended to use an SMTP outbound server as the
MTA, but if you know what you're doing you can use skip_mta and then
``alerta-mailer`` will resolve the proper destination MX DNS record for
each address and attempt to deliver the email directly. Some email
systems may detect certain email patterns to black-list you, such as
sending email using a hostname such as 'localhost'. You may need to
set the 'mail_localhost' option or set a proper FQDN in your server to
avoid this.
You can also use IP-authentication in your own SMTP server (by only
white-listing the alerta server IP), in such cases you should not
set the 'smtp_password' option to skip authentication altogether.
Application-specific passwords
https://support.google.com/accounts/answer/185833?hl=en
Rules File
----------
Notifications to other emails according regexp criteria can be enabled,
2016-12-10 15:00:42 +00:00
creating a JSON formatted file under ```alerta.rules.d/``` with the
following format:
```
[
{
"name": "foo",
"fields": [
{"field": "resource", "regex": "db-\w+"}
],
"contacts": ["dba@lists.mycompany.com", "dev@lists.mycompany.com"]
},
{
"name": "bar",
"fields": [
{"field": "resource", "regex": "web-\w+"}
],
"contacts": ["dev@lists.mycompany.com"],
"exclude" : true
}
]
```
2016-12-10 15:00:42 +00:00
``field`` is a reference to the alert object, regex is a valid python
regexp and contacts are a list of mails who will receive an e-mail if
2016-02-23 11:27:16 +00:00
the regular expression matches.
2016-12-10 15:00:42 +00:00
Multiple ``field`` dictionary can be supplied and all ``regex`` must
match for the email to be sent.
2016-12-10 15:00:42 +00:00
If the ``exclude`` parameter is set, contact list will be cleared and
replaced with only the contacts of the current matched rule.
2015-11-03 20:24:06 +00:00
Environment Variables
2016-02-23 11:27:16 +00:00
---------------------
2015-11-03 20:24:06 +00:00
``SMTP_PASSWORD`` - can be used instead of smtp_password in the configuration file.
2015-11-04 15:33:46 +00:00
Email Format
2016-02-23 11:27:16 +00:00
------------
2015-11-03 20:24:06 +00:00
2015-11-04 15:33:46 +00:00
The format for emails uses a templating engine called Jinja2.
2015-11-03 20:24:06 +00:00
The variable email_type can have 2 possible values:
2016-12-10 15:00:42 +00:00
- html: for just html emails, will fallback to text for text clients (mutt, etc)
- text: for just plain text emails
Multiple files config support
-----------------------------
2016-12-10 15:00:42 +00:00
Multiple configs files are supported for alerta-mailer you just need
to create a directory with the name of the config file with the ``.d``
suffix, i.e: (assuming you have a config file called ``mailer.conf``
on ``/etc/alerta/`` you will need to create the directory ``mailer.conf.d``
at the same level of your config file (mailer.conf in this example),
and place all your configs there.
2016-12-10 15:00:42 +00:00
Multiple email rules files can be supplied as well and rules are
going to be applied top-down as they appear on the filesystem and
on the files themselves.
2015-11-04 15:33:46 +00:00
Deployment
----------
2015-11-03 20:24:06 +00:00
$ export SMTP_PASSWORD=okvqhitqomebufyv
$ alerta-mailer
2015-11-04 15:33:46 +00:00
Dependencies
------------
2016-12-10 15:00:42 +00:00
The Alerta server *MUST* have the AMQP plugin enabled and configured.
See [AMQP](plugins/amqp) for more info.
Testing
-------
2016-12-10 15:00:42 +00:00
To execute unit-tests run:
2016-12-10 15:00:42 +00:00
$ python setup.py test
License
-------
Copyright (c) 2015-2016 Nick Satterly and [AUTHORS](AUTHORS). Available under the MIT License.