Skip to end of banner
Go to start of banner

Slack Integration

Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 4 Next »

Introduction

It is possible to push events generated via opEvents to external communication and collaboration tools, such as Slack using a Perl script.

Installation

Install the script

As a pre-requisite, you will need to create a scripts directory located within /usr/local/nmis9 (or where your NMIS9 installation resides), by executing the following command:

mkdir /usr/local/nmis9/scripts

Once complete, then upload the following script to the scripts folder you just created:

Set the script's permissions with the command:

/usr/local/nmis9/bin/nmis-cli act=fixperms

where /usr/local/nmis9 is the path to your NMIS installation.

Create your webhook

Navigate to the slack app page at https://api.slack.com/apps and click the "Create an App" button.

Select "From scratch":

Enter a name for your app and pick the workspace you want to use.  Click "Create App" when you are ready.

Click "Incoming Webhooks":

Click the switch to "Activate Incoming Webhooks":

Click "Add New Webhook to Workspace" at the bottom of the page:

Select the channel you want opEvents to post to and click allow to grant permission:

Scroll down to the bottom of the page and copy your webhook URL - you will need it for the next step.

Integrate with opEvents

Log into your opEvents installation from your browser.  Once authenticated, in the upper right, click System, then Edit Event Actions.

Immediately under the line that reads:

"script" : {

Add the text:

      "slacker" : {
         "exec" : "/usr/local/nmis9/scripts/slack_messages.pl",
         "output" : "save",
         "arguments" : "event._id node.uuid SERVER event.name event.priority event.element event.details event.time WEBHOOK"
      }

Where:

  • /usr/local/nmis9 is replaced with your NMIS path.
  • SERVER is replaced with the IP or domain of your server (eg. 192.168.10.101, or nmis-01.mydomain.net).
  • WEBHOOK is replaced with the webhook we copied in the last step.


When complete this should look like the following:

Then click the Validate button. If you see a 'Syntax OK' prompt, proceed to click Save. You can also click Save and this will also check the syntax is OK.

Add calls to the script

You can now call the script through opEvents with the command:

script.slacker()

How you do this exactly is going to vary depending on how you want the end result to work.  For example, let's add a call to the script when a node goes down.  To do this, scroll down in your Event Actions until you find the line that reads:

            "30" : {
               "BREAK" : "false",
               "IF" : "event.event eq \"Node Down\"",
               "THEN" : [
                  "tag.isbroken(nodedown)",
                  "tag.verybad(42)"
               ]

and add the call inside the square brackets.  The end result should look something like this:

Testing the integration

If you have applied the integration to an event that may not occur on a regular occurrence, you can also run the following command to simulate the event and verify your integration works:

/usr/local/omk/bin/opevents-cli.pl act=create-event node=DC-A-RTR-01 state=down event="Node Down" stateful="Node"

Troubleshooting

In the Event Context of a Event where you have included the script, you see the following in the Scripts section under slacker:

exec failed: Permission denied

To resolve this, you need to make the following modification to the "exec" section:

     "slacker" : {
        "exec" : "perl /usr/local/nmis9/scripts/slack_messages.pl",
        "output" : "save",
        "arguments" : "event._id node.uuid SERVER event.name event.priority event.element event.details event.time WEBHOOK"
       }

You will need to restart the opeventsd daemon once making this change.

  • No labels