From 0b52dd50b64a41f5fad10e6a9bd2cd652619939d Mon Sep 17 00:00:00 2001 From: Alireza <5110480+silverbios@users.noreply.github.com> Date: Sat, 10 Feb 2024 03:03:07 +0330 Subject: [PATCH 1/4] Create notify_matrix.sh add notification template for matrix-synapse --- notify_matrix.sh | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 notify_matrix.sh diff --git a/notify_matrix.sh b/notify_matrix.sh new file mode 100644 index 0000000..5f76a32 --- /dev/null +++ b/notify_matrix.sh @@ -0,0 +1,28 @@ +### DISCLAIMER: This is a third party addition to dockcheck - best effort testing. +# +# Copy/rename this file to notify.sh to enable the notification snippet. +# Required receiving services must already be set up. +# Modify to fit your setup - set MatrixServer, Room_id and AccessToken and . + +send_notification() { + Updates=("$@") + UpdToString=$( printf "%s\n" "${Updates[@]}" ) + FromHost=$(hostname) + + # platform specific notification code would go here + printf "\nSending Matrix notification\n" + + # Setting the MessageBody variable here. + MessageBody="🐋 Containers on $FromHost with updates available: \n$UpdToString" + + # Modify to fit your setup: + AccessToken="Your Matrix token here" + Room_id="Enter Room_id here" + MatrixServer="Enter Your HomeServer URL" + MsgBody="{msgtype":"m.text","body":"$MessageBody"}" + + # URL Example: https://matrix.org/_matrix/client/r0/rooms/!xxxxxx:example.com/send/m.room.message/?access_token=xxxxxxxx + + curl -sS -o /dev/null --fail -X PUT "$MatrixServer/_matrix/client/r0/rooms/$Room_id/send/m.room.message/?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody" + +} From c09e813aad09512a7b0a4abd99f172940c0fadad Mon Sep 17 00:00:00 2001 From: Alireza <5110480+silverbios@users.noreply.github.com> Date: Sat, 10 Feb 2024 20:47:36 +0330 Subject: [PATCH 2/4] Update notify_matrix.sh Fix Msgbody variable syntax --- notify_matrix.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/notify_matrix.sh b/notify_matrix.sh index 5f76a32..b69320a 100644 --- a/notify_matrix.sh +++ b/notify_matrix.sh @@ -19,10 +19,10 @@ send_notification() { AccessToken="Your Matrix token here" Room_id="Enter Room_id here" MatrixServer="Enter Your HomeServer URL" - MsgBody="{msgtype":"m.text","body":"$MessageBody"}" + MsgBody="{\"msgtype\":\"m.text\",\"body\":\"$MessageBody\"}" # URL Example: https://matrix.org/_matrix/client/r0/rooms/!xxxxxx:example.com/send/m.room.message/?access_token=xxxxxxxx - curl -sS -o /dev/null --fail -X PUT "$MatrixServer/_matrix/client/r0/rooms/$Room_id/send/m.room.message/?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody" + curl -sS -o /dev/null --fail -X PUT "$MatrixServer/_matrix/client/r0/rooms/$Room_id/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody" } From b2767864ab62e5972143236205b6587c9388bb17 Mon Sep 17 00:00:00 2001 From: Alireza <5110480+silverbios@users.noreply.github.com> Date: Sat, 10 Feb 2024 20:55:32 +0330 Subject: [PATCH 3/4] update comments --- notify_matrix.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notify_matrix.sh b/notify_matrix.sh index b69320a..0dfd38e 100644 --- a/notify_matrix.sh +++ b/notify_matrix.sh @@ -2,7 +2,7 @@ # # Copy/rename this file to notify.sh to enable the notification snippet. # Required receiving services must already be set up. -# Modify to fit your setup - set MatrixServer, Room_id and AccessToken and . +# Modify to fit your setup - set MatrixServer, Room_id and AccessToken send_notification() { Updates=("$@") From c63643dde8f2b60ac0f7b07c29810e1028e2d245 Mon Sep 17 00:00:00 2001 From: Alireza <5110480+silverbios@users.noreply.github.com> Date: Sat, 10 Feb 2024 21:01:42 +0330 Subject: [PATCH 4/4] Update Example URL --- notify_matrix.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/notify_matrix.sh b/notify_matrix.sh index 0dfd38e..b000db8 100644 --- a/notify_matrix.sh +++ b/notify_matrix.sh @@ -21,7 +21,7 @@ send_notification() { MatrixServer="Enter Your HomeServer URL" MsgBody="{\"msgtype\":\"m.text\",\"body\":\"$MessageBody\"}" - # URL Example: https://matrix.org/_matrix/client/r0/rooms/!xxxxxx:example.com/send/m.room.message/?access_token=xxxxxxxx + # URL Example: https://matrix.org/_matrix/client/r0/rooms/!xxxxxx:example.com/send/m.room.message?access_token=xxxxxxxx curl -sS -o /dev/null --fail -X PUT "$MatrixServer/_matrix/client/r0/rooms/$Room_id/send/m.room.message?access_token=$AccessToken" -H 'Content-Type: application/json' -d "$MsgBody"