@cryptotaxi247 / netdata-1 / commits / 8ceb431a9

add support for sending Telegram notifications to topics (#18173)

Ilya Mashchenko committed Jul 15, 2024 at 19:57 UTC 8ceb431a941465078bb19c14eb33a60252861aa0
3 files changed +11 -3
src/health/notifications/alarm-notify.sh.in
+9 -2
@@ -1515,13 +1515,20 @@ send_telegram() {
1515 notify_telegram=1
1516 notify_retries=${TELEGRAM_RETRIES_ON_LIMIT:-0}
1517
1518 + IFS=":" read -r chatID threadID <<< "${chatid}"
1519 +
1520 + # https://core.telegram.org/bots/api#sendmessage
1521 + api_url="https://api.telegram.org/bot${bottoken}/sendMessage?chat_id=${chatID}"
1522 + if [ -n "${threadID}" ]; then
1523 + api_url+="&message_thread_id=${threadID}"
1524 + fi
1525 +
1526 while [ ${notify_telegram} -eq 1 ]; do
1519 - # https://core.telegram.org/bots/api#sendmessage
1527 httpcode=$(docurl ${disableNotification} \
1528 --data-urlencode "parse_mode=HTML" \
1529 --data-urlencode "disable_web_page_preview=true" \
1530 --data-urlencode "text=${emoji} ${message}" \
1524 - "https://api.telegram.org/bot${bottoken}/sendMessage?chat_id=${chatid}")
1531 + "${api_url}")
1532
1533 notify_telegram=0
1534
src/health/notifications/health_alarm_notify.conf
+1
@@ -413,6 +413,7 @@ DEFAULT_RECIPIENT_KAVENEGAR=""
413
414 # multiple recipients can be given like this:
415 # "CHAT_ID_1 CHAT_ID_2 ..."
416 +# To send alerts to a specific topic within a chat, use `CHAT_ID:TOPIC_ID`.
417
418 # enable/disable sending telegram messages
419 SEND_TELEGRAM="YES"
src/health/notifications/telegram/metadata.yaml
+1 -1
@@ -40,7 +40,7 @@
40 required: true
41 - name: 'DEFAULT_RECIPIENT_TELEGRAM'
42 default_value: ''
43 - description: "Set `DEFAULT_RECIPIENT_TELEGRAM` to the chat ID you want the alert notifications to be sent to. You can define multiple chat IDs like this: -49999333322 -1009999222255."
43 + description: "Set the `DEFAULT_RECIPIENT_TELEGRAM` variable in your config file to your Telegram chat ID (find it with @myidbot). Separate multiple chat IDs with spaces. To send alerts to a specific topic within a chat, use `chatID:topicID`."
44 required: true
45 detailed_description: |
46 All roles will default to this variable if left unconfigured.