1602 - SWI - Integrating SW and Slack Ebook
1602 - SWI - Integrating SW and Slack Ebook
by Leon Adato
& Patrick Hubbard
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
WELCOME
WHAT IS THIS GUIDE ABOUT?
This book will help you integrate two of the most amazing tools ever conceived of
by the human mind: SolarWinds and Slack (we may be exaggerating just a bit, but
you’ll have to forgive our enthusiasm). Follow along with us to the end, and what
you’ll have is a system where alerts from SolarWinds will auto-magically appear in
one (or more) channels in Slack, allowing teams to view in real-time, search through
past events, and interact with those alerts to find out more information or even ac-
knowledge them back in the SolarWinds system.
2
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
TABLE OF CONTENTS
Welcome 2
What is this guide about 2
Table of Contents 3
All About 5
About the Authors 5
Leon Adato 5
Patrick Hubbard 5
About Slack 5
About SolarWinds 6
About You 6
What you should already know 6
Getting Started 8
What you’ll need to get this done 8
The Nitty Gritty 9
Overview 9
Step 1: Initial Setup 10
Set up Slack 10
Troubleshooting 12
Set up cURL 13
Troubleshooting 14
Step 2: Set up your first alert 16
A brief word about the “test” button 17
Troubleshooting 19
Step 3a: Add an action using cURL 20
Everything You Always Wanted to Know About the cURL Command 21
A Picture is Worth… 23
Test Early, Test Often 25
Troubleshooting 25
3
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
4
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
ALL ABOUT
ABOUT THE AUTHORS
Leon Adato
Leon Adato is a Head Geek™ and technical evangelist at SolarWinds, and is a Cisco®
Certified Network Associate (CCNA®), MCSE and SolarWinds Certified Professional®.
His experience spans financial, healthcare, food and beverage, and other industries.
Before he was a SolarWinds Head Geek, Adato was a SolarWinds user for over a
decade. His expertise in IT began in 1989 and has led him through roles in classroom
training, desktop support, server support, and software distribution.
Leon’s essays can be found anywhere they will let him post, as well as on Twitter® as
@LeonAdato, and on solarwinds.com.
Patrick Hubbard
Patrick Hubbard is a Head Geek and technical product marketing director at Solar-
Winds. With over 20 years of IT experience spanning network management, data
center, storage networks, VoIP, virtualization, and more. Hubbard’s career in tech-
nology began with in the technogenesis of skunkworks IT at American Airlines®.
Since then, his career has included product management and strategy, technical
evangelism, sales engineering and software development. Hubbard’s focus is appli-
cation and service delivery for startups and Fortune 500® companies alike that span
high tech, transportation, financial services and telecom industries.
You can find Patrick’s thoughts strewn across the internet like seeds on the Ethernet
winds, on Twitter as @FerventGeek, or on solarwinds.com.
ABOUT SLACK
Slack is a web-based tool that facilitates team communication. More than a simple
instant messenger client, Slack allows teams to share not only text messages, but also
files, images, documents and more. Anything that is shared can be commented on,
updated, indexed for searching, and synchronized to other web services.
5
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
ABOUT SOLARWINDS
ABOUT YOU
If you were sitting at your desk thinking, “I love the alerts I’m getting in SolarWinds,
but I wish I could get them in Slack, where my whole team could see them and
respond collaboratively,” then you, my friend have some pretty strange thoughts
and maybe you should get up from that desk every once in a while.
Also, you DEFINITELY can be our friend. Because we were thinking the same thing.
Only, we decided to take a shot at it and see if we could make such a crazy idea
happen.
Before we dig into this, there are a few things that we’re assuming you know about,
or know how to do. We’re not trying to be elitist or anything, it’s just that if you
aren’t comfortable with the skills we list below, you’re going to find a lot of the
concepts – let alone tasks – to be frustrating.
That’s not to say you’re out of luck. We happen to know a community of folks who
are more than willing to help guide you in your journey.
6
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Head over to thwack.com and start reading forum posts, asking questions, and
rubbing elbows with people from across the world who have been EXACTLY in
your position (for some folks, it wasn’t even that long ago!) and who would love to
help shepherd you along.
So take heart, young Padawan! When the student is ready, the teacher will appear!
With all of that said, here’s what you ought to be comfortable with:
7
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
GETTING STARTED
WHAT YOU’LL NEED TO GET THIS DONE:
Now we just listed out skills or areas of knowledge, but there are a few specific
THINGS (such as software, accounts, and access) you will need as well:
8
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Also note that steps 4, 5, and 6 are actually variations of the same step (set up an
alert action) with increasing levels of sophistication. If you are REALLY confident in
your skills—you know, the kind of person who does math problems and crossword
puzzles in pen rather than pencil—then feel free to jump straight to 6.
But we think that going through ALL the steps has value. Remember that it’s the
journey, not the destination that matters most.
9
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
5. Slack will helpfully notify you either the web browser or the mobile app
that a new webhook has been created. Notice a theme emerging here-
instant notification in a stream you’re already watching.
10
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
6. In the web page, you will see a screen that gives you a specific URL. This is
effectively an endpoint you will send all your messages to, which will then inject
them in the channel on Slack. Copy that URL and save it somewhere for later.
7. Examine the options on this page to customize your new webhook. You can
give it a different name, change the icon that displays when a new message
comes in, and lots more.
nce you’ve fiddled with those options a bit, click “Save Settings” at the
8. O
bottom of the page.
11
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Troubleshooting
Most of the troubleshooting at this point will be if you pick the wrong channel,
or lose the URL, or something minor like that.
Now look at the top of the page, where the “breadcrumbs” are located, and click
the “Incoming Webhooks”:
You’ll see a page with any of the Slack teams you are logged into. Click “Config-
ure” next to the one we’re setting up today.
Now you’ll see a list of all the webhooks currently in place for your Slack team.
Click the pencil to edit the one which is broken.
12
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
You are now BACK at the page where the webhook settings are located. You can
Re-generate a new service URL, copy the existing one, change something that you
don’t like, delete the webhook URL in case you posed it to Facebook® or just enjoy
the view. Ok, we know it sounds weird and slightly creepy, but we try not to judge.
TRICK: Remember that this webhook is Open to the Public, so you may come
back and regenerate the URL more often than you may think right now. If you
intend for this service to remain private, and you don’t want people sending un-
wanted messages to your Slack channel, you will probably go through a few
URLs. Fortunately, there’s a list of all URLs you’ve generated and clicking the edit
pencil icon lets you remove any you regret. Regret!? There’s no regret in DevOps!
Set up cURL
The next thing you need to do is get cURL for Windows installed on the SolarWinds
primary poller:
1. RDP to the SolarWinds primary poller
2. Open a browser and go to http://www.confusedbycode.com/curl/
3. D
ownload the correct version of cURL. You need the one that runs with
Administrator privileges. While we would like to insist that you install the
64-bit version, we leave it to your discretion. However, SolarWinds itself
requires a 64bit system, so why you’d go for 32bit here is beyond us.
NOTE: If you need a copy of Microsoft C++ library, you will be prompted
to download and install it here. Just go with the flow.
4. During the install, select advanced and CHOOSE where cURL will be installed.
Pick or create a folder that is a single word because lots of systems don’t like
spaces in path names. Make a note of this path, even go as far as to copy it
into your notes file for ready reference later, for example in step 5.
13
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
5. Test to make sure cURL is running correctly by going to the DOS prompt,
and yes, it IS called a DOS prompt, not “the command prompt” you baby-
faced youngster! Now hush while we take a sip of Ensure®. Typing the
command “<your path>\curl.exe --help”. For example, if you used our
suggestion and put cURL in C:\sw_tools\cURL\ then you would type:
6. Finally, test to make sure cURL running on your system can actually
connect to Slack. At the DOS prompt, type the following line
Troubleshooting
There shouldn’t be any troubleshooting during this step. We’re not saying nothing
could possibly go wrong, just that anything that happens is really abnormal, prob-
ably specific to your environment, and unfortunately you are pretty much on your
own to fix it. But, a great first step is to hit something small with cURL first to ensure
it’s not the bits, path or the way you’re calling it.
For that you can certainly use the DOS command prompt, or because we’re going
to be doing all this the Right Way thank-you-very-much by the end of this tutorial,
use a real admin’s tool, PowerShell.
Start a PowerShell prompt, cd to your cURL install folder’s \bin directory and at the
command prompt type curl google.com [Enter]
14
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Ahh PowerShell, keeping you out of trouble and ensuring you don’t have ambi-
guity in your execute path. And look at the last line, it even tells you it thinks it
knows where it is and suggests adding .\ before curl.exe. So friendly, that Pow-
erShell. Let’s try that again. Type .\curl google.com [Enter]
Ahh much better. If this works for you then cURL is working, and the issue is with
your syntax. See the Everything You Always Wanted To Know About the CURL
Command troubleshooting section for more details.
15
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
In this step we’re going to set up a fairly simple alert. Because we want to test this
alert a lot, we’re looking for something that we can trigger and then fix, easily and fre-
quently, with extreme prejudice. A monitor which checks your primary internet router
is exactly the worst choice you could make.
In this book, we’re going to go with a simple “interface status has changed” alert be-
cause we have a lab and some gear nobody is using and no one will freak out if we
shutdown interfaces. You could also do something like monitor a single switch port
which you can enable/disable/unplug, or a whole device which you can shut off/re-
start, or any other simple up/down type trigger.
Remember, the point here is not the sophistication of the alert, it’s all about getting
the alert action working.
16
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
For NOW, you can click “next” past the rest of the screens and save the alert. There is
obviously more to do, but we’ll get to that shortly.
The test button included in the SolarWinds Orion web-based alert manager is an
amazingly convenient option that calls to many monitoring engineers with the seduc-
tive power of the sirens in “The Odyssey.” And in many cases, the test button works.
However, it has a few drawbacks and we need to make them clear so you don’t trou-
bleshoot problems that aren’t a problem.
As the name implies, the test button will generate a test alert for the trigger you’ve set
up. But the trick here is that there isn’t really a problem to be alerted on, so some parts
of this test alert inevitably go missing or are incomplete and for once as and admin,
that’s perfectly ok.
For example, there’s no “Acknowledge” URL. Why? Because there was no actual alert
triggered, so there’s nothing to acknowledge! If your alert lists “components that are
down,” that list will be blank because as a test alert, none of the components are ac-
tually down. And so on. The goal here is to get something in Slack and test the inte-
gration. Later on we’ll verify the details. Assuming that skeeves you out, how do you
17
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
get around this? Step 1, don’t use the test button. Step 2, set up your alert so that you
can actually trigger it. Step 3, profit. For example, let’s say you want to test “high CPU”
alert that triggers when CPU utilization is over 90%.
First, add criteria that limits your alert to a single machine. That way you don’t end up
triggering 9,000 alerts by accident (don’t laugh, we’ve done it. Twice.).
Next, change the “greater than or equal to 90%” to “less than or equal to 99%.”
18
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Unless the machine you’ve specifically selected is already having a rough day, this alert
should trigger every single time.
NOW all you have to do is hit the “reset” button, and it will trigger again and again,
until you get your alert actions just the way you want them.
Troubleshooting
While there are a number of things that could potentially go wrong at this phase, none
of them are relevant to the integration of SolarWinds and Slack. For that reason, we’re
going to leave you to your own devices (no pun intended). If you are really stuck, we
strongly recommend going over to thwack.com and posting a question. Trust us, ev-
eryone there is very willing to help out.
19
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
In this first example, we’re going to use cURL (remember how we installed it back
in step 1?) which is specially designed to programmatically interact with web pages
and then report the results back to the calling program.
In plain English, this means cURL does the same web browser clicking you would
do, and then sends the results back to you as the output. Edit the alert you start-
ed before, and go to the Alert Actions tab. Then click “Add Action” and select
“Execute an External Program”.
20
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Once you are there, you are going give the Alert Action a name, and add a net-
work path value that looks something like this:
21
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Epic Copy–Paste
Last you’re going to squeeze a lot of cURL call into a little text box, and appreci-
ate editing big chunks of text in an editor not the web. Of course it lets you back
them up and test more easily, and everyone backs up their work correct?. When
you’ve got your cURL call looking the way you want, paste it into the “Network
path to external program” text box.
22
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Save your changes, click the box to the left of your new execute action in the
action list, click the test button and Hello World, you should see this in the Slack
channel of your choice:
Whew! We know that seems like a lot, but once you run through this a couple of
times it will become very familiar.
A Picture is Worth…
But we want to kick it up just a bit, and add some style. Let’s say that
you want your OrionBot Slack user (who doesn’t really exist) to have
a really cool icon. Something like this, and for the record those are
particles not a flame.
23
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
And let’s say you have that icon accessible on the internet here:
http://cool.example.com/slack/orionbot/img/particles.png
You COULD add just one extra variable to make each message show up with that
user icon, like this:
Put it all together, and your command would look something like this. For the
sake of argument, we’re going to say the path to cURL is C:\sw_tools, and the
channel is “#labbot”.
24
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
After you’ve gotten all of this set up (we recommend putting it all together in a
simple text editor like notepad, or better still in a programmer’s editor like Note-
pad++, Sublime, BlueFish®, or whatever you prefer). The next thing you want to do,
like any good developer, is TEST.
What we mean is, go to the DOS prompt, and execute EXACTLY your command.
Doing this from the DOS prompt will show you key error messages that you
wouldn’t see if you went straight to copy-and-pasting into the SolarWinds alert
trigger box.
You didn’t just jump ahead to that step, did you? Nah, we didn’t think you did.
Honest.
Now, when you test this from the DOS prompt, you aren’t going to get the actual
variables–you know, things like the ACTUAL node name. In Slack, you will see
“${nodename}” instead. But that’s ok because now you know there are no critical
errors.
NOW you should go ahead and paste your code into the SolarWinds alert action,
and save everything.
Depending on how you set things up, either use the test button or (if you read
carefully in the “A Brief Word About the Test Button” section) trigger your alert,
and then use the reset button to keep re-triggering it until everything is working
the way you want.
Troubleshooting
The main problems you may encounter here and going forward will be related to
two issues:
For syntax issues the DOS or PowerShell prompts are your friends if you’re sort-
ing out a double-wrapped, twice-escaped, and once Url encoded CURL call. The
challenge is that even if you turn on verbose logging in Orion, the execute CURL
command will eat a lot of the error detail. The only way to catch it is when you run
25
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
26
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
“Stack traces?!” you say, “I hate reading stack traces!” <Sighs, gets glasses, reads stack
trace>. Ah, “remote server returned an error: (500) Internal Server Error.” Easy, Slack is
down, right? Nope. Slack is just saying it barfed on what you sent over to it.
So, to get the real nitty gritty from Slack on why it balked, the first place to start
debugging is always the command line, not in the Alert Action box, and of course
we recommend PowerShell. And because you’re debugging with PowerShell, you
get to take advantage of another handy feature–single-quote strings. That crazy
double-escaped string you’re passing to cURL? Just wrap it in single quotes and it
works great. If Slack accepts your POST you’ll see this:
Slack, would it hurt ya to just send back a little meta besides HTTP 200 OK? Slack
webhooks are terse, no joke. If you really want to see what cURL is up to, add the ver-
bose –v parameter and you’ll get this:
27
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
cURL is not at all terse, but confirms that http://hooks.slack.com most certainly is.
But what Slack is great at, and what cURL, (and later on Invoke–WebRequest) will
expose for you, is helpful debugging information when the data you’re sending is bad.
There are lots of ways to mess this up as you experiment but they’re easy to fix, and
then sin no more.
You’ll even see cURL trying to resolve parts of the test in real time, as cURL can’t even
reach Slack. (In this example we forgot to switch our outer POST payload enclosing
double quotes to singles.)
When your call is good but you pass incorrect data to Slack, it tells you what to fix.
Here’s a bad webhook as indicated by “No Team”:
Slack will also send specific errors for invalid text characters, general JSON property
name problems, and more. In all these cases refer to the Slack developer pages and
you’ll be able to fix them in a jiffy from the command prompt. When you’re good to
go, paste the fixed syntax back into the Alert Execute Action.
If you’re sick of messing with escape characters and wonky string builds, that’s perfectly
normal and why we really recommend using a PowerShell script for this where you can
create JSON the right way, with no cURL, using objects. Read on for an example.
28
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Doing direct cURL commands from within SolarWinds alerts is… fine. It gets the job
done. HOWEVER, if you later decide you want to add additional fields, or change the
channel, or whatever, you will need to manually change (and test! Never forget you
must test!) each and every alert.
The real script (which is called by the shim) is a simple text file and can be changed
separately. Changing the script once will affect every single alert that uses it with no
need to update the Orion alert configuration. It’s also extra handy because multiple
alerts can re-use the same Alert Action. Reuse is a beautiful thing.
”Laziness is a virtue.”
Frame that and put it up over your desk.
Let’s Do This
We’re going to work backwards on this. First, we’re going to create the PowerShell
script and make sure it works, then we’re going to update our alert to use the shim.
1. If you didn’t create that C:\sw_tools folder when you installed cURL on your
primary poller do it now.
2. In that folder, create a new file called “MySlackOrionAlertSender.ps1.”
3. In that file, put (copy/paste or type if you are OCD and/or a masochist) the
following:
29
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
# Define varilables
$curl = ‘C:\sw _ tools\curl\bin\curl.exe’$icon = ‘http://cool.example.com/
slack/orionbot/img/particles.png’
$webhook = ‘https://YOUR _ SLACK _ WEBHOOK’
$channel = ‘labbot’
$username = ‘OrionBot’
30
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
31
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
7. What you should see in slack is a message from OrionBot with the
orionbot icon, that
You know what? You’re probably pretty sharp and we bet you can figure out
the rest from here. You are sending the variables into the script, which then
get processed and placed into a coherent message for Slack, right?
Actually, there isn’t much “on” to move. Once you’ve pasted that line into your
alert, you should test it.
A lot.
32
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Troubleshooting
The biggest issue you’re likely to encounter is calling the script correctly inside the
Alert action. Make sure that these three things are working from the <cough> DOS
command window.
2. The path to the script is correct. If Powershell.exe doesn’t know where to look,
that’s a problem.
3. You’re not passing a wonky parameter to the script. This is a simple position
based example, but there are other ways, including named parameter pass-
ing that may help. Google® passing parameters to PowerShell scrips for tips
and examples.
33
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Nothing. cURL is a perfectly lovely, a perfectly functional way to get stuff out of a pro-
gram and into a web-exposed REST service.
But it’s not the most efficient, flexible, or secure option. What it is, is simple. And that’s
why we started with it. Once you get the hang of it, cURL is extremely straightforward.
Before we even get into the actual steps, we want to clarify something: Nothing
changes in SolarWinds. The alert trigger action can remain exactly the same, because
we’re still just passing variables to a PowerShell script, and letting the script do all the
heavy lifting.
HOWEVER… because this is a learning experience and not exactly real life, we ARE
going to change things a little.
1. First, copy the alert from the last section. Once again, this is so you can look
back at how this whole thing has progressed.
That’s it for SolarWinds. Everything else will be taken care of in the script:
3. Go to C:\sw_tools
34
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
# Munge together the Slack formatted text string, (See Slack API
page for details)
$slackJSON.text = $emoji + $ftime + ‘- `’ + $Caption + ‘` status
changed to *’ + $Status + ‘*’ + “`n” + ‘View: <’ + $Details + ‘|De-
tails>, <’ + $Node + ‘|Node>’ + “`n” + ‘To acknowledge click <’ +
$AckUrl + ‘|here>’
# Send it to Slack
Invoke-WebRequest @webReq
35
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
6. N
ext, let’s break down the key elements of this script. Even though it’s fairly well
commented, this is a teaching guide so we’re not going to leave you hanging
with just “look through the code and it will all make sense” (even though we
hope it actually does!)
• param([string[]]$Caption,[string]$Status,[string]$De-
tails,[string]$Node,[string]$AckUrl) – This is where we define our variables.
Why should we bother? Ask Corey Adler (https://thwack.solarwinds.com/
community/solarwinds-community/geek-speak_tht/blog/2015/12/01/
moar-coding-tip-and-lots-of-caps )
• $emoji = ‘’ – This (and the lines that follow it) set up a cute little enhance-
ment we couldn’t do with cURL. It will set an emoji icon to match the status.
A good status gets you a green heart. A bad status looks like poop (literally!),
and an unknown status is a thought bubble.
• $slackJSON = @{} – This sets up the array that will hold all the JSON vari-
ables. You’ll see it later. Right now, this is just another declared variable.
• $slackJSON.channel = ‘#labbot’ – The Slack channel the alert will show up in.
• $slackJSON.icon_url = ‘http://cool.example.com/slack/orionbot/img/par-
ticles.png’ – As with all the cURL examples, this is the good old avatar that
will show up as the Slack user’s image.
• $slackJSON.text = – This block sets up the content of the actual alert message.
• + $emoji – The emoji for the status (that we set up earlier in the script)
36
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
• + “`n” + ‘To acknowledge click <’ + $AckUrl + ‘|here>’ – A hard return plus
a clickable link for the alert acknowledge.
• $webReq=@{ – This puts everything together into a nice neat usable bundle.
The URL plus the type of content and method (json and POST, respectively),
and the text of the message converted into JSON format.
7. Now test the code. At the regular old DOS prompt, type the following command:
Powershell.exe -File C:\sw _ tools\MySlackOrionAlertSender2.ps1
CapptainMal StillOffTheAir http://www.google.com http://www.xkcd.
com http://www.solarwinds.com
You should now see the following message in Slack:
8. Assuming everything works, you are done. Why? Because we already changed
the shim in the alert trigger area.
37
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Troubleshooting
The most likely problems you’ll encounter will be, wait for it, PowerShell syntax errors.
No biggie, just fix them. Ok, seriously, use Google to find the appropriate TechNet and
stackoverflow articles, tweak and test from the command line and you’re all set. Even
if you’re currently a config jockey by day, programming is fun, and unavoidably neces-
sary to keep a gig as we move to a software defined infrastructure. Experimentation,
even if you’re new to programming won’t hurt a bit.
Now then if you really want to make it easy, check out the end of the Advanced REST
and Orion Alert Integration section for an example of using modularity and reuse to
reduce script errors. Now scat!
38
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Orion ships with another built-in action that’s technically the quickest way to send
alerts to Slack. You don’t need to install cURL, string escapes are easier and you can
still use Orion variables. But with easy comes limited troubleshooting and more main-
tenance. You can’t do authentication, there’s no error reporting, (see reading the Ac-
tion log above), and no logic. That means if you have more than one, you’ll have to
configure each one individually. You can’t change behavior in a script and you can’t
interactively debug in a command window.
But for the sake of completeness, here’s how to do it. You’ll initially find it easy, might
like it and it may perfectly suit your needs. But you’ll be a bad person for using it, and
worse, a less accomplished geek.
First, edit the Trigger Actions section of an Alert, and add a “Send a GET or POST Re-
quest to a Web Server” Action:
Click “Configure Action” and configure the action. Give it a name, paste your web-
hook into the URL text box, select “Use HTTP POST,” and then post the JASON you
want to send to Slack in the “Body to POST” box.
39
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Save your changes and test using the Alert Action test button.
And voila! It’s working, you’re all done. Call it a day and knock off early. Unless
this happens:
What caused this? You may never know. If it’s a transport or HTTP issue you
will get details in the log file, but if there is any issue with your JSON, you’ll
only get “HTTP 500 you stink, go away,” and won’t be able to quickly debug
the payload. This is especially true with the really cool messages we’re sure
you’ll come up with using the very flexible Slack formatting options.
40
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Ok, so how about a compromise rather than wholesale condemnation of this meth-
od? If you want to set up a basic, quick alert to a Slack channel that you can use to
get your team interested and your boss to give you time to configure rich integra-
tion, it’s an ok way to start.
Troubleshooting
There’s not really a lot of options- that’s the good and the bad. If you get a “Failed
to execute HTTP Request” message when you test it, look for transport and HTTP
protocol issues in
C:\ProgramData\Solarwinds\Logs\Orion\ActionsExecutionAlert.log.
For anything else, you’ll just have to experiment with the “Body of POST” JSON and
cross your fingers.
41
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Consider these possibilities using Execute Program Alert Actions and Power-
Shell scripts:
In the first example of our guide you configured a direct cURL integration:
The Orion Execute Program Alert Action called cURL on the command line and cURL
sent an escaped, formatted POST directly to Slack. The downside is you’re stuffing a
lot of long parameters on the DOS command line and all edits must happen in the
Alert config screen.
Now consider what happens when you instead create a script that sends the alert
to Slack:
42
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
In this scenario, we have an extra “thing” to manage, but management is easier. First
the configuration of the Run Command Alert Action is much, much easier to main-
tain. {Path to PowerShell} {path to script} {parameters from Orion variables}. That’s
much easier for development. Second, notice that you can have multiple Alert Actions
call the same script. Maybe you want to pass different variables based on the type of
alert, (Node, Interface, Application, Virtual Machine etc.), but only maintain one script
that does the actual send to Slack. Aaaahh.
As an added bonus, you set up your alerts only once in Orion, and then fiddle with
the presentation details as much as you like, easily. Instead of editing Alert Actions,
you edit a script, save, test from the command line, and you’re done. Oooooh, Ahhhh.
Reuse is a beautiful thing. You can configure the Alert Action only once then reuse
it for many Alerts. It’s a great way to do Alert escalation, thresholding and more.
Because you can pass Alert instance data in the Alert Action config to the script,
the script can reformat based on the Alert ID, rather than the Action definition.
Good golly Miss Molly.
43
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
The real beauty of code comes in cleaning up the quick-typed spoor of your first
version to produce something that’s not brittle. It happens when you realize what
you can do with Orion Alerts and Slack. For example, what about this?
Don’t freak out! We’ll explain what’s going on here. You may find you want to send
certain alerts to specific Slack channels to reach different audiences. You may end up
with lots of Alerts using differentiated Alert Actions based on advanced rules. You may
have a selection of specialized sender scripts that contain specific advanced logic or
formatting, used in different situations. And in those cases the diagram above is actu-
ally pretty straightforward.
This design takes advantage of a small number of PowerShell scripts and lots of reuse
to scale out as far as your inspiration and perspiration take you. For example, you can
name your channels in a common config script, and set properties for their web-
hooks. Then if you need to change the webhook, you set it in a single file, and every
other integration gets updated. Want to reuse complex logic as a function across mul-
tiple PowerShell scripts? W00t, you can do that too, in time for lunch.
44
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Enough telling, more showing. Let’s walk through a setup using nothing but Solar-
Winds Orion, and Slack and you’ll see what we’re nattering on about.
First, pick a folder on the Orion poller where the alert runs and create three files.
Two are PowerShell .ps1 scripts and the other is a JSON config .json file. SlackSu-
perSenderScript.ps1 has an include for SlackAlerterCommon.ps1 which knows
how to read SlackAlerterSettings.json. Is your head exploding yet? Of course not,
because this is easy now that you’ve followed this oh-so-handy guide.
Why did we put the config in JSON instead of XML or text, well let’s take a look at
SlackAlerterSettings.json, while you copy and paste it onto your server. (Filenames
are important here but PowerShell will helpfully barf hints if you make a typo.)
{ “channels” : [
{ “labbot” : {
“webhook” : “https://hooks.slack.com/services/
T09HUKJH4/B0L6G78HH/jPHdT9gbuMsoq4cCnS5G3xnU”,
“username” : “OrionBot”
}},
{ “foobarbaz” : {
“webhook” : “kjshfkjsdf/sdksjdhfsdaf/sadfdfsdsdfdsaf”,
“username” : “OrionBot”
}}
],
“icon _ url” : “http://cool.example.com/slack/orionbot/img/
particles.png”
}
45
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
First, it defines an array of “channels,” named “labbot” and “foobarbaz.” Each has
properties like the webhook and username to use. This means you can have as
many webhooks as you want shared in many scripts, with single point update. Yea
verily. And second, it also has a global “icon_url” property, and I’ll bet you can guess
what that’s for.
So how do we read this file? Easy, we add our second file, SlackAlerterCommon.ps1,
which you can also copy from right here and tweak.
# Load the config file into an global object and add a couple of convenience vaial-
bles, note you may need the fill path to the .json config file here too.
46
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
# Send it to Slack
Invoke-WebRequest @webReq
}
Remember this file is designed to be reused by all of your actual sender scripts and
offload the common work like making the config data available, building some base
objects to make life easier and less error prone and also does the actual work of
sending the data to Slack. Sorry cURL, there’s no place for you here–because you’re
one more layer to install and debug, that’s why.
So last we have the script that does the actual creation and formatting of the mes-
sage we’re sending to Slack. Notice it doesn’t have any configuration details needed
to send the message, the common file takes care of that for us. Everything here is
either receiving the parameters from the Orion Alert Action of formatting output.
Create one more file called SlackSuperSenderScript.ps1 and paste this in. Tweak if
needed for your system, like adding the full paths to the include file.
# Define params to keep it clean when called by the Orion Alert and
allow for named passing rather than positional
Param(
[string]$objectCaption,
[string]$status,
[string]$nodeDisplayName,
[string]$detailsUrl,
[string]$nodeUrl,
[string]$ackUrl,
[string]$alertTriggerCount,
[string]$downTime
)
47
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
# This will work on your desktop as is, but you’ll want the full path to
this file in
# production or Orion won’t be able to find it.
. .\SlackAlerterCommon.ps1
# call a method in the common file to create the slack payload stub
$payload = NewSlackPayload “labbot” “OrionBot” $OrionSlackConfig.icon _ url
# And now the magic of building JSON from hashtables in PowerShell. Look
how beautiful this is!
# Use the Slack formatting guide for ideas https://api.slack.com/docs/
formatting and the attachments
# guide for overall structure https://api.slack.com/docs/attachments.
$attach = @{
title = $objectCaption + ‘ status changed to ‘ + $status
title _ link = $alertUrl
color = GetStatusColor $status
fallback = $objectCaption + ‘ status changed to ‘ + $status + ‘ @’
+ $ftime
text = ‘<’ + $ackUrl + ‘|Acknowledge>’
fields = @(
@{
title = “Time”
value = $ftime
short = $true
},
@{
title = “Node”
value = ‘<’ + $nodeUrl + ‘|’ + $nodeDisplayName + ‘>’
short = $true
},
@{
title = “DownTime”
value = $downTime
short = $true
},
@{
title = “Trigger Count”
value = $alertTriggerCount
short = $true
}
)
}
48
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
We bet you’re getting the picture by now. Notice that all the icky, yucky and evil
URL escaping and other shenanigans are completely gone, and happily forgotten.
It’s easy to read and much easier to debug than one big file. And the best bit is if
you want to completely reformat other messages, you can just clone this one into
something completely different. For extra credit you might even pass the layout
definition in on the Alert Action and have multiple layouts in a single file. The possi-
bilities are endless.
49
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
We’re almost done. The last step is to test it on the PowerShell command line thusly.
(Note we’re checking using incomplete parameter names but don’t have to type
them all out- another neat PowerShell trick.)
PS [Patrick.Hubbard]>.\SlackSuperSenderScript.ps1 -s “Down” -o
“MyBox”-ac “http://solarwinds.com” -nodeUrl “http://google.com
“ -nodeD “FooBar”-alert 200 -down 234
And what should happen is something like this over in your Slack channel:
Wowzers, look at all that slick Slack formatting. It’s using attachments to set a col-
ored bar for the status, includes an action header, and organizes the sub-elements
using fields. The cool thing is that this is not custom code in Slack, we’re just using
their online guide and hacking coolness on the fly. Also notice in the test above
that we’re passing named parameters into the script. This is a really helpful upgrade
when it comes to debugging, because positional parameters stink on ice and are
prone to bit rot.
If that worked for you, then you’re ready to complete the last step, configuring your
Alert Action. On your alert, create a new Execute External Program Action and give
it a cool name.
50
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
Next paste in the following template into the Network path to external program box,
editing the path to your SlackSuperSenderScript.ps1 script:
Powershell.exe -File {script path on Orion poller server}
-objectCaption “${N=SwisEntity;M=Caption}” -status
“${N=SwisEntity;M=Status}” -nodeDisplayName “${N=SwisEntity;M=Node.
DisplayName}” -detailsUrl “${N=Alerting;M=AlertDetailsUrl}”
-nodeUrl “${N=SwisEntity;M=Node.DetailsUrl}” -ackUrl
“${N=Alerting;M=AcknowledgeUrl}” -alertTriggerCount
“${N=Alerting;M=AlertTriggerCount}” -downTime
“${N=Alerting;M=DownTime}”
Notice in this example that instead of trying to remember which parameter goes
where, we name all of them. Check the parms definition at the top of your script
and there they are ready for copy–paste. You can even stick a copy of this right in
your script file as a multi-line comment block.
Click add action, finish saving the parent Alert and you’re ready to test. For this one
we test by un-managing and re-managing an interface because we’re triggering on
status change. You’ll want to make sure your polling interval for your test interface is
2-3 minutes so you won’t sit forever. What should happen is this:
51
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
First the alert query fires and notices that you previously set it into unmanaged
which means for the poller it’s unknown. The side bar is gray just like the status icon
in Orion. Within a couple of minutes the poller fires and the status changes from
Unknown to Up, which causes the Alert to fire again and bada-bing-bada-boom:
You’re green again indicating it’s back up. If you happen to have the Slack mobile app
you’re super green:
Hopefully that wasn’t difficult at all and now everyone on your team is singing your
praises, buying your lunch and urging you to take a three day weekend. OK, probably
not, but one can dream.
52
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
TROUBLESHOOTING
Assuming you got the above script to work from the first command line test, the
most likely issue you may encounter is fat fingering the Alert action script call or
selecting an incorrect SolarWinds Alert variable substitution. The quickest way to
check that is to test the template in Action using the Orion, Manage Alerts Test Ac-
tion button. You should see something like this:
It won’t be fully populated, but it will pick up most of the information from the test
interface you selected in the web test panel. Notice also that the <|{tag}> is visible
because if a URL is blank, Slack shows an empty control.
If that doesn’t work, then go back and paste the template into your PowerShell
command window and you should see something like this:
Notice that all the elements have been replaced with the SWIS API definitions for
each of the variables you’re passing to the script. It’s really handy when you get to
dozens of parameters where one is missing or out of place because you can test
both the Alert engine layer and the script->Slack layer. And who doesn’t like layers
53
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
This section has nothing to do with Slack, very little to do with SolarWinds, and ev-
erything to do with stopping the “noise” that everyone always complains about with
regard to monitoring and alerting.
Intelligent alerting is not about more programming, better macros, etc. It’s about
putting enough information into each alert that recipients understand what hap-
pened and why they received a message. With that information, they’re able to
communicate with you (the monitoring engineer) to fine tune the trigger, timing,
thresholds, etc.
It all starts with what information you include. At one end of the scale, you have the
ugly (but all too common) message:
Better (but still not great) is what we usually see in most monitoring environments:
OK, at least we know what device and element it is, but it’s still a long way from
what any of us who have worked the helpdesk (or on-call) would consider to be
truly useful.
54
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
These values are easily extracted from most monitoring systems. What they give
the recipient is a far more accurate view of what happened (even with something as
simple as a CPU alert).
And at the end of the day, that is what matters most. Not whether you send to Slack
or Jabber® or email. Not whether you have fancy icons and emoji’s.
What matters is that the right people get the right information in time to take deci-
sive action to correct (or better still, avert) a problem that will impact your environ-
ment, and therefore impact your business.
55
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
WRAPPING UP
TAKE A MOMENT TO REFLECT
This has been an amazing journey for us, and we hope you feel the same sense of
excitement over the possibilities these techniques open up for you and your team.
You are now able to get data and interactive links out of SolarWinds and into a col-
laborative online communication platform like (Slack), where teams can be notified
on multiple devices (without having to set up multiple alerts); where you can create
“FYI” messages without wondering which team is actually working the ticket and
which have mentally decided they’re “NOT IT!”; and where you have an ongoing
historic archive of events and the conversations around those events that doesn’t
depend on email, log files, or locally-accessible ticket systems.
Looking beyond SolarWinds and Slack for just a moment, you’ve learned about
cURL and JSON and REST-ful function calls, and how to use those via PowerShell.
That’s not a bad set of skills to have, with or without the monitoring and workgroup
features.
WHAT’S NEXT?
Without really tipping our hand, we’ve opened the door for you to the wide world of
“ChatOps.” This is a whole new category of automation that allows teams to interact
with systems within a text-based communication system (like Slack) using “chatbots.”
Chatbots can do everything from sending information from remote systems into
the chat stream (which we’ve already done) to listening for commands and acting
on them in ways that are amusing (like “Find me a cute cat video”), informative (“Tell
me what the stock price is for a particular company” or “What is the CPU on SERV-
ER123”), to downright useful (“restart the IIS service on SERVER123”).
The only limits are your willingness to code, and your imagination.
56
THE INCOMPLETE GUIDE TO INTEGRATING SOLARWINDS ORION INTO SLACK
DBA SURVIVOR GUIDE: YOUR FIRST 100 DAYS
DEDICATIONS
“For Debbie. Caring for someone who loves their job is clearly more difficult than
caring for someone who hates it, but you have stood by me as I have savored this
dream job called “Head Geek.” Your patience and love have been a constant through
decades of time and generations of family. I still love you more than everything.”
–Leon
“To my wife Mandy, the greatest automation engineer I’ve ever known. I’m truly
honored to pass your white box tests.”
–Patrick
57
© 2016 SolarWinds Worldwide, LLC. All rights reserved.
SOLARWINDS, SOLARWINDS & Design, and ORION are the exclusive property of SolarWinds Worldwide, LLC.
All other trademarks are property of their respective owners. BR-1602