[Feature Request] User Scripts as Notification Entities


Recommended Posts

There are notification agents that aren't included in unRAID, ntfy.sh for example. It would be great if one of the notification agents could just be a user script, or multiple. This way you could write your own notification command and not have to wait for your preferred agent to be added officially.

Then you user script could be something along the lines of (for ntfy.sh):

curl \
  -H "Title: $UNRAID_NOTIF_SUBJECT" \
  -H "Priority: default" \
  -H "Tags: unRAID" \
  -d "$UNRAID_NOTIF_DESC" \
  ntfy.sh/unraid_notifs

where there are a defined list of environment variables passed to it such as:

  • UNRAID_NOTIF_SUBJECT
  • UNRAID_NOTIF_EVENT
  • UNRAID_NOTIF_TIMESTAMP
  • UNRAID_NOTIF_DESC
  • UNRAID_NOTIF_IMPORTANCE
  • UNRAID_NOTIF_CONTENT
  • UNRAID_NOTIF_LINK
  • ...
Edited by jlaning
  • Upvote 2
Link to comment
  • jlaning changed the title to [Feature Request] User Scripts as Notification Entities

After some initial investigation, it seems that at least maybe dropping a custom script into the directory

/boot/config/plugins/dynamix/notifications/agents/

would work based on the code in

/usr/local/emhttp/plugins/dynamix/scripts/notify

 

but I haven't tested this. However, a UI way of doing this would be preferred.

 

EDIT:

 

Creating a script

/boot/config/plugins/dynamix/notifications/agents/ntfy

 

worked (as a temp solution). Here's my example for ntfy.sh

 

#!/bin/bash
curl -u "user:pass" \
  -H "Title: ${SUBJECT}" \
  -H "Tags: unRAID" \
  -d "Event: ${EVENT}
Subject: ${SUBJECT}
Description: ${DESCRIPTION}
Importance: ${IMPORTANCE}
Time: $(date '+%Y-%m-%d %H:%M:%S')

${CONTENT}" \
  https://ntfy.domain.tld/unRAID

 

Edited by jlaning
added temporary solution
  • Like 2
  • Upvote 3
Link to comment
  • 2 weeks later...
  • 3 months later...
On 10/4/2022 at 4:09 PM, jlaning said:

After some initial investigation, it seems that at least maybe dropping a custom script into the directory

/boot/config/plugins/dynamix/notifications/agents/

would work based on the code in

/usr/local/emhttp/plugins/dynamix/scripts/notify

 

but I haven't tested this. However, a UI way of doing this would be preferred.

 

EDIT:

 

Creating a script

/boot/config/plugins/dynamix/notifications/agents/ntfy

 

worked (as a temp solution). Here's my example for ntfy.sh

 

#!/bin/bash
curl -u "user:pass" \
  -H "Title: ${SUBJECT}" \
  -H "Tags: unRAID" \
  -d "Event: ${EVENT}
Subject: ${SUBJECT}
Description: ${DESCRIPTION}
Importance: ${IMPORTANCE}
Time: $(date '+%Y-%m-%d %H:%M:%S')

${CONTENT}" \
  https://ntfy.domain.tld/unRAID

 

Are you saying that you got it working with that script?

Link to comment
  • 2 weeks later...

So upon further review this totally works, if the folder does not exist just create it, you can also name the .sh file pretty much anything you want.  I also updated it a bit for nicer looking notifications

 

#!/bin/bash

ntfy_url="https://ntfy.sh/topic"
# Use ntfy_username and ntfy_password OR ntfy_token
ntfy_username=""
ntfy_password=""
ntfy_token=""
# Leave empty if you do not want an icon.
ntfy_icon="https://raw.githubusercontent.com/walkxcode/dashboard-icons/main/png/unraid.png"

if [[ -n $ntfy_password && -n $ntfy_token ]]; then
  echo "Use ntfy_username and ntfy_password OR ntfy_token"
  exit 1
elif [ -n "$ntfy_password" ]; then
  ntfy_base64=$( echo -n "$ntfy_username:$ntfy_password" | base64 )
  ntfy_auth="Authorization: Basic $ntfy_base64"
elif [ -n "$ntfy_token" ]; then
  ntfy_auth="Authorization: Bearer $ntfy_token"
else
  ntfy_auth=""
fi

ntfy_title="Unraid: ${SUBJECT}"
ntfy_message="${DESCRIPTION}"

if [ "${IMPORTANCE}" == "alert" ]; then
  ntfy_tag=rotating_light
  ntfy_priority="urgent"
  ntfy_xpriority=5
elif [ "${IMPORTANCE}" == "warning" ]; then
  ntfy_tag=warning
  ntfy_priority="high"
  ntfy_xpriority=4
else
  ntfy_tag=information_source
  ntfy_priority="default"
  ntfy_xpriority=3
fi

curl $ntfy_url \
-H "$ntfy_auth" \
-H "tags:"$ntfy_tag \
-H "X-Title: $ntfy_title" \
-H "X-Icon: $ntfy_icon" \
-H "Priority: $ntfy_priority" \
-H "X-Priority: $ntfy_xpriority" \
-d "$ntfy_message" \

 

Edited by semaj4712
  • Like 3
Link to comment
  • 4 months later...
  • 2 months later...
  • 2 months later...

I just want to add a note that may help keep anyone else from going down the Rabbit-hole that caught me.

 

The file path to install the NTFY agent that is on this page is correct. But the one in the built-in help of the Notifications settings page is incorrect (as of 2023-1221 v 6.12.6) 

 

This page has - /boot/config/plugins/dynamix/notifications/agents/

 

Help on notifications page has - /boot/config/plugins/dynamix/notification/agents/

 

The only difference is that the correct value is plural while the Help doc has singular "notifications" vs "notification"

 

That one little letter drove me crazy for a while.   :-) 

Link to comment
22 minutes ago, macronin said:

The file path to install the NTFY agent that is on this page is correct. But the one in the built-in help of the Notifications settings page is incorrect (as of 2023-1221 v 6.12.6) 

NTFY should be an agent by default and you don't have to do anything as the post above yours imply.

Link to comment
8 minutes ago, ich777 said:

NTFY should be an agent by default and you don't have to do anything as the post above yours imply.

The post above mine talks about a submitted update that has not gone live yet (as far as I can tell).

 

I had checked all the options on myidentifier.myunraid.net/Settings/Notifications page and NTFY is not listed as of yet. It might be in the nightly version (for future public release) but I am running Stable 6.12.6 which is the latest general usage version.

 

Umm, just realized tat you are the author of the post above me. :-)  Is this maybe in a diff location that I may haver missed?

Link to comment
20 minutes ago, macronin said:

Umm, just realized tat you are the author of the post above me. 🙂 Is this maybe in a diff location that I may haver missed?

10 minutes ago, nlz said:

I haven't seen it natively in the options yet either.

Oh sorry, I've pushed that against master that should be 6.13.0 and not 6.12.x

Link to comment
  • 1 month later...
On 10/17/2023 at 4:26 AM, ich777 said:

I hope this is what you where after:
grafik.thumb.png.ca0aebd207f67fb6442ac13c034fb280.png

 

grafik.png.3818459e6fe80dc4508b015251b6dadb.png

 

Already created a PR and will be hopefully included in one of the next releases. ;)

I can't seem to get this to appear.  I followed all the steps.  Is a reboot required to read the script from: /boot/config/plugins/dynamix/notifications/agents

 

EDIT: just noticed the version is 6.13 and i'm on 6.12.6  

Edited by MP715
Link to comment

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.