• Stars
    star
    154
  • Rank 242,095 (Top 5 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 9 years ago
  • Updated 2 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

πŸ“ˆπŸ€– Query Grafana dashboards

Grafana for Hubot

npm version Node CI

Use Hubot to query Grafana dashboards. Inspired by the work of hubot-graphite and hubot-graphme.

Note: This package requires Grafana 5 or higher. If you need support for an older version, use the v2.x releases. As of version 3.x you must use the UID of a given dashboard because of a change in the Grafana API. We strongly recommend using the hubot-alias to save some time in making common requests.

Installation

In the Hubot project repo, run:

npm install hubot-grafana --save

Then add hubot-grafana to your external-scripts.json:

[
  "hubot-grafana"
]

Configuration Variables

General Settings

Configuration Variable Required Description
HUBOT_GRAFANA_HOST Yes^ Host for your Grafana 2.x install, e.g. https://play.grafana.org
HUBOT_GRAFANA_API_KEY Yes^^ Grafana API key (This can be "Viewer" role.)
HUBOT_GRAFANA_PER_ROOM No Allow per room Grafana Host & API key configuration
HUBOT_GRAFANA_QUERY_TIME_RANGE No Default time range for queries (defaults to 6h)
HUBOT_GRAFANA_DEFAULT_WIDTH No Default width for rendered images (defaults to 1000)
HUBOT_GRAFANA_DEFAULT_HEIGHT No Default height for rendered images (defaults to 500)
HUBOT_GRAFANA_DEFAULT_TIME_ZONE No Default time zone for rendered images (defaults to "")
HUBOT_GRAFANA_ORG_ID No Default organization id, need for image rendering in new versions of Grafana (defaults to "")
HUBOT_GRAFANA_API_ENDPOINT No Default rendering api endpoint, need for image rendering in new versions of Grafana (defaults to d-solo)
HUBOT_GRAFANA_USE_THREADS No When set to any value, graphs are sent in thread instead of as new message (only Slack supports this for now).
HUBOT_GRAFANA_MAX_RETURNED_DASHBOARDS No Count of dashboards to return to prevent chat flood (defaults to 25)

^ Not required when HUBOT_GRAFANA_PER_ROOM is set to 1.

^^ Not required for auth.anonymous Grafana configurations. All other authentication models will require a user-specific API key.

Image Hosting Configuration

By default, hubot-grafana will assume you intend to render the image, unauthenticated, directly from your Grafana instance. The limitation is that you will only receive a link to those images, but they won't appear as images in most circumstances in your chat client.

You can use one of the following strategies to host the generated images from Grafana.

Example Configuration

export HUBOT_GRAFANA_HOST=https://play.grafana.org
export HUBOT_GRAFANA_API_KEY=abcd01234deadbeef01234
export HUBOT_GRAFANA_QUERY_TIME_RANGE=1h
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

Sample Interaction

user1>> hubot graf db 000000011
hubot>> Graphite Carbon Metrics: https://play.grafana.org/render/d-solo/000000011/graphite-carbon-metrics/?panelId=1&width=1000&height=500&from=now-6h - https://play.grafana.org/d/000000011/graphite-carbon-metrics?panelId=1&fullscreen&from=now-6h

Grafana Commands

Retrieve a Dashboard

Get all panels in a dashboard. In this example, 000000011 is the UID for the given dashboard. To obtain the UID, use hubot graf list or hubot graf search <term>.

hubot graf db 000000011

Retrieve Specific Panels

Get a single panel of a dashboard. In this example, only the third panel would be returned. Note that this is the visual panel ID, counted from top to bottom, left to right, rather than the unique identifier stored with the panel itself.

hubot graf db 000000011:3

If you want to refer to the API Panel ID, use the :panel-<identifier> format to retrieve it. These will not change when the dashboard is re-arranged.

hubot graf db 000000011:panel-8

Get all panels matching a particular title (case insensitive) in a dashboard. In this case, only panels containing cpu would be returned.

hubot graf db 000000011:cpu

Retrieve Dashboards in a Time Window

Specify a time range for the dashboard. In this example, the dashboard would be set to display data from 12 hours ago to now.

hubot graf db 000000011 now-12hr

If you don't want to show the dashboard uptil now, you can add an extra time specification, which will be the to time slot. In this example, the dashboard would be set to display data from 24 hours ago to 12 hours ago.

hubot graf db 000000011 now-24hr now-12hr

You can combine multiple commands in this format as well. In this example, retrieve only the third panel of the graphite-carbon-metrics dashboard with a window of eight days ago to yesterday.

hubot graf db 000000011:3 now-8d now-1d

Templated Dashboards

Grafana allows dashboards to be set up as templates and accept arguments to generate them through the API. In this example, we get a templated dashboard with the $host parameter set to carbon-a

hubot graf db 000000011 host=carbon-a

Utility Commands

This command retrieves all dashboards and their slugs so they can be used in other commands.

hubot graf list

Dashboards can be tagged for easier reference. In this example, return all dashboards tagged with production.

hubot graf list production

Similarly, you can search the list of dashboards. In this example, return all dashboards that contain the word elb.

hubot graf search elb

Per room configuration

When HUBOT_GRAFANA_PER_ROOM is set to '1' the following commands configure the Grafana Host and API key for the room in which the commands are issued.

hubot graf set host https://play.grafana.org
hubot graf set api_key abcd01234deadbeef01234

More Repositories

1

yammer-oauth2-php

πŸ—£ PHP wrapper for Yammer's API
PHP
10
star
2

hubot-fitbit-leaders

πŸ‘ŸπŸ€– Show a leadeboard for your Hubot's friends on Fitbit
JavaScript
9
star
3

hubot-foursquare-locator

πŸ—ΊπŸ€– Find your friends on Swarm
JavaScript
8
star
4

hubot-github-deployments

πŸš€πŸ€– Integrate with the GitHub deployment API
JavaScript
6
star
5

hubot-untappd-friends

πŸ»πŸ€– Get the latest checkins from your Untappd friends.
JavaScript
4
star
6

arduino-projects

Copy of my Arduino project directory.
Arduino
4
star
7

dashing-bcycle

Example of Dashing Dashboard with BCycle widgets.
JavaScript
3
star
8

raspberrypi-setup

Configuration scripts for a Raspberry Pi + Camera
Shell
3
star
9

hubot-getbacktowork

πŸ˜ πŸ€– When the GIFs and YouTube links get out of control
JavaScript
3
star
10

angularjs-brewery-db

Demonstration of AngularJS and Brewery DB.
HTML
3
star
11

hubot-hockey

πŸ’πŸ€– Get the latest scores and playoff odds for your NHL team.
JavaScript
3
star
12

hubot-bcycle-finder

πŸš²πŸ€– Get the status of nearby BCycle stations
JavaScript
3
star
13

checkyoursource

Scratchpad for perhaps a future project dealing with the trust levels of various news web sites.
2
star
14

hubot-flickr-group-search

πŸ“ΈπŸ€– Search a specified Flickr group for photos
JavaScript
2
star
15

guess-a-number

XCode / C++ tutorial project
Objective-C
2
star
16

hubot-nashville-news

πŸ“°πŸ€– Top local news from Nashville media outlet RSS feeds
JavaScript
2
star
17

google-plus-php

Google+ PHP Client Library
PHP
2
star
18

unfollow-5000

⛔️ Life is too short for spam followers.
Ruby
2
star
19

hubot-createsend

πŸ“§πŸ€– Manage your Campaign Monitor lists and campaigns
JavaScript
2
star
20

hubot-nashville-electric

βš‘οΈπŸ—Ί Get reported power outages in Nashville.
JavaScript
2
star
21

hubot-brightwheel

πŸ‘ΆπŸ“· Show activity and photos from Brightwheel, a daycare management app.
JavaScript
2
star
22

hubot-hue-meeting

πŸ’‘πŸ€– Control your Hue lights for meeting mode
JavaScript
1
star
23

hubot-lyft

πŸš™πŸ€– List estimated arrival times and available Lyft services
CoffeeScript
1
star
24

hubot-dad-jokes

πŸ‘¨β€πŸ‘§β€πŸ‘¦πŸ˜† Dad jokes for your Hubot.
JavaScript
1
star
25

brightwheel-photo-exporter

Export your Brightwheel photos for safe keeping.
Ruby
1
star
26

my-boxen

My Boxen setup
Ruby
1
star
27

ratings-ios-app

XCode / Swift for iOS tutorial project. Added a the `Select Rating` view.
Swift
1
star
28

tripit-share-php

Allows users to share TripIt trip data via e-mail.
PHP
1
star
29

hubot-foursquare-lunch

πŸ₯ͺπŸ€– Figure out where to get lunch
JavaScript
1
star
30

jquery-tablemeter

jQuery plugin to add quick indicator bars to tabluar data.
HTML
1
star
31

wp-mytunes

Very old plugin I wrote to show recent last.fm tracks on my blog.
PHP
1
star
32

hubot-event-tracker

πŸ“† Track days since or days until an event.
JavaScript
1
star
33

hubot-homepage

πŸ πŸ€– Give your bot a default home page
JavaScript
1
star
34

calculator-ios

Simple calculator built from examples during Lecture 1 and 2 in the Developing iOS 8 Apps with Swift course from Stanford University.
Swift
1
star
35

hubot-openweathermap

β˜”οΈπŸŒ‘οΈ Get current weather from OpenWeatherMap
JavaScript
1
star