Cronicle icon indicating copy to clipboard operation
Cronicle copied to clipboard

Issues with Webhook for MS Teams using corporate proxy

Open StoneCut opened this issue 4 years ago • 7 comments

Summary

We are trying to set up a webhook for MS Teams, however we are running into issues which are possibly related to using a corporate proxy.

Web Hook Error: https://outlook.office.com/webhook/xxxxxx/IncomingWebhook/xxxxx/xxxxxx: Error: Connection Refused: Failed to connect to host: outlook.office.com]

Your Setup

We have a proxy configured in our environment variables and also set one for npm (which may be totally unrelated):

# npm set config set proxy http://ourproxy.domain:8080
# npm set config set https-proxy http://ourproxy.domain:8080

The same URL ist reachable using cURL on the same machine.

We configured relevant web_hook_custom_data in config.json:

"web_hook_custom_data": {
		"@type": "MessageCard",
		"@context": "https://schema.org/extensions",
		"summary": "Cronicle Test",
		"themeColor": "0078D7",
		"title": "Test",
		"sections": [
				{
						"activityTitle": "Notification",
						"activitySubtitle": "Super important",
						"activityImage": "https://www.iconsdb.com/icons/download/black/message-2-48.png",
						"facts": "The facts",
						"text": "The text"
				}
		]
},

Operating system and version?

Ubuntu 18.04.5 LTS

Node.js version?

v8.10.0

Cronicle software version?

v0.8.54

Are you using a multi-server setup, or just a single server?

Single server

Are you using the filesystem as back-end storage, or S3/Couchbase?

file system

Can you reproduce the crash consistently?

No crash, but yes I can reproduce

Log Excerpts

[1611239674.52][2021-01-21 15:34:34][some-hostname][16369][Cronicle][debug][9][Firing web hook for job complete: jkk6yi16r01: https://outlook.office.com/webhook/xxxxxx/IncomingWebhook/xxxxx/xxxxxx][]
[1611239674.528][2021-01-21 15:34:34][some-hostname][16369][Cronicle][debug][9][Web Hook Error: https://outlook.office.com/webhook/xxxxxx/IncomingWebhook/xxxxx/xxxxxx: Error: Connection Refused: Failed to connect to host: outlook.office.com][]

Is it not possible to send web hook notifications when using a proxy?

StoneCut avatar Jan 21 '21 16:01 StoneCut

I believe those proxy env variables only used by npm to install modules. When you do actual http request via some node http client you need to specify proxy in request options. I don't think there is a way to configure this in cronicle, but this is definitely tweakable.

Regarding incomig webhooks - you don't really need to configure web_hook_custom_data. It will work out of the box since incoming webhooks use message data from "text" property of the request body (cornicle provides this already). Check the link below for MS teams but this is true basically for any other messenger (slack, webex, etc) https://docs.microsoft.com/en-us/microsoftteams/platform/webhooks-and-connectors/how-to/connectors-using#post-a-message-to-the-webhook-using-curl

mikeTWC1984 avatar Jan 22 '21 03:01 mikeTWC1984

Try the script below and see if you can call your webhook. It's using same http client as cronicle. Save it as test.js in cronicle base directory (/opt/cronicle) and execute using node (e.g. node test.js)

const PixlRequest = require('pixl-request');
const request = new PixlRequest();

let body = { text: "hello there"}
let options = {
    host: "ourproxy.domain",
    port: "8080",
    path: "https://outlook.office.com/webhook/xxxxxx...",
    timeout: 3000
}
request.json("", body, options, (err, resp, data) => {
   if(err) return console.error(err)
   console.log(data)
});

mikeTWC1984 avatar Jan 22 '21 03:01 mikeTWC1984

Thank you for your help! The referenced cURL command from the MS website works fine. You code snippet also works. How can I get this to work with Cronicle?

StoneCut avatar Jan 22 '21 07:01 StoneCut

I can add some configuration features to allow this to work with Cronicle web hooks. I'm not sure how yet, but I'll figure something out.

jhuckaby avatar Jan 22 '21 16:01 jhuckaby

I can add some configuration features to allow this to work with Cronicle web hooks. I'm not sure how yet, but I'll figure something out.

Thank you, that would be much appreciated.

StoneCut avatar Jan 23 '21 15:01 StoneCut

Okay, Cronicle version v0.8.55 has just dropped, with outbound web hook proxy support. Here is what you should do:

First, upgrade Cronicle to the latest. See these instructions for details.

Second, edit your /opt/cronicle/conf/config.json file and include the new web_hook_custom_opts section:

"web_hook_custom_opts": {
	"host": "my-corp-proxy.com",
	"port": 8080
}

Third, restart Cronicle one last time, and then fire off an event with a web hook configured. Set the web hook URL to the final destination URL you want, and it should detect the proxy host/port, and set the URL as the path parameter internally.

Thanks to @mikeTWC1984 for the code snippet. I honestly have never seen nor used a proxy before.

jhuckaby avatar Jan 23 '21 17:01 jhuckaby

Thank you very much for incorporating the change so quickly. Unfortunately, it doesn't seem to work for some reason:

[1611559375.439][2021-01-25 08:22:55][somehost][7097][Cronicle][debug][9][Firing web hook for job complete: jkkc8ubzc01: https://outlook.office.com/webhook/xxxxxx@xxxxxx/IncomingWebhook/xxxxxx/xxxxxx][]
[1611559375.449][2021-01-25 08:22:55][somehost][7097][Cronicle][debug][9][Web Hook Error: https://outlook.office.com/webhook/xxxxxx@xxxxxx/IncomingWebhook/xxxxxx/xxxxxx: Error: Protocol error (write EPROTO 140659875064704:error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol:s23_clnt.c:827: )][]

EDIT: I think I figured out the cause. According to the documentation for http.request it uses "http:" protocol by default. However, the implementation in Cronicle appears to use "https:" instead because if I configure "protocol" to explicitly use "http:" I receive a different error:

[1611567023.502][2021-01-25 10:30:23][emea-srv-s02p][23007][Cronicle][debug][9][Firing web hook for job start: jkkcde9oi01: https://outlook.office.com/webhook/xxxxxx@xxxxxx/IncomingWebhook/xxxxxx/xxxxxx][]
[1611567023.508][2021-01-25 10:30:23][emea-srv-s02p][23007][Cronicle][debug][1][Uncaught Exception: Error: Protocol "http:" not supported. Expected "https:"][Error: Protocol "http:" not supported. Expected "https:"     at new ClientRequest (_http_client.js:131:11)     at Object.request (http.js:38:10)     at Object.request (https.js:239:15)     at __construct.request (/opt/cronicle/node_modules/pixl-request/request.js:551:25)     at __construct.post (/opt/cronicle/node_modules/pixl-request/request.js:358:8)     at __construct.json (/opt/cronicle/node_modules/pixl-request/request.js:166:15)     at /opt/cronicle/lib/job.js:295:20     at /opt/cronicle/node_modules/async/dist/async.js:3874:9     at /opt/cronicle/node_modules/async/dist/async.js:473:16     at replenish (/opt/cronicle/node_modules/async/dist/async.js:993:25)]

If I configure "protocol" to use the non-default "https:" then I receive the error I posted first again.

Could you please review the implementation to support http? Many thanks!

StoneCut avatar Jan 25 '21 07:01 StoneCut