Skip to content
/ grack Public

Chef cookbook for grack - used to send Grafana graphs to Slack

Notifications You must be signed in to change notification settings

cjs226/grack

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grack Cookbook

This cookbook provides resources for configuring and managing cron jobs to send Grafana graphs to Slack. Grack in the wild

Steps to get it up and running

  • Create a Data Bag named grack

  • Generate a Grafana API Key

  • Store the key in an encrypted Data Bag Item name grafana in the grack Data Bag with the key api_key.

  • Example:

      {
        "id": "grafana",
        "api_key": "abc123oibTdsYWRTMWtMUnFWR2pGRlpjenRUMWRCMndERmZIV3YiLCJuIjoicmVhZG9ubHkiLCJpZCI6MX0="
      }
    
  • Generate a Slack API Token

  • Store store the token in an encrypted Data Bag Item named slack in the grack Data Bag with the key api_token.

  • Example:

      {
        "id": "slack",
        "api_token": "xoxb-abc12371906-o2HBliCwGgG3R4GS6TPcGzYk"
      }
    
  • Set the following attributes

    • node['grack']['graphs']['name_of_graph']['dashboard']['name'] : Grafana dashboard name

    • node['grack']['graphs']['name_of_graph']['dashboard']['id']: Grafana dashboard id

    • node['grack']['graphs']['name_of_graph']['dashboard']['org_id']: Grafana org ID

    • node['grack']['grafana']['name_of_graph']['dashboard']['variables']: Any Grafana variables the graph depends on

    • node['grack']['graphs']['name_of_graph']['hour']: Hour to send the graph. Default is 0

    • node['grack']['graphs']['name_of_graph']['minute']: Minute to send the graph. Default is 30

    • node['grack']['graphs']['name_of_graph']['panel_id']: Grafana graph panel ID

    • node['grack']['graphs']['name_of_graph']['past_hours']: Number of hours, in the past, to graph. Default is 24

    • node['grack']['graphs']['name_of_graph']['slack_channel']: Slack channel to send graph to

    • node['grack']['graphs']['name_of_graph']['sleep_time']: Amount of seconds to sleep before generating the graph. This is helpful if you're sending a number of graphs during the same minute and would like them sent in the same order each time.

    • node['grack']['grafana']['host']: The FQDN of the Grafana server. Default is localhost

    • Example:

        "grack" => {
          "graphs" => {
            "ireland_production_cpu" => {
              "dashboard" => {
                "name" => "mysql",
                "id" => "abcdefghi",
                "org_id" => 1
              },
              "hour" => 12,
              "minute" => 0,
              "panel_id" => 4,
              "slack_channel" => "ireland_production_status"
            }
          },
          "grafana" => {
            "host" => "foo.bar"
          }
        }
      

Setting defaults

You can set graph_defaults to simplify your config:

  • Example:

      "grack" => {
        "graph_defaults" => {
          "dashboard" => {
            "name" => "mysql",
            "id" => "abcdefghi",
            "org_id" => 1,
          },
          "variables" => {
            "datasource" => "telegraf",
            "environment" => "production"
          },
          "hour" => 12,
          "minute" => 0,
          "slack_channel" => "ireland_production_status"
        },
        "graphs" => {
          "ireland_mysql_connections" => {
            "hour" => "0,12,16,20",
            "panel_id" => 5,
            "sleep_time" => 2
          },
          "ireland_mysql_cpu" => {
            "hour" => "0,16,20",
            "panel_id" => 4
          },
          "ireland_mysql_cpu_for_the_past_7_days" => {
            "panel_id" => 4,
            "past_hours" => 168
          }
        },
        "grafana" => {
          "host" => "foo.bar"
      },
    

Removing cron jobs

To remove an existing cron job, set the graph's delete key to true:

  • node['grack']['graphs'][''name_of_graph'']['delete']: true

  • Example:

      "grack" => {
        "graphs" => {
          "ireland_mysql_connections" => {
            "delete" => true
          }
    

License and Authors

Author: Clif Smith ([email protected])

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at
    
        http://www.apache.org/licenses/LICENSE-2.0
    
    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

About

Chef cookbook for grack - used to send Grafana graphs to Slack

Resources

Stars

Watchers

Forks

Packages

No packages published