Jump to content

[HOWTO] Use unRAID's notification system inside containers

Featured Replies

Posted

Hi guys,

 

This is just a script I wrote to help the usage of unRAID notifications from inside a docker container (Transmission, in this example):

 

#!/bin/bash

UNRAID_ADDR="172.17.42.1"
UNRAID_PASS="pass"

#  Available Channels
#
#  1 = notify using browser-popups only;
#  2 = notify using e-mail only;
#  3 = notify using browser-popups and e-mail;
#  4 = notify using agents only;
#  5 = notify using browser-popups and agents;
#  6 = notify using e-mail and agents;
#  7 = notify using browser popups, e-mail and agents;

CHANNEL="2"

curl -d "cmd=add" \
     -d "e=Transmission: Torrent Done" \
     -d "s=Download of Torrent ${TR_TORRENT_NAME} finished on $TR_TIME_LOCALTIME" \
     -d "i=normal ${CHANNEL}" \
     -u "root:${UNRAID_PASS}" "http://${UNRAID_ADDR}/webGui/include/Notify.php"

 

Hope you enjoy it.

Hi guys,

 

This is just a script I wrote to help the usage of unRAID notifications from inside a docker container (Transmission, in this example):

 

#!/bin/bash

UNRAID_ADDR="172.17.42.1"
UNRAID_PASS="pass"

#  Available Channels
#
#  1 = notify using browser-popups only;
#  2 = notify using e-mail only;
#  3 = notify using browser-popups and e-mail;
#  4 = notify using agents only;
#  5 = notify using browser-popups and agents;
#  6 = notify using e-mail and agents;
#  7 = notify using browser popups, e-mail and agents;

CHANNEL="2"

curl -d "cmd=add" \
     -d "e=Transmission: Torrent Done" \
     -d "s=Download of Torrent ${TR_TORRENT_NAME} finished on $TR_TIME_LOCALTIME" \
     -d "i=mormal ${CHANNEL}" \
     -u "root:${UNRAID_PASS}" "http://${UNRAID_ADDR}/webGui/include/Notify.php"

 

Hope you enjoy it.

 

is this to go inside of a container ?

  • Author

 

is this to go inside of a container ?

 

Yes, inside /config folder, for example. A user asked me why his ssmtp script was failing, and I wrote this for him.

 

is this to go inside of a container ?

 

Yes, inside /config folder, for example. A user asked me why his ssmtp script was failing, and I wrote this for him.

 

got it, so for transmission, you'd call this say torrent-done.sh , make it executable and then in the transmission webui call it as an action when torrent is completed.

  • Author

 

is this to go inside of a container ?

 

Yes, inside /config folder, for example. A user asked me why his ssmtp script was failing, and I wrote this for him.

 

got it, so for transmission, you'd call this say torrent-done.sh , make it executable and then in the transmission webui call it as an action when torrent is completed.

 

Exactly that. Obviously, you can adapt it to Deluge, NZBGet etc...

 

is this to go inside of a container ?

 

Yes, inside /config folder, for example. A user asked me why his ssmtp script was failing, and I wrote this for him.

 

got it, so for transmission, you'd call this say torrent-done.sh , make it executable and then in the transmission webui call it as an action when torrent is completed.

 

Exactly that. Obviously, you can adapt it to Deluge, NZBGet etc...

 

cool, now to think of ways of using it in containers on the drawing board.

 

 

would be handy if UNRAID_ADDR was an environment variable could pass directly to container bit like time info.

  • Author

 

cool, now to think of ways of using it in containers on the drawing board.

 

would be handy if UNRAID_ADDR was an environment variable could pass directly to container bit like time info.

 

The problem always was those who doesn't use fixed IP address, relying only in the NETBIOS name.  If the IP changes, you have to recreate all containers...

  • Author

lol, just tried it from command line of a VM.

 

-d "i=mormal ${CHANNEL}" \

 

 

everything mormal here.

 

;D ;D ;D

 

Fixed

 

is this to go inside of a container ?

 

Yes, inside /config folder, for example. A user asked me why his ssmtp script was failing, and I wrote this for him.

 

got it, so for transmission, you'd call this say torrent-done.sh , make it executable and then in the transmission webui call it as an action when torrent is completed.

 

Exactly that. Obviously, you can adapt it to Deluge, NZBGet etc...

 

cool, now to think of ways of using it in containers on the drawing board.

 

 

would be handy if UNRAID_ADDR was an environment variable could pass directly to container bit like time info.

We figured that out before...  Map /usr/local/emhttp/state through to the container and you can scrap var.ini for the IP address

 

is this to go inside of a container ?

 

Yes, inside /config folder, for example. A user asked me why his ssmtp script was failing, and I wrote this for him.

 

got it, so for transmission, you'd call this say torrent-done.sh , make it executable and then in the transmission webui call it as an action when torrent is completed.

 

Exactly that. Obviously, you can adapt it to Deluge, NZBGet etc...

 

cool, now to think of ways of using it in containers on the drawing board.

 

 

would be handy if UNRAID_ADDR was an environment variable could pass directly to container bit like time info.

We figured that out before...  Map /usr/local/emhttp/state through to the container and you can scrap var.ini for the IP address

 

blah blah blah, i can't be expected to remember stuff, i'm old.

 

is this to go inside of a container ?

 

Yes, inside /config folder, for example. A user asked me why his ssmtp script was failing, and I wrote this for him.

 

got it, so for transmission, you'd call this say torrent-done.sh , make it executable and then in the transmission webui call it as an action when torrent is completed.

 

Exactly that. Obviously, you can adapt it to Deluge, NZBGet etc...

 

cool, now to think of ways of using it in containers on the drawing board.

 

 

would be handy if UNRAID_ADDR was an environment variable could pass directly to container bit like time info.

We figured that out before...  Map /usr/local/emhttp/state through to the container and you can scrap var.ini for the IP address

 

blah blah blah, i can't be expected to remember stuff, i'm old.

You're like 2 minutes older than I am dude....  ;)

Add:

 

-d "d=Description of event" \

 

to give the notification a description of the event.

thanks very much for your response  :)

am i missing something, i cant get notified :)

i replace my .sh script with the one you wrote above, write my UNRAID_ADDR and UNRAID_PASS.

 

lines in syslog:

Jun 18 15:27:14 Tower emhttp: /usr/bin/docker logs --tail=350 -f Transmission 2>&1
Jun 18 15:28:01 Tower emhttp: /usr/bin/tail -n 42 -f /var/log/syslog 2>&1
Jun 18 15:33:50 Tower emhttp: /usr/bin/tail -n 42 -f /var/log/syslog 2>&1
Jun 18 15:57:25 Tower emhttp: /usr/bin/tail -n 42 -f /var/log/syslog 2>&1

  • Author

thanks very much for your response  :)

am i missing something, i cant get notified :)

i replace my .sh script with the one you wrote above, write my UNRAID_ADDR and UNRAID_PASS.

 

lines in syslog:

Jun 18 15:27:14 Tower emhttp: /usr/bin/docker logs --tail=350 -f Transmission 2>&1
Jun 18 15:28:01 Tower emhttp: /usr/bin/tail -n 42 -f /var/log/syslog 2>&1
Jun 18 15:33:50 Tower emhttp: /usr/bin/tail -n 42 -f /var/log/syslog 2>&1
Jun 18 15:57:25 Tower emhttp: /usr/bin/tail -n 42 -f /var/log/syslog 2>&1

 

First thing to verify is if your script is executable. Then, verify if your Notification system is operational.

 

Please see if this helps debugging:

 

docker exec -ti Transmission /config/<your_script>.sh

 

First thing to verify is if your script is executable. Then, verify if your Notification system is operational.

 

Please see if this helps debugging:

 

docker exec -ti Transmission /config/<your_script>.sh

 

Yeap, thats helps me to solve, file permissions was wrong. Thanks agaion, Thumbs up! :)

 

By the way this is my way, tidier i think:

CHANNEL="3"

curl -d "cmd=add" \
     -d "e=Transmission: Torrent Done" \
     -d "s=Download finished" \
     -d "d=Download of Torrent ${TR_TORRENT_NAME} finished on $TR_TIME_LOCALTIME" \
     -d "i=normal ${CHANNEL}" \
     -u "root:${UNRAID_PASS}" "http://${UNRAID_ADDR}/webGui/include/Notify.php"

  • Author

Yeap, thats helps me to solve, file permissions was wrong. Thanks agaion, Thumbs up! :)

 

 

You're welcome. Glad it worked for you!

  • 3 years later...

I've got the following error after using the script and NO notification:

Quote

Nov 7 18:38:01 unraidserver root: error: /webGui/include/Notify.php: missing csrf_token

Any ideas how to fix?

You would have to also scrape var.ini to get the current csrf token and then append it to the url.

 

Would probably ultimately be easier to instead add a path mapping to /usr/local/emhttp/plugins/dynamix/scripts and then execute notify.php directly as a script.

20 hours ago, Squid said:

You would have to also scrape var.ini to get the current csrf token and then append it to the url.

Since I am not a programmer, I would be grateful if someone could adapt the original script accordingly.

20 hours ago, Squid said:

Would probably ultimately be easier to instead add a path mapping to /usr/local/emhttp/plugins/dynamix/scripts and then execute notify.php directly as a script.

Unfortunately this doesn't work because PHP doesn't exist in the docker container I use and I don't want to install it.

Something like this.

csrf=$(cat /var/local/emhttp/var.ini | grep csrf | sed 's/.*="\(.*\)"/\1/')
curl -d "csrf_token=${csrf}" -d "cmd=add" -d "e=Transmission: Torrent Done" -d "s=Download finished" -d "d=Download of Torrent" -d "i=normal" -u "root:THEROOTPASSWORD" "http://192.168.1.61/webGui/include/Notify.php"

You would need to map "/" to "/" on the container

17 hours ago, Squid said:

Something like this.


csrf=$(cat /var/local/emhttp/var.ini | grep csrf | sed 's/.*="\(.*\)"/\1/')
curl -d "csrf_token=${csrf}" -d "cmd=add" -d "e=Transmission: Torrent Done" -d "s=Download finished" -d "d=Download of Torrent" -d "i=normal" -u "root:THEROOTPASSWORD" "http://192.168.1.61/webGui/include/Notify.php"

You would need to map "/" to "/" on the container

Works! Thanks a lot! 👍

 

BTW: It is completely sufficient to link the host path /var/local/emhttp e.g. to the container path /var.

48 minutes ago, JoergHH said:

It is completely sufficient to link the host path /var/local/emhttp e.g. to the container path /var.

You might want to make that mapping RO to prevent the container from possibly overwriting something in the HOST OS. Also, maybe use a subfolder of /var on the container side to prevent HOST from overwriting something in the container OS.

  • 1 year later...

I would like to use this script with binhex-delugevpn.

 

I assume I primarily need to modify the two variables ${TR_TORRENT_NAME} and ${TR_TIME_LOCALTIME}. Does anyone know what they are for binhex-delugevpn?

 

Best,

Peter

  • 3 months later...

Also interested if this still works in 2020? Tried curling different endpoints, but either receive stock nginx page, or 'file not found.

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...