Http notifications and ntfy.sh

Hello guys,
could I please get some help with http-notifications text format?
I would like Duplicate to send notifications to ntfy.sh. Settings are
send-http-result-output-format=Duplicati

Unfortunately, the form url encoded body of the message is displayed by ntfy.sh like this:

(How) do I change this? Ive read the docs, but there doesn’t seem to be an easy answer. Just changing the above output format to json doesn’t work, Im getting back an error from ntfy.sh then.
Has anyone solved this before?
Thanks , JAN

Yes, that is the standard format, but it looks like ntfy.sh does not support that.

The only two options are form-encoded and JSON encoded, and it looks like neither works well here.

Not sure, but based on the docs, you can perhaps instead have a --run-script-after with content like:

if [ "$EVENTNAME" == "AFTER" ]; then
  if [ "$OPERATIONNAME" == "Backup" ]; then
    if ["$DUPLICATI__PARSED_RESULT" == "Success"]; then
      # Notify success
      curl -H tags:success -H prio:low -d "Backup '$DUPLICATI__backup_name' completed successfully" ntfy.sh/backups
    elif [ "$DUPLICATI__PARSED_RESULT" == "Warning" ]; then
      # Notify warning
      curl -H tags:warning -H prio:medium -d "Backup '$DUPLICATI__backup_name' completed with warnings" ntfy.sh/backups
    else
      # Notify failure
      curl -H tags:error -H prio:high -d "Backup '$DUPLICATI__backup_name' failed with status: $DUPLICATI__PARSED_RESULT" ntfy.sh/backups
    fi
  fi
fi

Thank you very much :star_struck: I feel like Im almost there:
I am running Duplicati from a Docker container which has no curl installed. So I installed it inside that container and I can now send curl messages to ntfy.sh BUT the script is not outputting anything from the if/then/elif/else statements?

#! /bin/bash
curl -d "Test!" ntfy.sh/raspi5

if [ "$EVENTNAME" == "AFTER" ]; then
  if [ "$OPERATIONNAME" == "Backup" ]; then
    if ["$DUPLICATI__PARSED_RESULT" == "Success"]; then
      # Notify success
      curl -H tags:success -H prio:low -d "Backup '$DUPLICATI__backup_name' completed successfully" ntfy.sh/raspi5
    elif [ "$DUPLICATI__PARSED_RESULT" == "Warning" ]; then
      # Notify warning
      curl -H tags:warning -H prio:medium -d "Backup '$DUPLICATI__backup_name' completed with warnings" ntfy.sh/raspi5
    else
      # Notify failure
      curl -H tags:error -H prio:high -d "Backup '$DUPLICATI__backup_name' failed with status: $DUPLICATI__PARSED_RESULT" ntfy.sh/raspi5
    fi
  fi
fi

leads to this error message:

and to this notification on ntfy.sh:

Could you please help some more?

Try putting -s after curl

curl -s -H tags:success -H prio:low -d “Backup ‘$DUPLICATI__backup_name’ completed successfully” ntfy.sh/raspi5

Sadly this doesnt work. Duplicati is still showing that error message. And the script is still not outputting anything to ntfy.sh :face_with_diagonal_mouth:

To try to explain some of this (unfortunately not yet all), Duplicati assumes that output on stderr is something like a warning or error from whatever you ran, so passes it on to you.

Unfortunately curl puts its progress message on stderr, so that’s why you get the warning.

curl is maybe the man page for your OS (if you know otherwise, see your own man page).

-s, --silent
    Silent or quiet mode. Do not show progress meter or error messages. Makes Curl mute. It will still output the data you ask for, potentially even to the terminal/stdout unless you redirect it.

    Use -S, --show-error in addition to this option to disable progress meter but still show error messages.

is a combination that might work to suppress unwanted info while allowing errors through.

--no-progress-meter
    Option to switch off the progress meter output without muting or otherwise affecting warning and informational messages like -s, --silent does. 

might also work, and might let warnings (not just errors) come through to you using stderr.

You need to use something like this on each curl use. Result says maybe you didn’t do so.

["$DUPLICATI__PARSED_RESULT" == "Success"] is apparently invalid syntax, as a space needs to go after the [ and another before the ]. Bash is picky. Other lines have spaces.

If you like, you can debug this at shell prompt by setting up the environment variables, e.g.

export EVENTNAME=AFTER and so on. You can even bash -x <script> to see execution.

Sadly, things are not working out for me. I have tried all curl options -s -S --no-progress-meter in various settings and I still can’t get rid of Duplicati reporting some curl status output as an error.
And I have fixed the script error, but still its not working and not outputting any backup result.

So Im giving up on this. Too much hassle for a backup notification. :face_with_bags_under_eyes:
It would be nice though if future versions of Duplicati would support ntfy.sh as a notification service for its send-http-url option.

You can just redirect everything to /dev/null, something like:

#!/bin/bash

# Defaults
LOG_FILE=${NTFY_LOG_FILE:-/dev/null}
NTFY_SERVER=${NTFY_SERVER:-ntfy.sh/raspi5}

# Uncomment to test if you see a message being sent
# curl -s -d "Test!" "$NTFY_SERVER" >>"$LOG_FILE" 2>&1

if [ "$EVENTNAME" == "AFTER" ]; then
  if [ "$OPERATIONNAME" == "Backup" ]; then
    if [ "$DUPLICATI__PARSED_RESULT" == "Success" ]; then
      # Notify success
      curl -s -H tags:success -H prio:low \
        -d "Backup '$DUPLICATI__backup_name' completed successfully" \
        "$NTFY_SERVER" >>"$LOG_FILE" 2>&1
    elif [ "$DUPLICATI__PARSED_RESULT" == "Warning" ]; then
      # Notify warning
      curl -s -H tags:warning -H prio:medium \
        -d "Backup '$DUPLICATI__backup_name' completed with warnings" \
        "$NTFY_SERVER" >>"$LOG_FILE" 2>&1
    else
      # Notify failure
      curl -s -H tags:error -H prio:high \
        -d "Backup '$DUPLICATI__backup_name' failed with status: $DUPLICATI__PARSED_RESULT" \
        "$NTFY_SERVER" >>"$LOG_FILE" 2>&1
    fi
  fi
fi

If it fails for some reason, you can set the LOG_FILE env var, or just edit the script to log somewhere.

My plan is to support templates, so it would be simple to format the message to fit whatever destination.