Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Table of Contents
maxLevel4
include[A-Za-z0-9_].*

Introduction

opEvents can send messages to slack through a perl 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

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

Code Block
mkdir /usr/local/nmis9/scripts

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

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

...

Set the script's permissions with the command:

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

where /usr/local/nmis9 is the path to your nmis 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."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 browserIn Once authenticated, in the upper right, click System, then Edit Event Actions.

...

Immediately under the line that reads:

"script" : {

add Add the text:

...

Code Block
      "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:

Click Then click the Validate button up top.   If you are told that the syntax is ok, click SaveIf 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:

...

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:

Code Block
            "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:

Code Block
/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:

Code Block
exec failed: Permission denied

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

Code Block
     "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.