wongnai / kube-slack

Kubernetes Slack Monitoring
MIT License
323 stars 59 forks source link

Proxy setting to reach slack webhooks. #34

Closed Saggi432 closed 6 years ago

Saggi432 commented 6 years ago

Firstly, thank you so much for providing this capability.. i am sure this is going to help to monitor the k8s infra...below is my query to run inside a corporate network..

I am running inside a corporate network, so i tried setting the http_proxy, https_proxy as env variables. I also set the proxy https_proxy in the .npmrc..but still i face the below error from the pod logs

(node:1) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 201) (node:1) UnhandledPromiseRejectionWarning: Error: tunneling socket could not be established, cause=connect EINVAL 0.0.35.130:80 - Local (0.0.0.0:0) at

My NPM config on the pod looks like below..

app $ npm config ls ; cli configs metrics-registry = "https://ok-repo.ok.com/nodejs/content/groups/npm/" scope = "" user-agent = "npm/5.6.0 node/v8.11.2 linux x64"

; project config /app/.npmrc https-proxy = "proxy-appgw.ok.com:9090" registry = "https://ci-repo.ok.com/nodejs/content/groups/npm/"

; userconfig /home/kube-slack/.npmrc http_proxy = "http://proxy-appgw.ok.com:9090" https_proxy = "http://proxy-appgw.ok.com:9090" proxy = "http://proxy-appgw.ok.com:9090/"

; node bin location = /usr/local/bin/node ; cwd = /app ; HOME = /home/kube-slack ; "npm config ls -l" to show all defaults.

whs commented 6 years ago

The npm settings are for npm commands only.

We're using Slack's SDK behind the scene, so this is how the docs says how to do it and added to this file.

whs commented 6 years ago

Oh wait, we're using node-slack

https://github.com/xoxco/node-slack/blob/81ed5dd5d91dd0d15b1adeb7d8cea270406752fe/slack.js#L31

so setting https_proxy or http_proxy should work...

I'm guessing that maybe Kubernetes API access is proxied too. Could you check your proxy server logs (or tcpdump)?

Saggi432 commented 6 years ago

Thank you for the reply.. Just to confirm more our K8S master and other infra is running on the same subnet as the node so to reach the k8s API we would not need the proxy to be set.. however we need proxy to reach slack as its outside our network..

On the logs at proxy sever..sure let me check them and get back to you.. since its corporate it might be difficult to get these logs.

whs commented 6 years ago

Yup, I'd like to know how the proxy get used.

On reading the original logs again, I noticed it mentioned EINVAL 0.0.35.130:80. Is that IP your proxy server? And is the 0.0 prefix redacted or is it that way in the log.

Saggi432 commented 6 years ago

The IP is not the proxy server IP.

I went to the pod shell and set the https_proxy manually and ran the following from the command line. this time its a different error..

app $ node . {"name":"kube-slack","hostname":"kube-slack-5df468977d-845w9","pid":47,"level":30,"msg":"Kubernetes monitors started","time":"2018-05-23T23:38:22.582Z","v":0}

node:47) UnhandledPromiseRejectionWarning: Error: tunneling socket could not be established, statusCode=403 at ClientRequest.onConnect (/app/node_modules/tunnel-agent/index.js:166:19) at Object.onceWrapper (events.js:319:30) at emitThree (events.js:136:13) at ClientRequest.emit (events.js:217:7) at Socket.socketOnData (_http_client.js:474:11) at emitOne (events.js:116:13) at Socket.emit (events.js:211:7) at addChunk (_stream_readable.js:263:12) at readableAddChunk (_stream_readable.js:250:11) at Socket.Readable.push (_stream_readable.js:208:10) at TCP.onread (net.js:597:20) (node:47) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:47) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

Saggi432 commented 6 years ago

Hi.. i did a try by enabling the http_noproxy as well to make sure the k8s cluster does not use proxy when it makes its call.. but still the 403 error comes up.. i will dig further and update you.

whs commented 6 years ago

I just added SLACK_PROXY option in master. Could you please try the image with latest tag?

Saggi432 commented 6 years ago

sure.. let me give a try..thank you!

Saggi432 commented 6 years ago

Hi, I just tried with the new changes in master..it looks to have an error..there is a conflict with config directory..cannot find the module config.

internal/modules/cjs/loader.js:596 throw err; ^ Error: Cannot find module 'config' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15) at Function.Module._load (internal/modules/cjs/loader.js:520:25) at Module.require (internal/modules/cjs/loader.js:650:17) at require (internal/modules/cjs/helpers.js:20:18) at Object.<anonymous> (/app/src/index.js:3:16) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3)

whs commented 6 years ago

You can use the prebuilt image on Docker hub (tagged latest).

For that error I believe you haven't run npm install or config module is missing from packages.json.

On Sat, Jun 2, 2018, 1:13 AM satishkumar432 notifications@github.com wrote:

Hi, I just tried with the new changes in master..it looks to have an error..there is a conflict with config directory..cannot find the module config.

internal/modules/cjs/loader.js:596 throw err; ^ Error: Cannot find module 'config' at Function.Module._resolveFilename (internal/modules/cjs/loader.js:594:15) at Function.Module._load (internal/modules/cjs/loader.js:520:25) at Module.require (internal/modules/cjs/loader.js:650:17) at require (internal/modules/cjs/helpers.js:20:18) at Object. (/app/src/index.js:3:16) at Module._compile (internal/modules/cjs/loader.js:702:30) at Object.Module._extensions..js (internal/modules/cjs/loader.js:713:10) at Module.load (internal/modules/cjs/loader.js:612:32) at tryModuleLoad (internal/modules/cjs/loader.js:551:12) at Function.Module._load (internal/modules/cjs/loader.js:543:3)

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/wongnai/kube-slack/issues/34#issuecomment-393966008, or mute the thread https://github.com/notifications/unsubscribe-auth/AAVFi6kBHzuNO-0ZyFDIVnkXxv7S7LIHks5t4YRNgaJpZM4UFZAd .