mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-12-03 21:18:19 +07:00
[GH-ISSUE #5188] [Feature]: Telegram bot notifications for outbound status changes (up/down) via Observatory #3640
Labels
No labels
backlog
bug
clarification needed
documentation
duplicate
enhancement
github_actions
good first issue
invalid
javascript
New Feature
PR welcomed
pull-request
question
wontfix
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference
MHSanaei/3x-ui#3640
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @Ssentiago on GitHub (Jun 10, 2026).
Original GitHub issue: https://github.com/MHSanaei/3x-ui/issues/5188
Is your feature request related to a problem?
There is no proactive alerting when an outbound goes down. The only way to detect a failed outbound is to manually check the panel UI or wait for client complaints. For multi-node setups (e.g. cascaded exit nodes across different countries) this creates a blind spot — an outbound can be dead for hours without anyone noticing.
Describe the solution you'd like
Telegram bot notifications when an outbound changes its status, leveraging the existing Observatory/BurstObservatory data that Xray-core already collects and the panel already queries for the UI.
Minimal behavior:
Optional / configurable:
Alternatives you've considered
A custom script polling /panel/api/server/xrayObservatory and sending Telegram messages directly. Works, but requires maintaining a separate process and running it as a cronjob or service. The panel already has the bot, the Observatory data, and the notification infrastructure — native integration is cleaner.
Concrete use case
A panel with multiple outbound nodes — when one goes dead, the admin should get a Telegram message immediately rather than discovering it from client complaints.
Mockups, screenshots, or examples
No response
Which parts of the panel would this affect?
Telegram bot
Are you willing to help?
Before submitting
@github-actions[bot] commented on GitHub (Jun 10, 2026):
Thanks for the detailed request and for volunteering to implement it — the use case is clear and the panel already has every building block in place.
What's already there
internal/web/service/xray_metrics.go:70ObservatorySnapshot()returns[]ObsTagSnapshot{Tag, Alive, Delay, LastSeenTime, …}xray_metrics.go:185applyObservatory()server.go:startTask()— old map is ins.obsByTag, new map is innextbefore they are swapped at line 213internal/web/service/tgbot/tgbot_send.go:160SendMsgToTgbotAdmins(msg)internal/web/entity/entity.go:49+setting.go:448TgBotLoginNotify/GetTgBotLoginNotify()— exact same shape needed hereinternal/web/job/check_cpu_usage.gosettingService+tgbotServicedependencies, registered inweb.go:startTask()internal/web/translation/en-US.json:1571cpuThreshold,loginSuccess, etc. — 13 locale files to updateSuggested implementation path
1. Callback hook in
applyObservatory()(recommended)applyObservatory()already has both the old state (s.obsByTag) and the new state (next) in scope before the swap. Add an optional callback:Inside
applyObservatory(), after buildingnextand befores.obsByTag = next:This reacts within the existing 2 s sample cycle — no extra polling loop.
2. Add the setting
In
internal/web/entity/entity.go(afterTgBotLoginNotify):In
internal/web/service/setting.go(afterGetTgBotLoginNotify):3. Wire the callback in
server.go:startTask()4. i18n keys
Add two keys to all 13 files under
internal/web/translation/— one for dead, one for alive. Follow thecpuThresholdpattern at line 1571 ofen-US.json:5. Frontend toggle
Add the
tgBotObservatoryNotifyboolean to the Telegram bot settings section in the React frontend (follows the existingtgBotLoginNotifycheckbox).One prerequisite worth documenting
Observatory data is only available when the
metricsblock is configured in the Xray config template (checked inxray_metrics.go:98-115). IfXrayMetricsService.State().Enabledis false,applyObservatory()is never called with live data, so no transitions will fire. The PR description or UI tooltip should note this dependency.Cooldown / flap suppression (optional but useful)
A simple
map[string]time.Timein the callback closure (or a new field onXrayMetricsService) storing the last notification time per tag is enough to implement the cooldown you mentioned — no additional dependencies needed.Good luck with the PR!