You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Alertmanager does not read telegram token file until there is an alert to send. #4479
changed the title [-]Alertmanager does not read telegram token file until there is an alert to find.[/-][+]Alertmanager does not read telegram token file until there is an alert to send.[/+]on Jul 17, 2025
I agree, this is a valid concern. I was looking through the code and had an idea for how we might be able to address this. Perhaps we could add validation logic directly into the New constructor function for each notifier? This would allow Alertmanager to check the configuration on startup and fail immediately if a notifier is set up incorrectly, providing much faster feedback.
From what I can tell, the initialization flows through the following path:
During startup, the main function calls a process that uses BuildReceiverIntegrations to set up notifiers:
Just one thing to keep in mind is just because file existence is checked at startup time doesn't mean it will still exist at time of use. For example configuration management might have deleted the file to rewrite it but failed. So the file was validated on startup, but the notification still fails because the file was deleted after startup (could be weeks after startup).
For this to truly be robust you will not only want to validate the file exists at startup time but also read it into memory at that time too?
Alertmanager will also reload the configuration when asked. That documentation notes that it will validate the configuration and refuse to reload the configuration if it is not valid. I would assume that we want the same validation to span both startup and reload checks.
Activity
[-]Alertmanager does not read telegram token file until there is an alert to find.[/-][+]Alertmanager does not read telegram token file until there is an alert to send.[/+]pehlicd commentedon Jul 17, 2025
I agree, this is a valid concern. I was looking through the code and had an idea for how we might be able to address this. Perhaps we could add validation logic directly into the New constructor function for each notifier? This would allow Alertmanager to check the configuration on startup and fail immediately if a notifier is set up incorrectly, providing much faster feedback.
From what I can tell, the initialization flows through the following path:
During startup, the main function calls a process that uses BuildReceiverIntegrations to set up notifiers:
alertmanager/cmd/alertmanager/main.go
Line 440 in c653800
BuildReceiverIntegrations then calls the specific New constructor for each configured integration, like for Telegram here:
alertmanager/config/receiver/receiver.go
Line 46 in c653800
Which leads to the constructor itself:
alertmanager/notify/telegram/telegram.go
Line 46 in c653800
Adding validation inside these New methods seems like a pattern that could be applied consistently across all notifiers.
What do the maintainers think of this approach? Happy to hear other thoughts or suggestions.
NorfairKing commentedon Jul 17, 2025
@pehlicd We can go even further and validate that the credentials are valid according to telegram as well: https://telegram-bot-sdk.readme.io/reference/getme
grobinson-grafana commentedon Jul 20, 2025
This to me feels like something that could go in the
amtool check-configcommand?NorfairKing commentedon Jul 20, 2025
@grobinson-grafana Maybe ? I think that command is currently pure (i.e. no network or filesystem access) and maybe we want to keep it that way?
grobinson-grafana commentedon Jul 20, 2025
Just one thing to keep in mind is just because file existence is checked at startup time doesn't mean it will still exist at time of use. For example configuration management might have deleted the file to rewrite it but failed. So the file was validated on startup, but the notification still fails because the file was deleted after startup (could be weeks after startup).
For this to truly be robust you will not only want to validate the file exists at startup time but also read it into memory at that time too?
sysadmind commentedon Jul 21, 2025
Alertmanager will also reload the configuration when asked. That documentation notes that it will validate the configuration and refuse to reload the configuration if it is not valid. I would assume that we want the same validation to span both startup and reload checks.
ultrotter commentedon Nov 14, 2025
I think if we read it at startup we should then keep the value in memory inside the configured object, not re-read it for each notification.