Files
grafana/docs/sources/tutorials/hubot_howto.md
Torkel Ödegaard 96008c9738 Squashed commit of the following:
commit 4113ed00782590187d19dd2f8cbae683f164142c
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Fri Oct 21 10:47:35 2016 +0200

    docs(): minor fix for docs index page

commit 45478d120571519462fac905aadeab5954696690
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Thu Oct 20 14:28:21 2016 +0200

    updated

commit c9c1c1d5a462f85e8001a45218f24102583d7aee
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Thu Oct 20 14:27:34 2016 +0200

    docs(): updated image refs

commit 5fa0f27963968d77bbbbb7edd973847ea72135e3
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Wed Oct 19 14:33:04 2016 +0200

    docs is almost done

commit 6b988c90cb08563e2c27212338c2947e69f6fcc3
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Tue Oct 18 20:45:28 2016 +0200

    almost done

commit 17757c21ed813892ddb1f289f2e52613caf7bcef
Author: Torkel Ödegaard <torkel@grafana.org>
Date:   Tue Oct 18 16:45:48 2016 +0200

    making progress on docs

commit f06c815991dd81b8893912a6da04a17b80b63fda
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Tue Oct 18 14:30:55 2016 +0200

    progress on new docs

commit 5197237426252623de2d8b9cc22ddbbdbb240763
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Tue Oct 18 13:25:26 2016 +0200

    making progress

commit 33e2b6b617f16f65878141cf11e54b2817a2ea96
Merge: de385e5 ecb4a99
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Tue Oct 18 12:17:58 2016 +0200

    Merge branch 'new-docs' of github.com:grafana/grafana into new-docs

commit ecb4a99dd54aa39f17d9bf4d7e132a389812f8fd
Author: Torkel Ödegaard <torkel@grafana.org>
Date:   Tue Oct 18 10:39:59 2016 +0200

    keep urls for now

commit de385e56d86b071cf2150ccf9f1aa06ec5187277
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Mon Oct 17 17:56:18 2016 +0200

    more progress

commit 8469ebc239ab2316cbbc01862e5026737f272f00
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Mon Oct 17 17:08:06 2016 +0200

    progress on new docs

commit e755f656b12534cfcb23bad11f1fa696e43f7428
Merge: 4644a35 35cce3b
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Mon Oct 17 12:21:27 2016 +0200

    Merge branch 'new-docs' of github.com:grafana/grafana into new-docs

commit 4644a35102555204787e91041b50dcbfe0f7a213
Merge: 25c4bef 977cdd5
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Mon Oct 17 12:21:11 2016 +0200

    Merge branch 'master' of github.com:grafana/grafana into new-docs

commit 35cce3bef802fac020a53693b02c112a91a096fc
Author: Torkel Ödegaard <torkel@grafana.org>
Date:   Mon Oct 17 09:31:17 2016 +0200

    progress on #6170

commit 25c4bef629de7d77218ba95cc3bd25fb50bb19d6
Author: Torkel Ödegaard <torkel.odegaard@gmail.com>
Date:   Sun Oct 16 15:05:30 2016 +0200

    fix for osx

commit 6c6b52f975630be87da23dd51beafaecb820cec2
Author: Torkel Ödegaard <torkel@grafana.org>
Date:   Sun Oct 16 12:56:39 2016 +0200

    progress on new docs

commit 6a09633981ab26191d5542dbe3a788846ac6b73d
Author: Torkel Ödegaard <torkel@grafana.org>
Date:   Sat Oct 15 11:39:49 2016 +0200

    progress on new docs

commit 7d533fbc23e41b86fd1ba9c955dd17ae1ad977e5
Author: Torkel Ödegaard <torkel@grafana.org>
Date:   Mon Oct 10 09:25:12 2016 +0200

    making progress on new docs site

commit 50392ce98edfa201977716e92e4a86f9d48ae386
Author: Torkel Ödegaard <torkel@grafana.org>
Date:   Sun Oct 9 20:02:28 2016 +0200

    feat(new docs): progress on new docs site

commit 81a3d3d0952d3a5d790412e90d01ac5a247e0686
Author: Torkel Ödegaard <torkel@grafana.org>
Date:   Fri Oct 7 07:52:11 2016 +0200

    new docs site experiment

commit 704adc98664665b3624087ab38ce29fc9da005f1
Author: Torkel Ödegaard <torkel@grafana.org>
Date:   Sat Oct 1 20:46:53 2016 +0200

    new docs poc
2016-10-21 11:01:34 +02:00

5.1 KiB

+++ title = "How To integrate Hubot and Grafana" type = "docs" keywords = ["grafana", "tutorials", "hubot", "slack", "hipchat", "setup", "install", "config"] [menu.docs] parent = "tutorials" weight = 10 +++

How to integrate Hubot with Grafana

Grafana 2.0 shipped with a great feature that enables it to render any graph or panel to a PNG image. No matter what data source you are using, the PNG image of the Graph will look the same as it does in your browser.

This guide will show you how to install and configure the Hubot-Grafana plugin. This plugin allows you to tell hubot to render any dashboard or graph right from a channel in Slack, Hipchat or Basecamp. The bot will respond with an image of the graph and a link that will take you to the graph.

Amazon S3 Required: The hubot-grafana script will upload the rendered graphs to Amazon S3. This is so Hipchat and Slack can show them reliably (they require the image to be publicly available).

What is Hubot?

Hubot is an universal and extensible chat bot that can be used with many chat services and has a huge library of third party plugins that allow you to automate anything from your chat rooms.

Install Hubot

Hubot is very easy to install and host. If you do not already have a bot up and running please read the official Getting Started With Hubot guide.

Install Hubot-Grafana script

In your Hubot project repo install the Grafana plugin using npm:

npm install hubot-grafana --save

Edit the file external-scripts.json, and add hubot-grafana to the list of plugins.

[
"hubot-pugme",
"hubot-shipit",
"hubot-grafana"
]

Configure

The hubot-grafana plugin requires a number of environment variables to be set in order to work properly.

export HUBOT_GRAFANA_HOST=http://play.grafana.org
export HUBOT_GRAFANA_API_KEY=abcd01234deadbeef01234
export HUBOT_GRAFANA_S3_BUCKET=mybucket
export HUBOT_GRAFANA_S3_ACCESS_KEY_ID=ABCDEF123456XYZ
export HUBOT_GRAFANA_S3_SECRET_ACCESS_KEY=aBcD01234dEaDbEef01234
export HUBOT_GRAFANA_S3_PREFIX=graphs
export HUBOT_GRAFANA_S3_REGION=us-standard

Grafana server side rendering

The hubot plugin will take advantage of the Grafana server side rendering feature that can render any panel on the server using phantomjs. Grafana ships with a phantomjs binary (linux only).

To verify that this feature works try the Direct link to rendered image link in the panel share dialog. If you do not get an image when opening this link verify that the required font packages are installed for phantomjs to work.

Grafana API Key

You need to set the environment variable HUBOT_GRAFANA_API_KEY to a Grafana API Key. You can add these from the API Keys page which you find in the Organization dropdown.

Amazon S3

The S3 options are optional but for the images to work properly in services like Slack and Hipchat they need to publicly available. By specifying the S3 options the hubot-grafana script will publish the rendered panel to S3 and it will use that URL when it posts to Slack or Hipchat.

Hubot commands

  • hubot graf list
    • Lists the available dashboards
  • hubot graf db graphite-carbon-metrics
    • Graph all panels in the dashboard
  • hubot graf db graphite-carbon-metrics:3
    • Graph only panel with id 3 of a particular dashboard
  • hubot graf db graphite-carbon-metrics:cpu
    • Graph only the panels containing "cpu" (case insensitive) in the title
  • hubot graf db graphite-carbon-metrics now-12hr
    • Get a dashboard with a window of 12 hours ago to now
  • hubot graf db graphite-carbon-metrics now-24hr now-12hr
    • Get a dashboard with a window of 24 hours ago to 12 hours ago
  • hubot graf db graphite-carbon-metrics:3 now-8d now-1d
    • Get only the third panel of a particular dashboard with a window of 8 days ago to yesterday
  • hubot graf db graphite-carbon-metrics host=carbon-a
    • Get a templated dashboard with the $host parameter set to carbon-a

Aliases

Some of the hubot commands above can lengthy and you might have to remember the dashboard slug (url id). If you have a few favorite graphs you want to be able check up on often (let's say from your mobile) you can create hubot command aliases with the hubot script hubot-alias.

Install it:

npm i --save hubot-alias

Now add hubot-alias to the list of plugins in external-scripts.json and restart hubot.

Now you can add an alias like this:

  • hubot alias graf-lb=graf db loadbalancers:2 now-20m
Using the alias:

Summary

Grafana is going to ship with integrated Slack and Hipchat features some day but you do not have to wait for that. Grafana 2 shipped with a very clever server side rendering feature that can render any panel to a png using phantomjs. The hubot plugin for Grafana is something you can install and use today!