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

Fix mattermost couldn't find channel issue #1298

Merged
merged 1 commit into from
Feb 13, 2022

Conversation

ananthkamath
Copy link
Contributor

@ananthkamath ananthkamath commented Feb 13, 2022

Description

The Mattermost integration currently has a small problem, which is if the name of the channel include Upper Case letters like Uptime-Alerts the backend will trigger a "Couldn't find the channel" error. This happens because the Mattermost expects the channel name in url in Lower Case as uptime-alerts.

People who use lower case letters for channels will not face this issue, but people who use Upper Case in channel will get above error.

Fixes #(issue)

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Checklist

  • My code follows the style guidelines of this project
  • I ran ESLint and other linters for modified files
  • I have performed a self-review of my own code and tested it
  • I have commented my code, particularly in hard-to-understand areas
  • My changes generate no new warnings
  • My code needed automated testing. I have added them (this is optional task)

Screenshots (if any)

Error Trace from logs:

Error: Error: Error: Request failed with status code 404 {"id":"web.incoming_webhook.channel.app_error","message":"Couldn't find the channel","detailed_error":"","request_id":"7yo4xcmbgtd3mf417d8pfnrixr","status_code":404}

Mattermost Link Sample:

@ananthkamath
Copy link
Contributor Author

@louislam first of all kudos on Uptime-Kuma, it is a fantastic tool and really helpful for monitoring critical services in private cloud. There are very few tools in this space.

When i started using this tool, if found that Mattermost alerts did not get delivered. Hence I wanted to raise and issue, but saw we already had few open issues addressing this problem.

So I started debugging via logs and found the problem, the change is very minor but wanted to be part of your journey with Uptime-Kuma :)

@@ -20,7 +20,7 @@ class Mattermost extends NotificationProvider {
return okMsg;
}

const mattermostChannel = notification.mattermostchannel;
const mattermostChannel = notification.mattermostchannel.toLowerCase;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believed that it should be .toLowerCase() ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that is correct my bad, fixed the same.

@philippkayser
Copy link

@louislam is the fix already included in v1.11.4?

Because we still receive:

Cannot send notification to Chat Notifications Error: Error: Error: Request failed with status code 404 {"id":"web.incoming_webhook.channel.app_error","message":"Couldn't find the channel.","detailed_error":"","request_id":"ezjbz8y4fp","status_code":404} at Mattermost.throwGeneralAxiosError (/app/server/notification-providers/notification-provider.js:32:15) at Mattermost.send (/app/server/notification-providers/mattermost.js:117:18) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Function.sendNotification (/app/server/model/monitor.js:684:21) at async beat (/app/server/model/monitor.js:391:17) at async Timeout.safeBeat [as _onTimeout] (/app/server/model/monitor.js:443:17)

@louislam
Copy link
Owner

@louislam is the fix already included in v1.11.4?

Because we still receive:

Cannot send notification to Chat Notifications Error: Error: Error: Request failed with status code 404 {"id":"web.incoming_webhook.channel.app_error","message":"Couldn't find the channel.","detailed_error":"","request_id":"ezjbz8y4fp","status_code":404} at Mattermost.throwGeneralAxiosError (/app/server/notification-providers/notification-provider.js:32:15) at Mattermost.send (/app/server/notification-providers/mattermost.js:117:18) at runMicrotasks (<anonymous>) at processTicksAndRejections (internal/process/task_queues.js:95:5) at async Function.sendNotification (/app/server/model/monitor.js:684:21) at async beat (/app/server/model/monitor.js:391:17) at async Timeout.safeBeat [as _onTimeout] (/app/server/model/monitor.js:443:17)

No, it was fixed after 1.11.4.

@philippkayser
Copy link

Thanks @louislam, so we will wait for the next release :-)

@nietzscheanic
Copy link

nietzscheanic commented Mar 9, 2022

The channel name is not a required field, but if you leave it empty your bug fix leads into:

Cannot send notification to Mattermost
Error: Error: TypeError: Cannot read property 'toLowerCase' of undefined
at Mattermost.throwGeneralAxiosError (/app/server/notification-providers/notification-provider.js:32:15)
at Mattermost.send (/app/server/notification-providers/mattermost.js:117:18)
at Function.send (/app/server/notification.js:94:57)
at Function.sendNotification (/app/server/model/monitor.js:687:40)
at async beat (/app/server/model/monitor.js:402:17)
at async safeBeat (/app/server/model/monitor.js:446:17)

Moreover you forgot to implement toLowerCase for the test button function of the configuraton dialog. That's why the test case doesn't leads to an error when the channel name isn't set, but the triggered action leads to an error in 1.12.1

edit: the channel name isn't used in the test case that's why both cases behave in a different way

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

Successfully merging this pull request may close these issues.

None yet

4 participants