Skip to content
New issue

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

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

Already on GitHub? # to your account

MattermostWebhook does not send message to https server #13514

Open
4 tasks done
zepaz opened this issue May 22, 2024 · 3 comments
Open
4 tasks done

MattermostWebhook does not send message to https server #13514

zepaz opened this issue May 22, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@zepaz
Copy link

zepaz commented May 22, 2024

First check

  • I added a descriptive title to this issue.
  • I used the GitHub search to find a similar issue and didn't find it.
  • I searched the Prefect documentation for this issue.
  • I checked that this issue is related to Prefect and not one of its dependencies.

Bug summary

Loading in the prefect Block and trying to send a message results in a status code 400 because the message is attempted to be send over an http:// connection instead of the https:// connection.

Reproduction

Code:

from prefect.blocks.notifications import MattermostWebhook
mattermost_webhook_block = MattermostWebhook.load("mattermost")
mattermost_webhook_block.notify("Hello from Prefect!")

This is in my Block:

MattermostWebhook(notify_type='prefect_default',
hostname='my-mattermost-server', 
token=SecretStr('**********'), 
botname='Test', 
channels=None, 
include_image=False, 
path=None, 
port=443)

Error

Log:
`
| WARNING | apprise - Failed to send Mattermost notification: Bad Request - Unsupported Parameters., error=400.
`
Requests.response:

b'<html>\r\n<head><title>400 The plain HTTP request was sent to HTTPS port</title></head>\r\n<body>\r\n<center><h1>400 Bad Request</h1></center>\r\n<center>The plain HTTP request was sent to HTTPS port</center>\r\n<hr><center>nginx/1.20.1</center>\r\n</body>\r\n</html>\r\n'


### Versions

```Text
Version:             2.16.4
API version:         0.8.4                    
Python version:      3.11.3                   
Git commit:          e3e7df9d                 
Built:               Thu, Mar 14, 2024 5:11 PM
OS/Arch:             win32/AMD64              
Profile:             dev                      
Server type:         server

Additional context

It looks like the problem is that when apprise gets initialized by

NotifyMattermost(
                token=self.token.get_secret_value(),
                fullpath=self.path,
                host=self.hostname,
                botname=self.botname,
                channels=self.channels,
                include_image=self.include_image,
                port=self.port,
)

it does not set a parameter for secure nor schema. If either secure or schema would get send, the URLBase class would have set self.secure = True and that would change the schema to https:// instead it sets self.secure = False and thus the schema used is http://

@zepaz zepaz added bug Something isn't working needs:triage labels May 22, 2024
@zepaz
Copy link
Author

zepaz commented May 22, 2024

for anyone reading along, #8141 (comment) has a workaround. In short; switch to slackwebhook, although not all Mattermost features are supported

@kripnerl
Copy link

kripnerl commented Dec 11, 2024

It is indeed a pity to use Slack webhook, which has less functionality.

For the record, the Mattermost block was added by #8341 (@zzstoatzz )

The support of the secure servers should be quite straightforward:

add

secure: bool = Field(
        default=False,
        description="Set True if the Mattermost server is running over https.",
    )

to

and

        url = SecretStr(
            NotifyMattermost(
                token=self.token.get_secret_value(),
                fullpath=self.path,
                host=self.hostname,
                botname=self.botname,
                channels=self.channels,
                include_image=self.include_image,
                port=self.port,
                secure=self.secure,
            ).url()

to

Unfortunately, this is the maximum I can afford for this issue at the moment. I may eventually create the pull request; however, I would appreciate it if somebody else took it from here.

Anyway, many thanks for the Prefect project!

@sochotnicky
Copy link
Contributor

FYI this is mostly sorted in PR #16884 which lets you set secure to True if you are sending HTTPs traffic.

But then I also found a bug in apprise so you might need caronc/apprise#1293 (unmerged right now)

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

No branches or pull requests

4 participants