This bot is designed to alert messages from grafana.
Forked from prometheus_bot.
docker pull padiazg/grafana-bot
Image page here
export GOPATH="your go path"
make clean
make
-
Create Telegram bot with BotFather, it will return your bot token
-
Specify telegram token in
config.yaml
:telegram_token: "token goes here" # ONLY IF YOU USING TEMPLATE required for test template_path: "template.tmpl" time_zone: "Europe/Rome" split_token: "|" # ONLY IF YOU USING DATA FORMATTING FUNCTION, NOTE for developer: important or test fail time_outdata: "02/01/2006 15:04:05" split_msg_byte: 4000
-
Run
grafana_bot
. Seegrafana_bot --help
for command line options -
Get chat ID with one of two ways
- Start conversation, send message to bot mentioning it
- Add your bot to a group. It should report group id now. To get ID of a group if bot is already a member send a message that starts with
/
Go to Alerting -> Notification channels -> New Channel
Set a name you like, ej. TelegramBotWebhook, and select webhook as Type.
In Url put the address of the instance or container.
Ej:
http://localhost:9087/alert/chat_id
http://my_docker:9087/alert/chat_id
Replace chat_id
with the number you got from your bot, make sure you include the -
if your id has one.
To use multiple chats just add more receivers.
This bot support go templating language. Use it for customising your message.
To enable template set these settings in your config.yaml
or template will be skipped.
telegram_token: "token here"
template_path: "template.tmpl" # your template file name
time_zone: "Europe/Rome" # your time zone check it out from WIKI
split_token: "|" # token used for split measure label.
You can also pass template path with -t
command line argument, it has higher priority than the config option.
WIKI List of tz database time zones
Best way for build your custom template is:
- Enable bot with
-d
flag - Catch some of your alerts in json, then copy it from bot STDOUT
- Save json in testdata/yourname.json
- Launch
make test
-d
options will enable debug
mode and template file will reload every message, else template is load once on startup.
Is provided as default template file with all possibile variable. Remember that telegram bot support HTML tag. Check telegram doc here for list of aviable tags.
Template language support many different functions for text, number and data formatting.
str_UpperCase
: Convert string to uppercasestr_LowerCase
: Convert string to lowercasestr_Title
: Convert string in Title, "title" --> "Title" fist letter become Uppercase- DEPRECATED
str_Format_Byte
: Convert number expressed inByte
to number in related measure unit. It usestrconv.ParseFloat(..., 64)
take look at go related doc for possible input format, usually every think '35.95e+06' is correct converted. Example:- 35'000'000 [Kb] will converter to '35 Gb'
- 89'000 [Kb] will converter to '89 Mb'
HasKey
: Param:dict map, key_search string Search in map if there requeted keystr_FormatDate
: Convert prometheus string date in your preferred date time format, config file paramtime_outdata
could be used for setup your favourite format Require more setting in your cofig.yaml
time_zone: "Europe/Rome"
time_outdata: "02/01/2006 15:04:05"