• Products
  • Get started
  • Documentation
  • Resources

Integrate Opsgenie with SaltStack

SaltStack logo

What does Opsgenie offer SaltStack users?

Use Opsgenie’s SaltStack Integration to create or close alerts in Opsgenie according to the Salt states or events. Opsgenie determines the right people to notify based on on-call schedules– notifies via email, text messages (SMS), phone calls, iOS & Android push notifications, and escalates alerts until the alert is acknowledged or closed.

Functionality of the integration

  • Alerts are created/closed according to the Salt States.

  • Alerts are created/closed according to the Salt's Event Reactor.

Add SaltStack Integration in Opsgenie

  1. Go to Opsgenie's SaltStack Integration page.

Under the Free and Essentials plans, the tabs under the Team dashboard are limited to Main, Integrations, Members, and Activity Stream.

2. Specify who is notified of SaltStack alerts using the Responders field. Autocomplete suggestions are provided as you type.

Did you know that you can also add this integration from your team dashboard? 

If you want your team to be the owner of this integration, add it from your team dashboard. Opsgenie will assign the alerts received through this integration to your team only.

To do that;

  1. Go to Teams,

  2. Find your team and select it to go to your team dashboard,

  3. From your team navigation, select Integrations,

  4. Select Add integration.

3. Copy the API Key.

4. Click Save Integration.

SaltStack integration

Configuration in SaltStack

  • Download the Opsgenie's Execution Module.

  • If using Opsgenie from another domain(EU, sandbox etc.) update API_ENDPOINT variable at Opsgenie script. Default configured as (https://api.opsgenie.com).

  • Move the module into a directory named _modules at the root of the Salt fileserver.

  • Download the Opsgenie’s State Module.

  • Move the module into a directory named _states at the root of the Salt fileserver.

  • Apply these module changes to the minions by running command:

Shell

1 salt '*' saltutil.sync_all

Integrating Opsgenie with Salt States

After the initial configuration Opsgenie’s state module can be used with SaLt State files(SLS).

Let's walk through an example use case which creates/closes alerts according to the disk usage of the minion. Create a file named disk.sls located at the root of the Salt fileserver.

YAML

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 used_space: disk.status: - name: / - maximum: 79% - minimum: 10% opsgenie_create_action_sender: opsgenie.create_alert: - api_key: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX - reason: 'Disk capacity is out of designated range.' - name: disk.status - onfail: - disk: used_space opsgenie_close_action_sender: opsgenie.close_alert: - api_key: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX - name: disk.status - require: - disk: used_space

After the creation of the Salt State file, let's try it with the below command.

Shell

1 salt salt-minion state.apply disk

We've used the SaltStack's Requisites (onfailrequire) for triggering Opsgenie’s state module.
After successful configuration, an alert is created/closed in Opsgenie.

Field

Mandatory

Description

api_key

true

It's the API Key you've copied while adding integration in Opsgenie.

reason

true

It will be used as alert's default message in Opsgenie.

name

false

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 this case.

Integrating Opsgenie with SaltStack's Event Reactor

After initial configuration, Opsgenie’s execution module can be used with Salt's Event Reactor.

Let's walk through an example use-case which creates/closes alerts according to the events sent to the Salt's event bus.

If using Salt's Event Reactor for the first time, append the below configuration into the configuration for the Salt master which is located at 

/etc/salt/master

 by default. If familiar with Salt's Event Reactor, edit the existing reactor configuration as desired.

 

YAML

1 2 3 reactor: - 'og-tag': - /srv/salt/reactor/og-reactor.sls

Create the Salt State file 

og-reactor.sls

 located at /srv/salt/reactor/ and paste the YAML content below.

 

YAML

1 2 3 4 5 6 7 8 opsgenie_event_poster: local.opsgenie.post_data: - tgt: 'salt-minion' - kwarg: name: event.reactor api_key: XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX reason: {{ data['data']['reason'] }} action_type: Create

Send an event with the custom tag 

'og-tag'

 using the command below.

 

Shell

1 salt-call event.send 'og-tag' '{"reason" : "Overheating CPU!"}'

If the configuration is successful, an alert is created/closed in Opsgenie.

Field

Mandatory

Description

api_key

true

It's the API Key you've copied while adding integration in Opsgenie.

reason

true

It will be used as alert's default message in Opsgenie.

name

false

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 this case.

action_type

true

Opsgenie supports the default values Create/Close for action_type. You can customize this field with Opsgenie’s custom actions for other purposes like adding notes or acknowledging alerts.

Sample payload sent from SaltStack

JSON

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 { "username": "root", "kernel": "Linux", "uuid": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX", "name": "event.reactor", "kernelRelease": "4.12.13-300.fc26.x86_64", "saltVersion": "2017.7.1", "fqdn": "localhost.localdomain", "saltPath": "/usr/lib/python2.7/site-packages/salt", "cpuArch": "x86_64", "reason": "Overheating CPU!", "actionType": "Create", "host": "localhost", "master": "127.0.0.1", "os": "Fedora", "id": "salt-minion", "cpuModel": "Intel(R) Core(TM) i7-4770HQ CPU @ 2.20GHz" }

Sample alert

Alert created in chapter Integrating Opsgenie with Salt States:

Salt Events sample alert

Alert created in chapter Integrating Opsgenie with Salt's Event Reactor:

SaltStack Event Reactor sample alert

 

Last modified on Jun 18, 2021
Cached at 2:29 PM on Jul 30, 2021 |

Additional Help

Ask the Community