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

MS Teams notification reporting syntax incorrect in Windows #1245

Closed
giggio opened this issue Mar 8, 2022 · 14 comments · Fixed by #1249
Closed

MS Teams notification reporting syntax incorrect in Windows #1245

giggio opened this issue Mar 8, 2022 · 14 comments · Fixed by #1249

Comments

@giggio
Copy link

giggio commented Mar 8, 2022

Describe the bug

Running with the msteams notification yields an error.

To Reproduce

  1. Run c:\bin\watchtower.exe --notifications msteams --notification-msteams-hook https://x.webhook.office.com/x --trace
  2. See error:
time="2022-03-08T15:03:04-03:00" level=fatal msg="open https://x.webhook.office.com/x: The filename, directory name, or volume label syntax is incorrect."

Expected behavior
Runs without errors.

Environment
This is running as a container, using this images from visualon:

docker run -ti --rm --entrypoint cmd -v \\.\pipe\docker_engine:\\.\pipe\docker_engine ghcr.io/visualon/watchtower:1.4.0

This image is running the latest 1.4.0 version in a Nano server.

Additional context
I tried it with --trace and --debug, neither work, it exits immediately.
If I run with trace and without the notification I can see that it works as expected, it finds the containers, and is able to connect to docker hub and do its thing.
I have a Linux server working fine with watchtower, using the same teams webhook url, so the url is not the problem.
I also tried it with the environment variables instead of the parameters, I got the same results.

@github-actions
Copy link

github-actions bot commented Mar 8, 2022

Hi there! 👋🏼 As you're new to this repo, we'd like to suggest that you read our code of conduct as well as our contribution guidelines. Thanks a bunch for opening your first issue! 🙏

@giggio
Copy link
Author

giggio commented Mar 8, 2022

I just tried without the container, it fails with the same error. Downloaded and extracted the latest release, then ran it with the same arguments.

@piksel
Copy link
Member

piksel commented Mar 9, 2022

Yeah, this is unfortunately a bug with the windows os package in go std lib. There is no way to check if a file exists. On other platforms, you can just os.stat for a file and it will return a os.ErrNotExist error. On windows, it just causes a fatal error and exits the app.

It should be possible to fix by ruling out any arguments that have "invalid" characters in the name. The : is the most common culprit for our use case.

The reason why it hasn't been fixed is that we don't really have any known windows users of watchtower.

@giggio
Copy link
Author

giggio commented Mar 9, 2022

You do now! What can I do to help?

@piksel
Copy link
Member

piksel commented Mar 10, 2022

You can try the branch fix/windows-flag-files and see if it fixes your problem.

@giggio
Copy link
Author

giggio commented Mar 10, 2022

Ok, I'm getting a different error, now: Error instantiating Docker client: protocol not available.

$ .\watchtower.exe --notifications msteams --notification-msteams-hook https://x.webhook.office.com/x --trace
time="2022-03-10T12:18:13-03:00" level=debug
time="2022-03-10T12:18:13-03:00" level=fatal msg="Error instantiating Docker client: protocol not available"

I built it with build.sh. The problem with the url seems to be gone, I'll investigate some more and report what I find. This new error also happens with the binary built with the release gh action.

@giggio
Copy link
Author

giggio commented Mar 10, 2022

Yes, the problem is fixed. I'm not sure why the problem is happening when I run it from the command line directly, but if I put it in a container it works. I got the notification in Teams just fine.

@giggio
Copy link
Author

giggio commented Mar 10, 2022

Just for completeness, this is the log I got (partially redacted):

$ \bin\watchtower.exe --label-enable  --notifications msteams --notification-msteams-hook https://x.webhook.office.com/x --run-once --monitor-only --debug
time="2022-03-10T12:36:03-03:00" level=debug
time="2022-03-10T12:36:03-03:00" level=debug msg="Sleeping for a second to ensure the docker api client has been properly initialized."
time="2022-03-10T12:36:04-03:00" level=debug msg="Making sure everything is sane before starting"
time="2022-03-10T12:36:04-03:00" level=info msg="Watchtower v1.4.0-4-gc25f848"
time="2022-03-10T12:36:04-03:00" level=info msg="Using notifications: teams"
time="2022-03-10T12:36:04-03:00" level=info msg="Only checking containers using enable label"
time="2022-03-10T12:36:04-03:00" level=info msg="Running a one time update."
time="2022-03-10T12:36:04-03:00" level=debug msg="Checking containers for updated images"
time="2022-03-10T12:36:04-03:00" level=debug msg="Retrieving running containers"
time="2022-03-10T12:36:05-03:00" level=debug msg="Trying to load authentication credentials." container=/...

@giggio
Copy link
Author

giggio commented Mar 10, 2022

Never mind this comment, I debugged in Windows (my first ever debug on golang!) and noticed my url was wrong, sorry about that.

Well, I'm not sure what happened, but I can't make it work anymore. I'm getting the error time="2022-03-10T14:24:20-03:00" level=fatal msg="failed to create notification config: invalid webhook URL format".

This is when running (url changed, I'm using a real teams url):

.\watchtower.exe --label-enable --notifications msteams --notification-msteams-hook https://x.webhook.office.com/x --run-once --monitor-only --debug

@piksel
Copy link
Member

piksel commented Mar 11, 2022

Thanks for testing it! I use docker desktop with "Expose daemon on tcp://localhost:2375 without TLS" enabled, and the DOCKER_HOST env variable set to tcp://localhost:2375.
The visualon docker image adds

ENV DOCKER_HOST=npipe:////./pipe/docker_engine

to the image, which is probably why it works with just the pipe mounted.

It should probably work the same way if your run:

$ \bin\watchtower.exe --host npipe:////./pipe/docker_engine --label-enable  --notifications msteams --notification-msteams-hook https://x.webhook.office.com/x --run-once --monitor-only --debug

@piksel
Copy link
Member

piksel commented Mar 11, 2022

Also, I added a check in the build script that adds .exe to the end of the binary when it's being run in MSYS/MINGW (git bash).

@giggio
Copy link
Author

giggio commented Mar 11, 2022

When I set DOCKER_HOST it worked too. Yes, that was the problem!
The fix in the bash script is welcome, I had to manually rename it. :)
Debugging with VS Code was easy enough, too. I'm not sure what tools you use, but it would be useful to add the .vscode/launch.json file. This is what I used, if anyone ever needs it (webhook redacted):

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch Package",
            "type": "go",
            "request": "launch",
            "mode": "auto",
            "program": "${workspaceRoot}/main.go",
            "args": [
                "--label-enable",
                "--notifications",
                "msteams",
                "--notification-msteams-hook",
                "https://x.webhook.office.com/webhookb2/x",
                "--run-once",
                "--monitor-only",
                "--debug"
            ],
            "env": {
                "DOCKER_HOST": "npipe:////./pipe/docker_engine"
            },
        }
    ]
}

@giggio
Copy link
Author

giggio commented Jul 1, 2022

Hi @piksel, do you know when a new release will be made? We've been expecting this fix.
Thanks!

@piksel
Copy link
Member

piksel commented Jul 1, 2022

I can't give a date, but I should be able to find some time for this pretty soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants