Introduction
opEvents can send messages to slack through a perl script.
Installation
Install the script
Create a scripts directory with the command:
mkdir /usr/local/nmis9/scripts
where /usr/local/nmis9 is the path to your nmis installation.
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.
Get your webhooks
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 into opEvents
Log into your opEvents. 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, and WEBHOOK is replaced with the webhook we copied in the last step. When complete this should look like the following:
Click the Validate button up top. If you are told that the syntax is ok, click Save.
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: