We have been using Slack at EVT for several months now. It has become an integral part of our internal communication. But Slack is not only good at helping you chat with the rest of your team, it also integrates with many of your favorite web services, such as google hangouts. Another thing Slack does is let you communicate with it through external interfaces. We use this interface to gather information about our internal servers. We do this using a windows batch file, some clever scripting, and Slack’s Slackbot integration. In this two part tutorial I’ll be showing you what you need to make Slackbot tell you when your servers are running low on disk space. Here in part one, we’ll get your Slackbot url, and download a command line utility for sending http requests the Slack service. In part two we’ll look at the code in the batch file, and in the end you should get a message from Slackbot telling you when your server is low on disk space.
The Slackbot integration provides a url to post messages to a channel, which we will use for our free space notifications. Let’s look at how to get one, and what it looks like.
Note: You will need a team admin to proceed with this tutorial.
First you, or a team admin should go into your teams Slack home page. (We’ll use the team name slackteam) Your home page url should look similar to slackteam.slack.com/home. Once you’re there, look to the left navigation and select Configure Apps.
From here, click App Directory at the top near the Slack logo. This will take you to the app page where you can search for Slack apps (they used to be called integrations.)
Here, you are going to search for Slackbot in the search box. You’ll see a result called Slackbot: Easily control your slackbot from external services.
Click on that, then select configure next to the team that you want to use Slackbot with.
Select Add Configuration, then the next page has some information about other options for controlling Slackbot. Just select Add Slackbot Integration to move on to the next page.Now you should be presented with the configuration page for this Slackbot integration. Here you will see your Slackbot url, it should look similar to the one below:
It will start with your teamname.slack.com. Then further down you will see a token parameter. This is what lets the Slack servers know that you are allowed to post messages to this team. It also separates this Slackbot configuration from other Slackbot configurations in your team. You may have also noticed on the configuration page that you have to specify a channel name to post to. So, our full url will look like this:
If you posted a message to this url, you would get that message in your general channel. You can also post to direct messages, by using %40user (%40 is a url encoded @) in the channel parameter. If you use yourself, you will get a message in the Slackbot channel that only you can see. I have found this useful for development, so I don’t bug the rest of my team with a bunch of messages that don’t relate to them.
The last thing we need to do before we can start using your newly acquired url is download Curl. Curl is a command line tool for interacting with different web protocols. We will be using it to post our Slack messages using https. So, go to http://www.paehl.com/open_source/?download=curl_745_0_ssl.zip to download the zip file. Extract the zip so that you get the curl.exe file. Now we have everything we need to script some batch, and send messages.
In part two we’ll take a look at the code in the batch file where we’ll get the disks, check the free space, and send a message when they’re low.