Automatic Slack Notifications

Slack is an incredible communication tool for groups of any size (see my recent piece on it). At the company I work for during the day, Slack has become more widely used than email or instant messaging. It truly has become the hub of company communication. So rather than have my servers send email, I've turned to Slack for delivering information to my users. Thankfully, Slack is extremely open to adding applications and integrations.

The simplest integration is called an "incoming webhook", and it delivers messages to Slack channels (or individual users) by sending a POST to a specially formed URL. The first step is to find the custom integration area in Slack, which isn't as clear as I'd like. On the website, click on your Slack group name at the top left, and pick "Apps & Integrations" from the drop-down menu. Then on the apps page, click "build" on the upper right. Finally, click "Make a Custom Integration" and select "incoming webhooks".

From there it's a matter of selecting where you want the notification to post, what icon to give it, what name to assign to your bot and so on. Once it's saved, you can use curl to post a message to your unique URL (which is on the creation page, be sure to copy it to your clipboard):


curl -X POST --data "payload={"text": "Cool Message"}"
 ↪https://hooks.slack.com/services/YOURAPI/CODEHERE/TOPOST

That's it! You can create a BASH script to make the process simple and integrate the notification system into your server scripts!

______________________

Shawn Powers is a Linux Journal Associate Editor. You might find him on IRC, Twitter, or training IT pros at CBT Nuggets.