Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] generic:// notifications parameter does not work correctly (attempting to get Signal-CLI to work) #623

Open
ajkblue opened this issue Apr 4, 2024 · 5 comments
Labels
good first issue Good for newcomers help wanted Extra attention is needed

Comments

@ajkblue
Copy link

ajkblue commented Apr 4, 2024

Describe the bug
When trying to use the generic:// notification option from Shoutrrr, it fails to pass along JSON keys. I am trying to get the Signal CLI working as a means of receiving notifications. At first, it appeared to fail to due Shoutrrr not supporting arrays, but the signal-cli recently allowed for a single recipient parameter to be used, which should allow me to send a message. Running the below setup and testing the notifications with podman exec -it scrutiny-web curl -X POST http://localhost:8080/api/health/notify gives me this result from Webhook (which is incorrect, the number and recipient fields are not respected). This should work, as Shoutrrr supports custom data fields with the $key=value parameter as shown in the documentation:

{
  "message": "TEST NOTIFICATION:\nScrutiny SMART error notification for device: /dev/sda\nFailure Type: EmailTest\nDevice Name: /dev/sda\nDevice Serial: FAKEWDDJ324KSO\nDevice Type: ATA\n\nDate: 2024-04-04T23:16:53Z"
}

But, when running the shoutrrr container itself with the exact same parameters:
podman run --rm docker.io/containrrr/shoutrrr send -u 'generic://webhook.site/random-webhook-generated-id-here?template=json&disabletls=yes&$number=%2b12223334444&$recipient=%2b16667779999' --message "MESSAGE" it does work, and also works when swapping the URL for my local signal API instance as the correct JSON keys are preserved (number and recipient):

{
  "message": "MESSAGE",
  "number": "+12223334444",
  "recipient": "+16667779999"
}

Expected behavior
I expect to be able to send a proper notification to my locally running Signal CLI, testing with Webhook.site.

Config files
$HOME/config/scrutiny.yaml

...
notify:
  urls:
    - 'generic://webhook.site/random-webhook-generated-id-here?template=json&disabletls=yes&$number=%2b12223334444&$recipient=%2b16667779999'
...

I am running all of this in Podman with the hub-spoke method, the collector is running with sudo permissions while everything else (the influx database and the web interface) are running rootless. All of that works fine, SMART status, dashboard etc... it's only notifications I am struggling with:

podman run -d -p 8086:8086 \
  -v ~/scrutiny/influxdb2:/var/lib/influxdb2 \
  --name scrutiny-influxdb \
  docker.io/library/influxdb:2.2

podman run -d -p 8087:8080 \
  --label "io.containers.autoupdate=image" \
  -v ~/scrutiny-hub:/opt/scrutiny/config \
  --name scrutiny-web \
  -e SCRUTINY_WEB_INFLUXDB_HOST=IP-OF-INFLUX-DB \
  -e SCRUTINY_WEB_INFLUXDB_PORT=8086 \
  ghcr.io/analogj/scrutiny:master-web

sudo podman run -d \
  -v /run/udev:/run/udev:ro \
  --cap-add SYS_RAWIO \
  --cap-add SYS_ADMIN \
  --device=/dev/sda \
  --device=/dev/nvme0 \
  -e COLLECTOR_HOST_ID=Machine1 \
  -e COLLECTOR_API_ENDPOINT=http://IP-OF-SCRUTINTY-WEB:8087 \
  --name scrutiny-collector \
  ghcr.io/analogj/scrutiny:master-collector
@ajkblue ajkblue added the bug Something isn't working label Apr 4, 2024
@AnalogJ
Copy link
Owner

AnalogJ commented Apr 5, 2024

Can you confirm the version of shoutrrr you tested with? I'm guessing we're on an older version.

@AnalogJ AnalogJ added help wanted Extra attention is needed good first issue Good for newcomers and removed bug Something isn't working labels Apr 5, 2024
@ajkblue
Copy link
Author

ajkblue commented Apr 7, 2024

I pulled the latest tag from docker, so it appears to be v0.8.0

@GAS85
Copy link

GAS85 commented May 18, 2024

I did it simpler, add script to the yaml file:

notify:
  urls:
    - "script:///opt/scrutiny/bin/signal-notifications.sh"

Mount it in compose file

    volumes:
      - ${WORKINGDIR}/docker/scrutiny/signal-notifications.sh:/opt/scrutiny/bin/signal-notifications.sh
...

And create this script as signal-notifications.sh:

#!/bin/bash

# By Georgiy Sitnikov.
# https://github.com/GAS85
# AS-IS without any warranty

signalHost="signal-cli:8080"
signalRegisteredNubmer="+123456789"
signalRecipients="+987654321"

# Replace new lines with \n
signalMessage=$(echo "$SCRUTINY_MESSAGE" | sed ':a;N;$!ba;s/\n/\\n/g')

curl -fsS -m 10 --retry 2 -X POST -H "Content-Type: application/json" "http://$signalHost/v2/send" \
        -d "{\"message\": \"$signalMessage\", \"number\": \"$signalRegisteredNubmer\", \"recipients\": [ \"$signalRecipients\" ]}"  && exit 0 || exit 1

@smilence86
Copy link

smilence86 commented Jun 12, 2024

Thank you, I want to send msg to telegram, But I'm in china with poor network, I tested more than 10 times, all of them failed via Shoutrrr,

I checked network, domain, dns, port, It's all right. and waste much time, finnally find the reason until write my own script that copy from answer above. thanks for your idea.

Shoutrrr's timeout is about 10 seconds, maybe it's too short in some case. in my script, It's 40s worked finnally.

#!/bin/bash

# apt install curl -y

chat_id="your chat id"
telegramToken="your token"

# Replace new lines with \n
signalMessage=$(echo "$SCRUTINY_MESSAGE" | sed ':a;N;$!ba;s/\n/\\n/g')

notification_telegram="curl -X POST --retry 5 --header 'Content-Type: application/json' --data '{\"chat_id\":\"$chat_id\",\"text\":\"$signalMessage\"}' -m 40 https://api.telegram.org/bot$telegramToken/sendMessage"
# eval $notification_telegram

response=$(eval $notification_telegram 2>&1)
status=$?

if [ $status -ne 0 ]; then
  echo "telegram send failed curl: $response"
else
  echo "telegram send success: $response"
fi


BTW, the cli tool cloud not work

docker run --rm -it containrrr/shoutrrr generate telegram

Generating URL for telegram using telegram generator
To start we need your bot token. If you haven't created a bot yet, you can use this link:
  https://t.me/botfather?start

Enter your bot token: xxxxx:xxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Fetching bot info...
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x38 pc=0x720910]

goroutine 1 [running]:
github.com/containrrr/shoutrrr/pkg/services/telegram.(*Generator).Generate(0xc00016a1b0, {0xc000052030?, 0xc000155c38?}, 0xc000023f80, {0x3?, 0x0?, 0x4?})
	/home/runner/work/shoutrrr/shoutrrr/pkg/services/telegram/telegram_generator.go:55 +0x470
github.com/containrrr/shoutrrr/shoutrrr/cmd/generate.Run(0xc3eda0, {0xc00002a800?, 0x1?, 0x8b7ab2?})
	/home/runner/work/shoutrrr/shoutrrr/shoutrrr/cmd/generate/generate.go:119 +0x872
github.com/spf13/cobra.(*Command).execute(0xc3eda0, {0xc00002a7d0, 0x1, 0x1})
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:944 +0x863
github.com/spf13/cobra.(*Command).ExecuteC(0xc3e7e0)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:1068 +0x3a5
github.com/spf13/cobra.(*Command).Execute(...)
	/home/runner/go/pkg/mod/github.com/spf13/[email protected]/command.go:992
main.main()
	/home/runner/work/shoutrrr/shoutrrr/shoutrrr/main.go:31 +0x1a

@GAS85
Copy link

GAS85 commented Sep 2, 2024

@smilence86 did you check documentation? Telegram should be supported out of the box.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants