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] first path segment in URL cannot contain colon with discord notifier #745

Open
remi-espie opened this issue Jan 29, 2025 · 2 comments
Labels
bug Something isn't working

Comments

@remi-espie
Copy link

remi-espie commented Jan 29, 2025

Describe the bug
I use scrutiny:master-omnibus with Docker Compose.
I set the environment variable SCRUTINY_NOTIFY_URLS to "discord://<token>@<webhookid>".
When I run curl -X POST http://localhost:8080/api/health/notify, I have the following error:

{"errors":["error initializing router services: parse \"\\\"discord://<token>@<webhookid>\\\"\": first path segment in URL cannot contain colon"],"success":false}

Expected behavior
For scrutiny to send a test notification to Discord.

docker-compose.yml

version: '3.5'

services:
  scrutiny:
    container_name: scrutiny
    image: ghcr.io/analogj/scrutiny:master-omnibus
    cap_add:
      - SYS_RAWIO
    ports:
      - "8080:8080" # webapp
    volumes:
      - /run/udev:/run/udev:ro
      - ./config:/opt/scrutiny/config
      - ./influxdb:/opt/scrutiny/influxdb
    environment:
      - SCRUTINY_NOTIFY_URLS="discord://<token>@<webhookid>"
    devices:
      - "/dev/sda"
      - "/dev/sdb"
    restart: unless-stopped

Log Files

scrutiny  | Start the scrutiny server
scrutiny  | 2025/01/29 13:59:12 No configuration file found at /opt/scrutiny/config/scrutiny.yaml. Using Defaults.
scrutiny  | time="2025-01-29T13:59:12Z" level=info msg="Trying to connect to scrutiny sqlite db: /opt/scrutiny/config/scrutiny.db\n" type=web
scrutiny  | time="2025-01-29T13:59:12Z" level=info msg="Successfully connected to scrutiny sqlite db: /opt/scrutiny/config/scrutiny.db\n" type=web
scrutiny  | time="2025-01-29T13:59:12Z" level=info msg="InfluxDB certificate verification: true\n" type=web
scrutiny  | time="2025-01-29T13:59:12Z" level=info msg="Database migration starting. Please wait, this process may take a long time...." type=web
scrutiny  | time="2025-01-29T13:59:12Z" level=info msg="Database migration completed successfully" type=web
scrutiny  | time="2025-01-29T13:59:12Z" level=info msg="SQLite global configuration migrations starting. Please wait...." type=web
scrutiny  | time="2025-01-29T13:59:12Z" level=info msg="SQLite global configuration migrations completed successfully" type=web
scrutiny  | time="2025-01-29T13:59:43Z" level=info msg="Sending notifications to \"discord://<token>@<webhookid>\"" type=web
scrutiny  | time="2025-01-29T13:59:43Z" level=error msg="An error occurred while sending notifications \"discord://<token>@<webhookid>\": error initializing router services: parse \"\\\"discord://<token>@<webhookid>\\\"\": first path segment in URL cannot contain colon" type=web
scrutiny  | time="2025-01-29T13:59:43Z" level=error msg="One or more notifications failed to send successfully. See logs for more information." type=web
scrutiny  | time="2025-01-29T13:59:43Z" level=error msg="An error occurred while sending test notification error initializing router services: parse \"\\\"discord://<token>@<webhookid>\\\"\": first path segment in URL cannot contain colon" type=web
scrutiny  | time="2025-01-29T13:59:43Z" level=error msg="192.168.16.1 - 4891be7098ef [29/Jan/2025:13:59:43 +0000] \"POST /api/health/notify\" 500 231 \"\" \"curl/7.88.1\" (1ms)" clientIP=192.168.16.1 hostname=4891be7098ef latency=1 method=POST path=/api/health/notify referer= respLength=231 statusCode=500 type=web userAgent=curl/7.88.1
docker info Client: Docker Engine - Community Version: 27.5.1 Context: default Debug Mode: false Plugins: buildx: Docker Buildx (Docker Inc.) Version: v0.20.0 Path: /usr/libexec/docker/cli-plugins/docker-buildx compose: Docker Compose (Docker Inc.) Version: v2.32.4 Path: /usr/libexec/docker/cli-plugins/docker-compose

Server:
Containers: 22
Running: 22
Paused: 0
Stopped: 0
Images: 49
Server Version: 27.5.1
Storage Driver: overlay2
Backing Filesystem: extfs
Supports d_type: true
Using metacopy: false
Native Overlay Diff: true
userxattr: false
Logging Driver: json-file
Cgroup Driver: systemd
Cgroup Version: 2
Plugins:
Volume: local
Network: bridge host ipvlan macvlan null overlay
Log: awslogs fluentd gcplogs gelf journald json-file local splunk syslog
Swarm: inactive
Runtimes: runc io.containerd.runc.v2
Default Runtime: runc
Init Binary: docker-init
containerd version: bcc810d6b9066471b0b6fa75f557a15a1cbf31bb
runc version: v1.2.4-0-g6c52b3f
init version: de40ad0
Security Options:
apparmor
seccomp
Profile: builtin
cgroupns
Kernel Version: 6.1.0-30-amd64
Operating System: Debian GNU/Linux 12 (bookworm)
OSType: linux
Architecture: x86_64
CPUs: 12
Total Memory: 31.12GiB
Name: nas
ID: f2d7c9c9-6a5b-42a5-a420-3069aee47d76
Docker Root Dir: /var/lib/docker
Debug Mode: false
Experimental: false
Insecure Registries:
127.0.0.0/8
Live Restore Enabled: false

@remi-espie remi-espie added the bug Something isn't working label Jan 29, 2025
@remi-espie
Copy link
Author

After experimenting, I discovered that the following docker-compose.yml works:

version: '3.5'

services:
  scrutiny:
    container_name: scrutiny
    image: ghcr.io/analogj/scrutiny:master-omnibus
    cap_add:
      - SYS_RAWIO
    ports:
      - "8080:8080" # webapp
    volumes:
      - /run/udev:/run/udev:ro
      - ./config:/opt/scrutiny/config
      - ./influxdb:/opt/scrutiny/influxdb
    environment:
+      - SCRUTINY_NOTIFY_URLS=discord://<token>@<webhookid>
-      - SCRUTINY_NOTIFY_URLS="discord://<token>@<webhookid>"
    devices:
      - "/dev/sda"
      - "/dev/sdb"
    restart: unless-stopped

The difference is only the quote around the url.

I then looked at the code, and a "patch" could be easily made by adding the following line in the notify.go file

url = strings.Trim(url, "\"")

Or to add it "earlier" in the config.go, maybe by modifying

-	c.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_"))
+	c.SetEnvKeyReplacer(strings.NewReplacer("-", "_", ".", "_", "\"", ""))

Let me know what you think, I may make a PR !

@remi-espie
Copy link
Author

Hello again, I investigated this issue more, and I have new ideas.

I tracked the issue back to the notify.go file.

So, turns out when using environment variable, n.Config.GetStringSlice("notify.urls") slice the variable on spaces. As of right now, If you wanted mutiple notify urls using env var, you should do:

SCRUTINY_NOTIFY_URLS=discord://token@webhookid slack://token:token@channel/ ...

The documentation is not very clear, but in docs/INSTALL_HUBS_SPOKE.md, the example state that you can use array of string for SCRUTINY_NOTIFY_URLS. So my example from before should be:

SCRUTINY_NOTIFY_URLS=["discord://token@webhookid", "slack://token:token@channel/", "..."]

(which does not work right now).

To resolve that without changing the inner working, we could try to json.Unmarshal the notify.urls var in the notify.go file. If no error happens, we then use that instead of the base configUrls.

Please let me know your thought on this !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant