alertmanager icon indicating copy to clipboard operation
alertmanager copied to clipboard

Request: Add topic_id as an optional parameter to telegram_config

Open instantdreams opened this issue 1 year ago • 8 comments

What did you do? Configured Alertmanager to use Telegram notifications, and set the chat_id to be a group.

What did you expect to see? The ability to set a topic_id to target a particular topic.

What did you see instead? Under which circumstances? Messages go to first topic, usually General.

Environment

  • System information: Linux 6.1.0-17-amd64 x86_64

  • Alertmanager version: alertmanager, version 0.26.0 (branch: HEAD, revision: d7b4f0c7322e7151d6e3b1e31cbc15361e295d8d) build user: root@df8d7debeef4 build date: 20230824-11:11:58 go version: go1.20.7 platform: linux/amd64 tags: netgo

  • Prometheus version: prometheus, version 2.49.1 (branch: HEAD, revision: 43e14844a33b65e2a396e3944272af8b3a494071) build user: root@6d5f4c649d25 build date: 20240115-16:58:43 go version: go1.21.6 platform: linux/amd64 tags: netgo,builtinassets,stringlabels

  • Alertmanager configuration file:

global:
  resolve_timeout: 10m

route:
  group_by: ['alertname']
  group_wait: 30s
  group_interval: 30s
  repeat_interval: 5m
  receiver: 'id-telegram'

receivers:
- name: 'id-telegram'
  telegram_configs:
  - api_url: https://api.telegram.org
    bot_token: $BOT_TOKEN
    chat_id: $CHAT_ID
    send_resolved: true
  • Prometheus configuration file:
global:
  scrape_interval:     15s
  evaluation_interval: 15s

alerting:
  alertmanagers:
  - static_configs:
    - targets: ['[host-ip]:[port}']

rule_files:
  - 'alert.yml'

scrape_configs:
  - [various-configurations]
  • Logs: n/a

  • Notes: My logging stack is working well, but I would very much like to be able to target a particular topic in Telgram.

instantdreams avatar Jan 16 '24 15:01 instantdreams

Hello, I agree that alertmanager need this feature.

Scealang avatar Feb 05 '24 11:02 Scealang

There is no topic_id in telegram api. We have to add reply_to_message_id in GET request. When we reply to message "The topic "sometopic" was created" we actually send a message into this topic. I guess we should begin with:

	DisableNotifications bool   `yaml:"disable_notifications,omitempty" json:"disable_notifications,omitempty"`
	ParseMode            string `yaml:"parse_mode,omitempty" json:"parse_mode,omitempty"`
	ReplyToMessageID     int64  `yaml:"reply_to_message_id,omitempty" json:"reply_to_message_id,omitempty"`
}

https://github.com/efajunk/alertmanager/compare/main...efajunk-patch-1

efajunk avatar Feb 06 '24 21:02 efajunk

Field is called message_thread_id https://core.telegram.org/bots/api#sendmessage

#3332

we1rdw4y avatar Feb 11 '24 01:02 we1rdw4y

Recommendation to implement message_thread_id and update <telegram_config> to include:

# ID of the message thread (topic) of the forum; for groups (optional)
[ message_thread_id [<int>](https://prometheus.io/docs/alerting/latest/configuration/#int) ]

instantdreams avatar Feb 12 '24 23:02 instantdreams

There are two open PRs for this https://github.com/prometheus/alertmanager/pull/3560 and https://github.com/prometheus/alertmanager/pull/3638.

grobinson-grafana avatar Apr 17 '24 17:04 grobinson-grafana

@grobinson-grafana We've had a few different PRs around this, and its very important to support this functionality. Right now we're in a world where everything is routed to the telegram equivalent of a #general chat on Slack with no ability to change the routing to avoid going to the whole organization.

I think https://github.com/prometheus/alertmanager/issues/3672 is ready to go to alleviate this issue.

Ryan-DL avatar Apr 23 '24 17:04 Ryan-DL

I'm working with @th0th on #3638. Please follow that PR for updates.

grobinson-grafana avatar Apr 23 '24 19:04 grobinson-grafana

Hi! 👋 #3638 has been merged! You can close the issue 🙂

grobinson-grafana avatar May 01 '24 20:05 grobinson-grafana