azlux / log2ram

ramlog like for systemd (Put log into a ram folder)
MIT License
2.64k stars 194 forks source link

[Feature] Support for Telegram #178

Closed jliebich closed 2 months ago

jliebich commented 2 years ago

I use log2ram on different Raspberry Pi's.

The feature I miss, is a support for Telegram instead of E-Mail for the error system message if there is not enough place on RAM.

My proposal would be to make it similar as in this project: https://github.com/framps/raspiBackup

Proposal:

Add this options to the config file:

# Telegram token
DEFAULT_TELEGRAM_TOKEN=""
# Telegram target chatid
DEFAULT_TELEGRAM_CHATID=""

If these options are not empty, send the error system message if there is not enough place on RAM via Telegram.

If you do not know how to send Telegram messages via Bash script, you may refer to function sendTelegramMessage() in https://github.com/framps/raspiBackup/blob/master/raspiBackup.sh or https://thecodersblog.com/sending-the-message-on-telegram-using-cUrl/

azlux commented 2 years ago

Hi, I will not implement telegram or other message system (discord/teams/irc...) but we can add a custom command (in the config file) to use instead of the mailcommand. This way you can use the command you want. Good for you ?

xtvdata commented 2 years ago

IMHO the best would be to just trigger a configurable user script to run in case of OOM in the RAM disk. Something like:

ONERROR_USERSCRIPT="/path/to/my-script"

Providing a couple of arguments to the script call, could also be useful:

Then everyone can write his own script to either: send an email, send a message on Telegram, Pushover, etc... This would also allow to option to integrate with more structured monitoring systems (e.g. Zabbix, etc...).

jliebich commented 2 years ago

I like xtvdata's suggestion because it allows everyone (including me) to craft their own customized solution!

xtvdata commented 2 years ago

On the other hand, it might be already possible to send messages leveraging other standard tools...

E.g.:

If you check rsyslog documentation and find an output module that fits your need it's a matter of writing a line of configuration for rsyslog.

The advantage of having an ONERROR_USERSCRIPT is that it would be easier to extrapolate details via arguments, however an error catch somewhere in log2ram with a standardized line in syslog (with a documented structure easy to parse), may achieve the same result (or even better - since it would be more standard and with less code to maintain for @azlux ).

azlux commented 5 months ago

Add custom command here : https://github.com/azlux/log2ram/commit/d368260763935a9bae5d3ad2f16d0e30e127375b