Skip to content

Commit

Permalink
Fix API usage
Browse files Browse the repository at this point in the history
* ApiClient is now Client
* API client no longer has send() method, instead has send_alert()
* Alert import no longer needed
  • Loading branch information
ashmckenzie committed Nov 9, 2017
1 parent 013ae17 commit 1ef998c
Showing 1 changed file with 16 additions and 5 deletions.
21 changes: 16 additions & 5 deletions integrations/consul/consulalerta.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#!/usr/bin/env python

from alertaclient.api import ApiClient
from alertaclient.alert import Alert
from alertaclient.api import Client
import sys
import os
import time
Expand Down Expand Up @@ -59,7 +58,7 @@
alerttype = "ConsulAlert"


api = ApiClient(endpoint=url, key=key)
api = Client(endpoint=url, key=key)

SEVERITY_MAP = {
'critical': 'critical',
Expand All @@ -76,11 +75,23 @@ def createalert( data ):
except:
environment = "Production"

alert = Alert(resource=data['Node'], event=data['CheckId'], value=data['Status'], correlate=SEVERITY_MAP.keys(), environment=environment, service=[data['CheckId']], severity=SEVERITY_MAP[data['Status']], text=data['Output'], timeout=timeout, origin=origin, type=alerttype)
for i in range(max_retries):
try:
print("Response:")
print(api.send(alert))
response = api.send_alert(
resource=data['Node'],
event=data['CheckId'],
value=data['Status'],
correlate=SEVERITY_MAP.keys(),
environment=environment,
service=[data['CheckId']],
severity=SEVERITY_MAP[data['Status']],
text=data['Output'],
timeout=timeout,
origin=origin,
type=alerttype
)
print(response)
except Exception as e:
print("HTTP Error: {}".format(e))
time.sleep(sleep)
Expand Down

0 comments on commit 1ef998c

Please sign in to comment.