"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "salt/modules/opsgenie.py" between
salt-2019.2.0.tar.gz and salt-2019.2.1.tar.gz

About: SaltStack is a systems management software for data center automation, cloud orchestration, server provisioning, configuration management and more. Community version.

opsgenie.py  (salt-2019.2.0):opsgenie.py  (salt-2019.2.1)
skipping to change at line 32 skipping to change at line 32
''' '''
# Import Python libs # Import Python libs
from __future__ import absolute_import, print_function, unicode_literals from __future__ import absolute_import, print_function, unicode_literals
import logging import logging
import requests import requests
# Import Salt libs # Import Salt libs
import salt.exceptions import salt.exceptions
import salt.utils.json 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__) log = logging.getLogger(__name__)
def post_data(api_key=None, name='OpsGenie Execution Module', reason=None, def post_data(api_key=None, name='OpsGenie Execution Module', reason=None,
action_type=None): action_type=None):
''' '''
Post data to OpsGenie. It's designed for Salt's Event Reactor. Post data to OpsGenie. It's designed for Salt's Event Reactor.
After configuring the sls reaction file as shown above, you can trigger the After configuring the sls reaction file as shown above, you can trigger the
module with your designated tag (og-tag in this case). module with your designated tag (og-tag in this case).
skipping to change at line 70 skipping to change at line 70
can customize this field with OpsGenie's custom actions for other can customize this field with OpsGenie's custom actions for other
purposes like adding notes or acknowledging alerts. purposes like adding notes or acknowledging alerts.
Optional parameters: Optional parameters:
name name
It will be used as alert's alias. If you want to use the close It will be used as alert's alias. If you want to use the close
functionality you must provide name field for both states like in functionality you must provide name field for both states like in
this case. 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( raise salt.exceptions.SaltInvocationError(
'API Key or Reason or Action Type cannot be None.') 'API Key or Reason cannot be None.')
data = dict() data = dict()
data['name'] = name data['alias'] = name
data['reason'] = reason data['message'] = reason
data['actionType'] = action_type # data['actions'] = action_type
data['cpuModel'] = __grains__['cpu_model'] data['cpuModel'] = __grains__['cpu_model']
data['cpuArch'] = __grains__['cpuarch'] data['cpuArch'] = __grains__['cpuarch']
data['fqdn'] = __grains__['fqdn'] data['fqdn'] = __grains__['fqdn']
data['host'] = __grains__['host'] data['host'] = __grains__['host']
data['id'] = __grains__['id'] data['id'] = __grains__['id']
data['kernel'] = __grains__['kernel'] data['kernel'] = __grains__['kernel']
data['kernelRelease'] = __grains__['kernelrelease'] data['kernelRelease'] = __grains__['kernelrelease']
data['master'] = __grains__['master'] data['master'] = __grains__['master']
data['os'] = __grains__['os'] data['os'] = __grains__['os']
data['saltPath'] = __grains__['saltpath'] data['saltPath'] = __grains__['saltpath']
data['saltVersion'] = __grains__['saltversion'] data['saltVersion'] = __grains__['saltversion']
data['username'] = __grains__['username'] data['username'] = __grains__['username']
data['uuid'] = __grains__['uuid'] data['uuid'] = __grains__['uuid']
log.debug('Below data will be posted:\n%s', data) log.debug('Below data will be posted:\n%s', data)
log.debug('API Key: %s \t API Endpoint: %s', api_key, API_ENDPOINT) log.debug('API Key: %s \t API Endpoint: %s', api_key, API_ENDPOINT)
response = requests.post( if action_type == "Create":
url=API_ENDPOINT + api_key, response = requests.post(
data=salt.utils.json.dumps(data), url=API_ENDPOINT,
headers={'Content-Type': 'application/json'}) 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 return response.status_code, response.text
 End of changes. 5 change blocks. 
10 lines changed or deleted 19 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)