Skip to content

Commit

Permalink
add support for multiple alertmanager endpoints
Browse files Browse the repository at this point in the history
Signed-off-by: Nick Revin <[email protected]>
  • Loading branch information
nrvnrvn committed Sep 16, 2019
1 parent 5da3e2a commit 476c616
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions elastalert/alerts.py
Original file line number Diff line number Diff line change
Expand Up @@ -2173,11 +2173,11 @@ def get_info(self):
class AlertmanagerAlerter(Alerter):
""" Sends an alert to Alertmanager """

required_options = frozenset({'alertmanager_host'})
required_options = frozenset({'alertmanager_hosts'})

def __init__(self, rule):
super(AlertmanagerAlerter, self).__init__(rule)
self.url = '{}/api/v1/alerts'.format(self.rule['alertmanager_host'])
self.urls = ['{}/api/v1/alerts'.format(host) for host in self.rule['alertmanager_hosts']]
self.alertname = self.rule.get('alertmanager_alertname', self.rule['name'])
self.labels = self.rule.get('alertmanager_labels', dict())
self.annotations = self.rule.get('alertmanager_annotations', dict())
Expand Down Expand Up @@ -2210,14 +2210,15 @@ def alert(self, matches):
try:
if not self.verify_ssl:
requests.packages.urllib3.disable_warnings()
response = requests.post(
self.url,
data=payload,
headers={'content-type': 'application/json'},
verify=self.verify_ssl,
proxies=self.proxies,
)
response.raise_for_status()
for url in self.urls:
response = requests.post(
url,
data=payload,
headers={'content-type': 'application/json'},
verify=self.verify_ssl,
proxies=self.proxies,
)
response.raise_for_status()
except RequestException as e:
raise EAException("Error posting to Alertmanager: %s" % e)
elastalert_logger.info("Alert sent to Alertmanager")
Expand Down

0 comments on commit 476c616

Please sign in to comment.