Search results for "{{ search.query }}"

No results found for "{{search.query}}". 
View All Results

SaltStack Integration

SaltStack is an intelligent orchestration and configuration management software delivers scalable, event-driven automation for the software-defined data center. OpsGenie is an alert and notification management solution that is highly complementary to SaltStack's state and event mechanism.

What does OpsGenie offer to SaltStack users?

By using OpsGenie’s SaltStack Integration you can create or close alerts in OpsGenie according to the Salt states or events. OpsGenie can determine the right people to notify based on on-call schedules, using email, text messages (SMS), phone calls, iOS & Android push notifications, and escalating alerts until the alert is acknowledged or closed.

Functionality of the integration

  • Alerts can be created/closed according to the Salt States.
  • Alerts can be created/closed according to the Salt's Event Reactor.

Add SaltStack Integration in OpsGenie

  1. Please create an OpsGenie account if you haven't done so already.
  2. Go to OpsGenie's SaltStack Integration page.
  3. Specify who should be notified for SaltStack alerts using the "Teams" field. Autocomplete suggestions will be provided as you type.
  4. Copy the API Key.
  5. Click on "Save Integration."

Configuration in SaltStack

  • Download the OpsGenie's Execution Module.
  • 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:
salt '*' saltutil.sync_all

Integrating OpsGenie with Salt States

After the initial configuration OpsGenie's state module can be used with your 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.

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.

salt salt-minion state.apply disk

We've used the SaltStack's Requisites (onfail, require) for triggering OpsGenie's state module.
If everything goes well, an alert will be 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 Salt's Event Reactor

After the 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 this is the first time that you are using Salt's Event Reactor, append the below configuration into the configuration for your Salt master which is located at /etc/salt/master by default. If you are familiar with Salt's Event Reactor, you can edit your existing reactor configuration.

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 below YAML content.

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

Let's send an event with our custom tag 'og-tag' using the below command.

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

If everything goes well, an alert will be 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

{
    "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

SaltStack Integration