Giter Club home page Giter Club logo

grafana-email's Introduction

grafana-email

Pipeline Status Docker Stars Docker Pulls Docker Image Version (latest) Docker Image Size (latest) Gitlab Project

Connects to Grafana and sends an e-mail with attached graphs.

Warning! For grafana-email to work, you need the grafana-image-renderer plugin (details also here: Image Rendering). I'm using the docker image grafana/grafana-image-renderer for this. See below the example under Grafana configuration on docker swarm, with grafana-image-renderer

Supported environment variables

Example panel url:

http://grafana1:3001/render/d-solo/gV6maGVZz/e-mail-reports?orgId=1&from=1562006810978&to=1562078810980&panelId=2&width=1000&height=500&tz=Europe%2FOslo

You can see the panel url by selecting Share in a panel menu (click on its name) -> Link -> Direct link rendered image

Variable Default Mandatory Description
GRAFANA_TOKEN - YES the authentication token for Grafana
GRAFANA_DASHBOARD - YES the short code for the dashboard (example: gV6maGVZz/e-mail-reports)
SMTP_FROM - YES the e-mail address of the sender
SMTP_TO - YES the e-mail address of the receipient. Alternatively, a space separated list of recipients.
SMTP_PORT 25 NO the port for the SMTP host
SMTP_HOST localhost NO the SMTP host
SMTP_SUBJECT Grafana Email Report NO the e-mail subject
PANEL_IDS 1 NO comma separated list with the IDs of the panels (example: 2)
PANEL_ORG_ID 1 NO the Grafana organization (in example: 1)
PANEL_FROM now-1d NO the start of the panel time interval (example: 1562006810978)
PANEL_TO now NO the end of the panel time interval (example: 1562078810980)
PANEL_WIDTH 500 NO the width of the image in pixels (example: 1000)
PANEL_HEIGHT 250 NO the height of the image in pixels (example: 500)
PANEL_THEME light NO one of dark, light
GRAFANA_HOST grafana NO the hostname or FQDN of the Grafana host (example: grafana1)
GRAFANA_PORT 3000 NO the port for the Grafana host (example: 3001)
GELF_PORT 12201 NO if GELF_HOST is configured (see below), use this UDP port for logging
LOGLEVEL INFO NO Logging Level
GELF_HOST - NO the GELF capable host, for logging
SMTP_USER - NO fill this out, if your SMTP server requires authentication
SMTP_PASSWORD - NO fill this out, if your SMTP server requires authentication
PANEL_TZ - NO the timezone, needed for timestamp PANEL_FROM or PANEL_TO (example: Europe/Oslo)
PANEL_TIMEOUT - NO the timeout for Grafana to generate the panel
GRAFANA_HEADER_HOST - NO useful if the hostname of the Grafana host/container is set to something than the FQDN in Grafana
GRAFANA_URL_PARAMS - NO add additional URL params (example: var-RequestHost=alex&var-Filters=OriginStatus|!%3D|404)
GRAFANA_SSL_VERIFY TRUE NO set to FALSE to ignore SSL certificate errors
GRAFANA_TIMEOUT 60 NO the number of seconds to wait for the connection to Grafana

Examples

Bash

docker run -it --rm --name=grafana-email \
  -e GRAFANA_TOKEN='MyAmazingTokenFromGrafana=' \
  -e GRAFANA_DASHBOARD="gV6maGVZz/e-mail-reports" \
  -e SMTP_FROM="[email protected]" \
  -e SMTP_TO="[email protected]" \
  -e SMTP_HOST="10.0.10.1" \
  -e PANEL_IDS="2,5,6" \
  -e PANEL_FROM="now-6h" \
  -e PANEL_THEME="light" \
  -e PANEL_TZ="Europe/Berlin" \
  -e GRAFANA_HOST="grafana1" \
  -e GRAFANA_PORT="3001" \
  -e GELF_HOST="graylog" \
  -e GRAFANA_HEADER_HOST="grafana.example.com" \
  -e LOGLEVEL="DEBUG" \
  registry.gitlab.com/ix.ai/grafana-email:latest

systemd example:

Place the files under /etc/systemd/system and run sudo systemctl daemon-reload. You can test it by running sudo systemctl start grafana-email.service --now.

grafana-email.service

[Unit]
Description=Send an e-mail with Grafana graphs
After=docker.service

[Service]
Type=oneshot
ExecStart=docker run -it --rm --name=grafana-email \
-e GRAFANA_TOKEN='MyAmazingTokenFromGrafana=' \
-e GRAFANA_DASHBOARD="gV6maGVZz/e-mail-reports" \
-e SMTP_FROM="[email protected]" \
-e SMTP_TO="[email protected]" \
-e SMTP_HOST="10.0.10.1" \
-e PANEL_IDS="2,5,6" \
-e PANEL_FROM="now-6h" \
-e PANEL_THEME="light" \
-e PANEL_TZ="Europe/Berlin" \
-e GRAFANA_HOST="grafana1" \
-e GRAFANA_PORT="3001" \
-e GELF_HOST="graylog" \
-e GRAFANA_HEADER_HOST="grafana.example.com" \
-e LOGLEVEL="DEBUG" \
registry.gitlab.com/ix.ai/grafana-email:latest

grafana-email.timer

[Unit]
Description=Timer for grafana-email.service daily at 06:59

[Timer]
OnCalendar=06:59

[Install]
WantedBy=multi-user.target

Grafana configuration on docker swarm, with grafana-image-renderer

version: '3.7'

services:
  grafana:
    image: grafana/grafana:latest
    environment:
      GF_INSTALL_PLUGINS: grafana-image-renderer
      GF_LOG_FILTERS: rendering:debug
      GF_RENDERING_SERVER_URL: http://grafana-image-renderer:8081/render
      GF_RENDERING_CALLBACK_URL: http://grafana:3000/
  grafana-image-renderer:
    image: grafana/grafana-image-renderer:latest
    networks:
      - grafana-email
    environment:
      ENABLE_METRICS: 'true'
      LOG_LEVEL: 'info'

Tags and Arch

Starting with version v0.3.0, the images are multi-arch, with builds for amd64, arm64 and armv7. Version v0.4.0 also adds 386 build.

  • vN.N.N - for example v0.3.0
  • latest - always pointing to the latest version
  • dev-master - the last build on the master branch

Resources:

grafana-email's People

Contributors

dependabot[bot] avatar tlex avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

kvaggelakos

grafana-email's Issues

ImportError: attempted relative import with no known parent package

docker run -it --name=grafana-email \

-e GRAFANA_TOKEN='MyAmazingTokenFromGrafana='
-e GRAFANA_DASHBOARD="gV6maGVZz/e-mail-reports"
-e SMTP_FROM="[email protected]"
-e SMTP_TO="[email protected]"
-e SMTP_HOST="10.0.10.1"
-e PANEL_IDS="2,5,6"
-e PANEL_FROM="now-6h"
-e PANEL_THEME="light"
-e PANEL_TZ="Europe/Berlin"
-e GRAFANA_HOST="grafana1"
-e GRAFANA_PORT="3001"
-e GELF_HOST="graylog"
-e GRAFANA_HEADER_HOST="grafana.example.com"
-e LOGLEVEL="DEBUG"
registry.gitlab.com/ix.ai/grafana-email

Traceback (most recent call last):
File "/grafana-email/grafana-email.py", line 15, in
from . import constants
ImportError: attempted relative import with no known parent package

How can I fix it?

Ignore https errors

Hello, we are using grafana with https and used the -e GRAFANA_SSL=https option for the grafana-email container.
But certificate validation fails. Is there an option to ignote certificate errors when connecting?

Not possible to use multiple recipients

Hello, I'm trying to sent my grafana reports to multiple recpients by using comma separated mail addresses as value for the SMTP_TO environment variabele but this is not working. Can you help me out defining multiple recipients? Thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.