-1

Very new to python. I am in need of a sample code in python that would allow me to get the list of alerts/alarms configured in Grafana. Thanks for your help.

I have tried googling and searching on github but what I could get was a code to create new alarms. But I just want to get the list of alarms. Don't really know how to go about it.

Junior
  • 1
  • 1

1 Answers1

0

There exists a python package for this exact usage grafana_alerts. You want to get Grafana alerts onto your python script using some sort of API.

Installation: pip install grafana_alerts

You'll have to create a config file /etc/grafana_alerts/grafana_alerts.cfg

#
# Grafana alerts configuration file.
#

# The URL where grafana server is listening. It must finish with the character '/' (default value: http://localhost:3130) grafana_url =
http://yourgrafanaserver.com/grafana/

# Grafana token with viewer access (default value: empty string) grafana_token =
qwertysDssdsfsfsdfSFsfsfEWrwrwERwrewrwrWeRwRwerWRwERwerWRwerweRwrEWrWErwerWeRwRwrewerr==

# email to use as alert sender (default value: grafana-alert@localhost) email_from = alert@example.com

# smtp server to use (default value: localhost) smtp_server = localhost

# smtp server host to use (default value: 25)
# if port is not 25, starts a tls session. smtp_port = 25

# smtp server username to use if it is needed. Optional. Leave it commented if not used. (default value: no username)
#smtp_username = my_smtp_username

# smtp server password to use if it is needed. Optional. Leave it commented if not used. (default value: no password)
#smtp_password = my_smtp_password

Add the task to execute it for example each 3 minutes:

*/3 * * * * grafana_alerts

Read more about the package and repository.

Jishan Shaikh
  • 1,572
  • 2
  • 13
  • 31