mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Merge pull request #51174 from jpsv/2018.3
Update OpsGenie to use their V2 API (2018.3)
This commit is contained in:
commit
a96deed641
2 changed files with 20 additions and 13 deletions
|
@ -29,7 +29,7 @@ import requests
|
|||
import salt.exceptions
|
||||
import salt.utils.json
|
||||
|
||||
API_ENDPOINT = "https://api.opsgenie.com/v1/json/saltstack?apiKey="
|
||||
API_ENDPOINT = "https://api.opsgenie.com/v2/alerts"
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
|
||||
|
@ -68,14 +68,14 @@ def post_data(api_key=None, name='OpsGenie Execution Module', reason=None,
|
|||
functionality you must provide name field for both states like in
|
||||
this case.
|
||||
'''
|
||||
if api_key is None or reason is None or action_type is None:
|
||||
if api_key is None or reason is None:
|
||||
raise salt.exceptions.SaltInvocationError(
|
||||
'API Key or Reason or Action Type cannot be None.')
|
||||
'API Key or Reason cannot be None.')
|
||||
|
||||
data = dict()
|
||||
data['name'] = name
|
||||
data['reason'] = reason
|
||||
data['actionType'] = action_type
|
||||
data['alias'] = name
|
||||
data['message'] = reason
|
||||
# data['actions'] = action_type
|
||||
data['cpuModel'] = __grains__['cpu_model']
|
||||
data['cpuArch'] = __grains__['cpuarch']
|
||||
data['fqdn'] = __grains__['fqdn']
|
||||
|
@ -93,8 +93,17 @@ def post_data(api_key=None, name='OpsGenie Execution Module', reason=None,
|
|||
log.debug('Below data will be posted:\n%s', data)
|
||||
log.debug('API Key: %s \t API Endpoint: %s', api_key, API_ENDPOINT)
|
||||
|
||||
response = requests.post(
|
||||
url=API_ENDPOINT + api_key,
|
||||
data=salt.utils.json.dumps(data),
|
||||
headers={'Content-Type': 'application/json'})
|
||||
if action_type == "Create":
|
||||
response = requests.post(
|
||||
url=API_ENDPOINT,
|
||||
data=salt.utils.json.dumps(data),
|
||||
headers={'Content-Type': 'application/json',
|
||||
'Authorization': 'GenieKey ' + api_key})
|
||||
else:
|
||||
response = requests.post(
|
||||
url=API_ENDPOINT + "/" + name + "/close?identifierType=alias",
|
||||
data=salt.utils.json.dumps(data),
|
||||
headers={'Content-Type': 'application/json',
|
||||
'Authorization': 'GenieKey ' + api_key})
|
||||
|
||||
return response.status_code, response.text
|
||||
|
|
|
@ -86,9 +86,7 @@ def create_alert(name=None, api_key=None, reason=None, action_type="Create"):
|
|||
if __opts__['test'] is True:
|
||||
ret[
|
||||
'comment'] = 'Test: {0} alert request will be processed ' \
|
||||
'using the API Key="{1}".'.format(
|
||||
action_type,
|
||||
api_key)
|
||||
'using the API Key="{1}".'.format(action_type, api_key)
|
||||
|
||||
# Return ``None`` when running with ``test=true``.
|
||||
ret['result'] = None
|
||||
|
|
Loading…
Add table
Reference in a new issue