mirror of
https://github.com/saltstack/salt.git
synced 2025-04-17 10:10:20 +00:00
Update to V2 API
* Added if/else block for creating or closing an alert * Removed test for "action_type"
This commit is contained in:
parent
14247345a6
commit
f93ce7ca0c
1 changed files with 19 additions and 10 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
|
||||
|
|
Loading…
Add table
Reference in a new issue