8000 GitHub - Brawcks/grafana-cli
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Brawcks/grafana-cli

 
 

Repository files navigation

grafana-cli

grafana-cli is a command line tool which allows you to execute actions against Grafana api server such as:

  • List grafana alerts
  • Pause grafana alerts
  • Resume grafana alerts

grafana-cli



Getting Started


Clone this repo:

git clone https://github.com/orojina/grafana-cli.git

Copy the .grafana folder into your home directory:

cd grafana-cli
cp -r .grafana ~
cp grafana-cli.sh ~

Update the configuration files for each environment (if you have only one Grafana instance you can use the prod configuration file). The config files must follow the following format; all fields are mandatory except for the GF_EXCLUDE_ALERTS variable which is optional.

grafana-cli


NOTE: The image shows the following sections:

[ENVIRONMENT]

This section contains:

  1. The name of the Grafana environment (dev | qa | prod)
  2. The grafana API server URL
  3. The authorization header to be used on every HTTP request

IMPORTANT: Make sure there is a line break between organizations, so that the confirgurations can be parsed successfully.


NOTE: Don't change the section name; keep it as [Environment]

[ORGANIZATION_A] [ORGANIZATION_B] [ORGANIZATION_N]

These sections are intended to store the Grafana tokens for each Grafana Organization. In this example we are declaring 2 Grafana Organizations ORGANIZATION_A & ORGANIZATION_B but you can have more organizations and name them as you wish. The name you use as the section name is the name of the organization you will be using to load the environment variables using the following command in your terminal:

    source ~/grafana-cli.sh config set-env dev ORGANIZATION_A

NOTE: The Grafana token must have the Grafana admin role of that organization.

IMPORTANT:

  • You should ask within your team if an API KEY already exists for your team usage.
  • If you need to create a new API Token, please refer to the Grafana documentation for instructions on how to create the Grafana token. Be aware that you need to have Organization admin rights to create a new API Token.
  • Make sure the token has the admin role attached.



Dependencies

  • grafana-cli requires jq to be installed.



How to use grafana-cli

Use the following command to see a list of available commands and how to use them

    ~/grafana-cli.sh -h

  • Load environment variables into your terminal session
    source ~/grafana-cli.sh config set-env prod ORGANIZATION_A

grafana-cli


  • Get a list of Grafana alerts
    ~/grafana-cli.sh alerts

grafana-cli



Pro Tip: use the following command to watch the status of your alerts; the alert list will be refreshed every 10 secs:

    watch -c -n 10 "~/grafana-cli.sh alerts"

grafana-cli



  • Pause all alerts in the Grafana Organization
    ~/grafana-cli.sh alerts pause

grafana-cli



  • Pause specific alerts by alertId

Use the -i option followed by the alert IDs you want grafana-cli to pause

    ~/grafana-cli.sh alerts pause -i 2,8,9

grafana-cli



  • Add annotations

Use the `-a` option followed by any text to add an annotation as part of the `pause/resume` action
    ~/grafana-cli.sh alerts pause -i 2,8,9 -a "Pausing alerts due maintenance activities"

grafana-cli grafana-cli



  • Add alerts to the exclusion list

grafana-cli allows you to set an exclusion list, which basically tells grafana-cli to ignore those alerts when pausing/resuming alerts.


All you need to do is to set the GF_EXCLUDE_ALERTS variable with the alert IDs you dont want grafana-cli to touch.

grafana-cli


Note: Whenever you change a config file, you need to make sure to source the confige file in your terminal window, otherwise changes wont be applied.

    source ~/grafana-cli.sh config set-env dev ORGANIZATION_A

grafana-cli

    ~/grafana-cli.sh alerts pause

grafana-cli


Note: To resume alerts just change the pause command from pause to resume

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 99.4%
  • JavaScript 0.6%
0