Mattermost Integrations Guide, Episode One: A New Hook

Introduction

One of the great things about Mattermost is how well it integrates with all the other systems you use. But this flexibility can make it difficult to figure out which integration to use for each purpose. This series will review the various ways Mattermost can connect to other systems to give you an idea of what is possible and when to use what method.

Incoming Webhooks: An Easy Introduction to Integrations

The first integration I’ll be covering is incoming webhooks. These are the easiest to set up and give you a lot of easy wins when it comes to integrations. Instructions for setting up and configuring an incoming webhook are available in our documentation, but what can you do with it once it’s created?

Mattermost webhooks allow any system that can send a HTTP request to the Mattermost server to post to a channel. So use them when there’s anything you want to be notified in a specific channel or any channel you are able to post in.

Because Mattermost incoming webhooks are Slack-compatible, any system you have that can send messages to Slack can now send updates to Mattermost. You’ll just have to change the URL to match the Mattermost webhook URL.

Another tip for using webhooks is to change the username and profile picture based on the sender and status of the message. If possible, configure your alerting system to use separate webhooks that have special icons or usernames that show you at a glance whether a notification is urgent.

An example: Logging cron job output automatically

Like many system administrators I have periodic tasks—called cron jobs—and would like to see their output.

#!/bin/bash

### mattermost_log.sh
#
# Sends info level notifications to Mattermost

webhook_url="https://mattermost.movetoiceland.com/hooks/4aroce5imbfa5p6h4kj16qnqdo"

username="$HOSTNAME Info Log"

info_log_text=""

while read line
do
	info_log_text+="$line\n"
done

echo $info_log_text

curl -i -X POST --data-urlencode "payload={\"username\": \"$username\", \"text\": \"$info_log_text\"}" $webhook_url

Now, modify your crontab to pipe the output of the cron file to the script:

@daily /usr/bin/daily-tasks.sh | /path/to/script/mattermost_log.sh

Now the output will be logged to Mattermost automatically!

Learn more about incoming webhooks

As you can see, incoming webhooks give you a simple but powerful way to bring information into Mattermost where your team can take action on it. This simple example just scratched the surface, but our documentation has more advanced examples. Remember that anything that can send an HTTP request to your Mattermost server can use a webhook, from scripts to programs to entire CI/CD pipelines!

In my next installment, I’ll be covering outgoing webhooks and giving some ideas on where and how to use them.

Share this article:

mm

Paul Rothrock

Paul Rothrock is the Customer Community Manager at Mattermost, Inc. Prior to joining Mattermost, he served as a support product manager for Oracle. Paul also worked in tech support and as a publisher advocate for AddThis and has held several other software development roles over the years. Paul holds a bachelor of science degree in information sciences and technology from Penn State University.

To get future blog posts to your inbox, subscribe below.

We use cookies for advertising, social media and analytics purposes. Read about how we use cookies here. By continuing to use this site, you consent to our use of cookies.