Compare commits
1 commit
master
...
prom-basic
Author | SHA1 | Date | |
---|---|---|---|
![]() |
ede6b2f68f |
3 changed files with 29 additions and 4 deletions
plugins/prometheus
|
@ -48,6 +48,24 @@ ALERTMANAGER_API_URL = 'http://demo.robustperception.io:9093' # default=http://
|
|||
ALERTMANAGER_SILENCE_DAYS = 2 # default=1
|
||||
```
|
||||
|
||||
Authentication
|
||||
--------------
|
||||
|
||||
Prometheus Alertmanager [does not provide any form of authentication][1] by
|
||||
default. For convenience, this plugin will support Basic Auth if it has
|
||||
been configured (using a reverse proxy or otherwise). Any other form of
|
||||
authentication will require development work by the user.
|
||||
|
||||
[1]: (https://prometheus.io/docs/operating/security/#authentication-authorization-and-encryption)
|
||||
|
||||
**Example of BasicAuth configuration**
|
||||
|
||||
```python
|
||||
ALERTMANAGER_API_URL = 'http://localhost:9093'
|
||||
ALERTMANAGER_USERNAME = 'promuser'
|
||||
ALERTMANAGER_PASSWORD = 'prompass'
|
||||
```
|
||||
|
||||
Troubleshooting
|
||||
---------------
|
||||
|
||||
|
|
|
@ -15,12 +15,19 @@ LOG = logging.getLogger('alerta.plugins.prometheus')
|
|||
DEFAULT_ALERTMANAGER_API_URL = 'http://localhost:9093'
|
||||
|
||||
ALERTMANAGER_API_URL = os.environ.get('ALERTMANAGER_API_URL') or app.config.get('ALERTMANAGER_API_URL', None)
|
||||
ALERTMANAGER_API_KEY = os.environ.get('ALERTMANAGER_API_KEY') or app.config.get('ALERTMANAGER_API_KEY', '') # not used
|
||||
ALERTMANAGER_USERNAME = os.environ.get('ALERTMANAGER_USERNAME') or app.config.get('ALERTMANAGER_USERNAME', None)
|
||||
ALERTMANAGER_PASSWORD = os.environ.get('ALERTMANAGER_PASSWORD') or app.config.get('ALERTMANAGER_PASSWORD', None)
|
||||
ALERTMANAGER_SILENCE_DAYS = os.environ.get('ALERTMANAGER_SILENCE_DAYS') or app.config.get('ALERTMANAGER_SILENCE_DAYS', 1)
|
||||
|
||||
|
||||
class AlertmanagerSilence(PluginBase):
|
||||
|
||||
def __init__(self, name=None):
|
||||
|
||||
self.auth = (ALERTMANAGER_USERNAME, ALERTMANAGER_PASSWORD) if ALERTMANAGER_USERNAME else None
|
||||
|
||||
super(AlertmanagerSilence, self).__init__(name)
|
||||
|
||||
def pre_receive(self, alert):
|
||||
return alert
|
||||
|
||||
|
@ -68,7 +75,7 @@ class AlertmanagerSilence(PluginBase):
|
|||
LOG.debug('Alertmanager: data=%s', data)
|
||||
|
||||
try:
|
||||
r = requests.post(url, json=data, timeout=2)
|
||||
r = requests.post(url, json=data, auth=self.auth, timeout=2)
|
||||
except Exception as e:
|
||||
raise RuntimeError("Alertmanager: ERROR - %s" % e)
|
||||
LOG.debug('Alertmanager: %s - %s', r.status_code, r.text)
|
||||
|
@ -90,7 +97,7 @@ class AlertmanagerSilence(PluginBase):
|
|||
base_url = ALERTMANAGER_API_URL or alert.attributes.get('externalUrl', DEFAULT_ALERTMANAGER_API_URL)
|
||||
url = base_url + '/api/v1/silence/%s' % silenceId
|
||||
try:
|
||||
r = requests.delete(url, timeout=2)
|
||||
r = requests.delete(url, auth=self.auth, timeout=2)
|
||||
except Exception as e:
|
||||
raise RuntimeError("Alertmanager: ERROR - %s" % e)
|
||||
LOG.debug('Alertmanager: %s - %s', r.status_code, r.text)
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
|
||||
from setuptools import setup, find_packages
|
||||
|
||||
version = '5.3.6'
|
||||
version = '5.4.0'
|
||||
|
||||
setup(
|
||||
name="alerta-prometheus",
|
||||
|
|
Loading…
Add table
Reference in a new issue