Sign inSign up

z7sv/grafana-annotations-bot

By z7sv

•Updated 6 months ago

Telegram bot that notifies you when new annotations will be added to Grafana

Image
Monitoring & observability
0

2.4K

z7sv/grafana-annotations-bot repository overview

⁠Telegram Bot for Grafana's Annotations

This is the Grafana annotations⁠ Telegram bot that notifies you when new annotations will be added to Grafana.

⁠Commands

⁠/start tagName,anotherOneTag
You're successfully subscribed for tags:
tagName anotherOneTag
⁠/stop
You're successfully unsubscribe for tags: [tagName anotherOneTag]
⁠/status
Grafana
Version: 5.4.2
Database: ok

Telegram Bot
Version: v2.1.0
Build date: 2024-05-24T15:14:46Z
Go version: go1.21.6
Uptime: Fri, 24 May 2024 15:15:40 UTC

⁠Installation

⁠Docker

docker pull docker.io/z7sv/grafana-annotations-bot:latest

⁠Bolt Storage
docker run -d \
	-e 'GRAFANA_URL=http://grafana:3000' \
	-e 'GRAFANA_TOKEN=XXX' \
	-e 'STORE=bolt' \
    -e 'BOLT_PATH=/data/bot.db' \
	-e 'TELEGRAM_ADMIN=1234567' \
	-e 'TELEGRAM_TOKEN=XXX' \
	-e 'TEMPLATE_PATH=/templates/default.tmpl' \
	-v '/data/grafana-annotations-bot:/data' \
	-v '${PWD}/default.tmpl:/templates/default.tmpl' \
	--name grafana-annotations-bot \
	docker.io/z7sv/grafana-annotations-bot:latest
⁠ETCD Storage
docker run -d \
	-e 'GRAFANA_URL=http://grafana:3000' \
	-e 'GRAFANA_TOKEN=XXX' \
	-e 'STORE=etcd' \
	-e 'ETCD_ENDPOINTS=localhost:2379' \
	-e 'ETCD_TLS_INSECURE=true' \
	-e 'TELEGRAM_ADMIN=1234567' \
	-e 'TELEGRAM_TOKEN=XXX' \
	-e 'TEMPLATE_PATH=/templates/default.tmpl' \
	-v '/data/grafana-annotations-bot:/data' \
	-v '${PWD}/default.tmpl:/templates/default.tmpl' \
	--name grafana-annotations-bot \
	docker.io/z7sv/grafana-annotations-bot:latest
⁠Build from source

go get github.com/zt-sv/grafana-annotations-bot

⁠Configuration
FlagENVRequiredDefaultDescription
--grafana.urlGRAFANA_URLTrueThe URL that's used to connect to the Grafana, example: http://localhost:3000
--grafana.tokenGRAFANA_TOKENTrueThe Bearer token used to connect with Grafana API
--grafana.scrapeIntervalGRAFANA_SCRAPE_INTERVALFalse10sScrape annotations interval
--grafana.tls.insecureGRAFANA_TLS_INSECUREFalsefalseInsecure connection to Grafana API
--grafana.tls.insecureSkipVerifyGRAFANA_TLS_INSECURE_SKIP_VERIFYFalsefalseGrafana TLS config - insecure skip verify
--grafana.tls.certGRAFANA_TLS_CERTFalseGrafana TLS config - client cert file path
--grafana.tls.keyGRAFANA_TLS_KEYFalseGrafana TLS config - client key file path
--store.typeSTORE_TYPEFalseboltThe store to use. Possible values: bolt, etcd
--store.keyPrefixSTORE_KEY_PREFIXFalseannotationsbot/chatsPrefix for store keys
--bolt.pathBOLT_PATHFalse/tmp/bot.dbBolt database file path
--etcd.endpointsETCD_ENDPOINTSFalselocalhost:2379The endpoints that's used to connect to the etcd store
--etcd.tls.insecureETCD_TLS_INSECUREFalsefalseInsecure connection to ETCD
--etcd.tls.insecureSkipVerifyETCD_TLS_INSECURE_SKIP_VERIFYFalsefalseETCD TLS config - insecure skip verify
--etcd.tls.certETCD_TLS_CERTFalseETCD TLS config - client cert file path
--etcd.tls.keyETCD_TLS_KEYFalseETCD TLS config - client key file path
--etcd.tls.caETCD_TLS_CAFalseETCD TLS config - CA file path
--log.jsonLOG_JSONFalsefalseTell the application to log json, default: false
--log.levelLOG_LEVELFalseinfoThe log level to use for filtering logs, possible values: debug, info, warn, error
--telegram.tokenTELEGRAM_TOKENTrueThe token used to connect with Telegram. Token you get from @botfather⁠
--template.pathTEMPLATE_PATHTrueThe path to the template
--telegram.adminTELEGRAM_ADMINTrueTelegram admin IDs
⁠Authentication

Users may be allowed to command the bot specifies by multiply --telegram.admin command line option.

Example:

grafana-annotations-bot --telegram.admin=123 --telegram.admin=456

Or by specifying a newline-separated list of telegram user IDs in the TELEGRAM_ADMIN environment variable.

Example:

TELEGRAM_ADMIN="123\n456" grafana-annotations-bot
⁠Message template

Message template specifies by --template.path command line option or by TEMPLATE_PATH environment variable. Default template⁠

⁠Template variables
Go template variableTypeDescription
{{.Title}}stringAnnotation title
{{.Message}}stringAnnotation message
{{.Tags}}[]stringAnnotation tags
{{.JoinedTags}}stringAnnotation tags joined to string by new line separator
{{.FormattedDate}}stringAnnotation date in RFC1123 format
{{.Text}}stringRaw annotation body string

⁠License

MIT⁠

Tag summary

Content type

Image

Digest

sha256:565c21bb5…

Size

6.6 MB

Last updated

6 months ago

docker pull z7sv/grafana-annotations-bot