Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions plugins/prometheus/alerta_prometheus.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def status_change(self, alert, status, text):
alert.event, alert.resource)
base_url = ALERTMANAGER_API_URL or alert.attributes.get(
'externalUrl', DEFAULT_ALERTMANAGER_API_URL)
url = base_url + '/api/v1/silence/%s' % silenceId
url = base_url + '/api/v2/silence/%s' % silenceId
try:
r = requests.delete(url, auth=self.auth, timeout=2)
except Exception as e:
Expand Down Expand Up @@ -90,7 +90,7 @@ def take_action(self, alert: Alert, action: str, text: str, **kwargs) -> Any:
if action == 'close':
LOG.warning(
'Got a close action so trying to close this in alertmanager too')
url = base_url + '/api/v1/alerts'
url = base_url + '/api/v2/alerts'
raw_data_string = alert.raw_data
raw_data = json.loads(raw_data_string)
# set the endsAt to now so alertmanager will consider it expired or whatever
Expand Down Expand Up @@ -126,11 +126,13 @@ def take_action(self, alert: Alert, action: str, text: str, **kwargs) -> Any:
'matchers': [
{
'name': 'alertname',
'value': alert.event
'value': alert.event,
"isRegex": False
},
{
'name': 'instance',
'value': alert.resource
'value': alert.resource,
"isRegex": False
}
],
'startsAt': datetime.datetime.utcnow().replace(microsecond=0).isoformat() + '.000Z',
Expand All @@ -149,7 +151,7 @@ def take_action(self, alert: Alert, action: str, text: str, **kwargs) -> Any:
base_url = ALERTMANAGER_API_URL or alert.attributes.get(
'externalUrl', DEFAULT_ALERTMANAGER_API_URL)

url = base_url + '/api/v1/silences'
url = base_url + '/api/v2/silences'

try:
r = requests.post(url, json=data, auth=self.auth, timeout=2)
Expand Down Expand Up @@ -178,7 +180,7 @@ def take_action(self, alert: Alert, action: str, text: str, **kwargs) -> Any:
if silenceId:
base_url = ALERTMANAGER_API_URL or alert.attributes.get(
'externalUrl', DEFAULT_ALERTMANAGER_API_URL)
url = base_url + '/api/v1/silence/%s' % silenceId
url = base_url + '/api/v2/silence/%s' % silenceId
try:
r = requests.delete(url, auth=self.auth, timeout=2)
except Exception as e:
Expand Down