Grafana dashboard integration into slack using hubot

by Gregor Uhlenheuer on July 16, 2018

I recently wanted to have an easy and interactive way to integrate our Grafana metrics and dashboards into our Slack workspace. It turns out this is really easy and convenient to achieve using hubot - a versatile and customizable bot implementation originally built at github.

In case I have to come back to my steps I will shortly summarize what I tried just now in here.

Slack

The hubot service we are about to create has to be registered in your Slack workspace beforehand. This is just a few clicks away given you have an existing Slack workspace and the necessary permissions to create and administrate the workspace:

  1. Create a new app in the app management page - choose a name and target workspace
  2. Change to "Bot User" page and create a new bot user with the desired “display name”
  3. Now you can navigate to "App page" and register the bot with the workspace you want the bot to live in. After authorization you can copy the Bot OAuth Access Token - we will need this token for the hubot configuration later

Hubot

Now that we have established the basic setup to integrate a slack bot we are going to setup hubot itself. There are numerous ways to achieve that - this is what I did:

After that you are almost ready to start - you have to add the hubot-grafana plugin to the external-scripts.json configuration file first:

Moreover there are a couple of configuration values you can or must set via environment variables.

The bare minimum set of configuration values are the following three:

S3 storage

Instead of directly uploading the PNG image files to Slack you will probably want to utilize a publicly available S3 bucket to store the generated metrics files. The following additional configuration values are needed in that case:

Let’s go

That’s all you have to do - you can now start the bot by specifying the slack adapter:

By default hubot chooses the listen on port 8080 - you may change that by overriding the PORT environment variable:

Interaction with hubot

Once started and connected to your Slack workspace you can interact with the bot either via direct messages or via mentions in all channels the bot was invited into before.

Please refer to the documentation of hubot-grafana for all the possible commands - the most common ones are probably:

References

This post is tagged with linux, programming, grafana, metrics, slack, hubot and bot