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.Image Removed"Activate Incoming Webhooks":

Image Added

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 Where:

  • /usr/local/nmis9 is replaced with your

...

  • NMIS path

...

  • .
  • SERVER is replaced with the IP or domain of your server

...

  • (eg. 192.168.24.85, 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:

Image RemovedImage Added

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:

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" : {
              This would look like the following:

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:

...

)",
                  "script.slacker()"
                ]
			}


After modifying the Event Actions to suit your needs, you can then proceed to press the Save button, and verify the Syntax is OK. Once confirmed, you will then need to restart the opEvents daemon (opeventsd).

Testing the integration

If you have applied the integration to an event that may not occur on a regular occurrence, you can 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-RTR-01 state=down event="Node Down" stateful="Node"

Troubleshooting

exec failed: Permission denied

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 opEvents daemon after making this change.

Slack push notifications - This content can't be displayed.

You may find that Slack push notifications display a "This content can't be displayed" message on some operating systems. A quick modification to your slack_messages.pl will resolve this. Locate the following lines:

Code Block
               \"username\": \"$server opEvents Notifier\",\n

Then underneath both of these (there should be two lines), add the following. Below is an example, but you can modify as you see necessary. Ensure to verify your formatting once changes have been made.

Code Block
				\"text\": \"$node - $event - Priority: $prioritynum\",