robusta-dev / kubewatch

Watch k8s events and trigger Handlers
Apache License 2.0
604 stars 84 forks source link

Nothing sent via generic webhook to google-chat #65

Open lgraziosi opened 8 months ago

lgraziosi commented 8 months ago

Hello, I'm trying to use kubewatch to send everything to a google-chat webhook.
I configured everything, and the test seems fine:

root@kubewatch-64577c4cc7-v5thc:/# kubewatch config test
INFO[0000] Custom log formatter: json                   
INFO[0000] Setting custom log formatter to: json        
Testing Handler configs from .kubewatch.yaml
{"level":"info","msg":"No webhook cert is given","time":"2024-01-26T11:42:54Z"}
{"level":"info","msg":"Message successfully sent to https://chat.googleapis.com/v1/spaces/CENSORED at 2024-01-26 11:42:54.488587515 +0000 UTC m=+0.251134753 ","time":"2024-01-26T11:42:54Z"}

But nothing is actually received in the group chat mentioned.
As a reference, something simple as this in python actually sends the message:

from httplib2 import Http
from json import dumps
import sys

def main():
    url = 'https://chat.googleapis.com/v1/spaces/CENSORED'
    bot_message = {
        'text' : sys.argv[1]}

    message_headers = { 'Content-Type': 'application/json; charset=UTF-8'}

    http_obj = Http()

    response = http_obj.request(
        uri=url,
        method='POST',
        headers=message_headers,
        body=dumps(bot_message),
    )

    print(response)

if __name__ == '__main__':
    main()

What could be the issue? Am I missing something? Thanks.

RobertSzefler commented 8 months ago

This will most probably not work with the generic kubewatch webhook handler because the Google Chat webhook API expects a specific JSON format that this handler does not support.

I recently developed a sink in Robusta (it’s based on kubewatch) that is specifically designed to handle Google Chat, you might want to take a look at it.

Another option is to implement a specific handler for Google Chat in the kubewatch codebase, basing on the generic webhook handler. It shouldn't be too hard, the Google Chat webhook requirements are not hard to meet :)

lgraziosi commented 8 months ago

Another option is to implement a specific handler for Google Chat in the kubewatch codebase, basing on the generic webhook handler. It shouldn't be too hard, the Google Chat webhook requirements are not hard to meet :)

That would be very cool. I certantly would be using it.
Thanks.