Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Telegram notifications / change stdout ? #113

Open
Nidwan opened this issue Jul 20, 2023 · 2 comments
Open

Telegram notifications / change stdout ? #113

Nidwan opened this issue Jul 20, 2023 · 2 comments

Comments

@Nidwan
Copy link

Nidwan commented Jul 20, 2023

Hello,

I'm not sure if this is the right place to ask, sorry if it's not.

Is there a way to get Telegram notifications? I would like to receive results of my monthly scrubs on it.

I've tried to modify BTRFS_LOG_OUTPUT in /etc/default/btrfsmaintenance like this but it didn't work:

BTRFS_LOG_OUTPUT="curl -s -X POST https://api.telegram.org/bot<MyTelegramToken>/sendMessage -d chat_id=<MyChatID> -d text="TEST NOTIFICATION""

Even if it works, is it possible to have two BTRFS_LOG_OUTPUT entries, one for stdout and one for Telegram? Or is it the wrong way to go anyway?

Any help would be greatly appreciated. Thanks!

@Nidwan
Copy link
Author

Nidwan commented Jul 21, 2023

For anyone asking the same question and myself for future reference, here's what I did:

I installed telegram.sh and configured it with my Telegram token and my Chat ID.

Then I edited the btrfsmaintenance configuration file:

# /etc/default/btrfsmaintenance
---
BTRFS_LOG_OUTPUT="telegram"

Finally I edited the btrfsmaintenance script I use (only btrfs-scrub in my case):

# usr/share/btrfsmaintenance/btrfs-scrub.sh
---
case "$BTRFS_LOG_OUTPUT" in
        stdout) cat;;
        telegram) cat | /bin/bash /usr/local/bin/telegram -;;
        journal) systemd-cat -t "$LOGIDENTIFIER";;
        syslog) logger -t "$LOGIDENTIFIER";;
        none) cat >/dev/null;;
        *) cat;;

I'm really not sure it's safe to modify these files, as they could be modified in a future update. Make a backup of your modifications!

Any other possibility to implement Telegram notifications is very welcome, as this is probably far to be ideal.

@Nidwan Nidwan closed this as completed Jul 21, 2023
@kdave kdave reopened this Jul 24, 2023
@kdave
Copy link
Owner

kdave commented Jul 24, 2023

I'm not sure if there is another standard way to redirect output on a system-wide logging level, adding it into the maintenance scripts is possible but it could be the wrong place. If you need it just for one of the services then it needs another configuration option. Also for telegram it would require the external script due to the access token, but this is fine as you say above.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants