borgmatic-collective / docker-borgmatic

Borgmatic in Docker
GNU General Public License v3.0
347 stars 92 forks source link

Apprise wont send notifications #318

Closed trash-it closed 5 months ago

trash-it commented 5 months ago

Hi, Unfortunately, apprise won't send any notifications. I tried it with telegram and mail. Both won't work. If I call apprise manually, it works. Manually like this:

apprise -vv -t "Test Message Title" -b "Test Message Body" \ tgram://123456789:abcdefg_hijklmnop/12315544/

When I put it in my config file it won't work. I start borgmatic with my crontxt with:

PATH=$PATH:/usr/bin:/usr/local/bin borgmatic --stats -v 0 > /tmp/backup_run.log

I have the following Version: apprise 1.7.6 borg 1.2.8 borgmatic 1.8.10

And here is my configfile: config-git.yaml.txt

witten commented 5 months ago

Thanks for filing this. Can we get a look at your borgmatic logs when run with --verbosity 2? Thanks!

trash-it commented 5 months ago

Hi, sure:

echo "Starting a backup job." curl -s -X POST https://api.telegram.org/botxxxx/sendMessage -d chat_id=-xxxx-d text="Backup Startet" BORG_EXIT_CODES=*** borg --version --debug --show-rc /etc/borgmatic.d/config.yaml: Borg 1.2.8 /etc/borgmatic.d/config.yaml: Calling apprise hook function initialize_monitor /etc/borgmatic.d/config.yaml: Calling apprise hook function ping_monitor Language set to %s backupserver: Running actions for repository /etc/borgmatic.d/config.yaml: No commands to run for pre-actions hook /etc/borgmatic.d/config.yaml: No commands to run for pre-backup hook

I deleted the hooks: part from my config file. I thought i just have to add the apprise stuff from the documentation (Native Apprise Configuration in Borgmatic 1.8.4+)

witten commented 5 months ago

That's odd.. I would expect to see one of the following log entries after Calling apprise hook function ping_monitor:

And then if there were misconfigurations or errors:

You're not seeing anything like that in your logs?

trash-it commented 5 months ago

No. I restartet the command with an grep and just get this:

/ # borgmatic --stats --verbosity 2 | grep apprise Starting a backup job. {"ok":true,"result":{"message_id":1081,"from":{"id":xxx,"is_bot":true,"first_name":"xxxx","username":"xxxxx"},"chat":{"id":-xxx,"title":"xxx","type":"group","all_members_are_administrators":true},"date":1713551402,"text":"Backup Startet"}} /etc/borgmatic.d/config.yaml: Calling apprise hook function initialize_monitor /etc/borgmatic.d/config.yaml: Calling apprise hook function ping_monitor Starting a backup job.

the first telegram message is my manual curl command. I removed it, because I thought it will cause problems. But nothing changed.

witten commented 5 months ago

Can I see your full command? And what happens if you omit the grep?

trash-it commented 5 months ago

sure.

full command is: borgmatic --stats --verbosity 2

and the result is like above: /etc/borgmatic.d/config.yaml: Running command for pre-everything hook echo "Starting a backup job." Starting a backup job. BORG_EXIT_CODES=*** borg --version --debug --show-rc /etc/borgmatic.d/config.yaml: Borg 1.2.8 /etc/borgmatic.d/config.yaml: Calling apprise hook function initialize_monitor /etc/borgmatic.d/config.yaml: Calling apprise hook function ping_monitor Language set to %s backupserver: Running actions for repository /etc/borgmatic.d/config.yaml: No commands to run for pre-actions hook /etc/borgmatic.d/config.yaml: Running command for pre-backup hook echo "Starting a backup job." Starting a backup job. backupserver: Creating archive

witten commented 5 months ago

I think I found the problem! Your configuration doesn't have a states: option in the apprise: section. Here's the documentation for states: from the borgmatic configuration reference:

    # List of one or more monitoring states to ping for:
    # "start", "finish", "fail", and/or "log". Defaults to
    # pinging for failure only. For each selected state,
    # corresponding configuration for the message title and body
    # should be given. If any is left unspecified, a generic
    # message is emitted instead.

Notice the "Defaults to pinging for failure only." portion of that. That means that unless you add a list of states: to your configuration, borgmatic won't ever ping your Apprise services except in the case of borgmatic failure.

Here's an example configuration of what you could do to solve that:

apprise:
   ...
   states:
       - start
       - finish
       - fail
trash-it commented 5 months ago

yes its working! thanks!

at my first try, I just added this block from the documentation:

` apprise: services:

that I have to create a list with states is not written on the configuration example. thanks for the hint!

trash-it commented 5 months ago

solved with missing states list:

I think I found the problem! Your configuration doesn't have a states: option in the apprise: section. Here's the documentation for states: from the borgmatic configuration reference:

    # List of one or more monitoring states to ping for:
    # "start", "finish", "fail", and/or "log". Defaults to
    # pinging for failure only. For each selected state,
    # corresponding configuration for the message title and body
    # should be given. If any is left unspecified, a generic
    # message is emitted instead.

Notice the "Defaults to pinging for failure only." portion of that. That means that unless you add a list of states: to your configuration, borgmatic won't ever ping your Apprise services except in the case of borgmatic failure.

Here's an example configuration of what you could do to solve that:

apprise:
   ...
   states:
       - start
       - finish
       - fail
witten commented 5 months ago

I'm glad to hear that did it!

thyeestes commented 5 months ago

I have the same error, but I do have states in my config.yaml. This my output: echo Finished a backup. Finished a backup. /etc/borgmatic/config.yaml: No commands to run for post-actions hook /etc/borgmatic/config.yaml: Calling apprise hook function ping_monitor Unable to import Apprise in monitoring hook /etc/borgmatic/config.yaml: Calling apprise hook function ping_monitor Unable to import Apprise in monitoring hook /etc/borgmatic/config.yaml: Calling apprise hook function destroy_monitor /etc/borgmatic/config.yaml: No commands to run for post-everything hook

witten commented 5 months ago

The hint there is Unable to import Apprise in monitoring hook. If you're using this container, are you using a new enough version such that apprise module is included and importable? You can try exec-ing into your container and running python -c "import apprise" to check. Either that command exits silently if Apprise is present or it errors if not.

thyeestes commented 5 months ago

No error when I run python3 -c "import apprise"

witten commented 5 months ago

That's within the container? What about if you run: python3 -c "from apprise import NotifyFormat, NotifyType"

thyeestes commented 5 months ago

Apologies. I cam across this item because of the error. I am not running Borgmatic nor Borg in a container

witten commented 5 months ago

In that case, all you need to do is install Apprise such that borgmatic can find it! See https://torsion.org/borgmatic/docs/how-to/monitor-your-backups/#apprise-hook for more information.

witten commented 5 months ago

And if that doesn't fix it, please file a ticket here to discuss further: https://torsion.org/borgmatic/#support-and-contributing

thyeestes commented 5 months ago

Running this command fixed it pipx install --force borgmatic[Apprise]

Thanks. I overlooked it.

witten commented 5 months ago

Awesome, glad to hear it!