flanksource / canary-checker

Kubernetes Native Health Check Platform
https://canarychecker.io
Apache License 2.0
172 stars 29 forks source link

Send events to external platform #1959

Open RelativeSure opened 3 weeks ago

RelativeSure commented 3 weeks ago

Hi,

At my workplace we are currently in the midst of working on a POC for this project. We get all our alerts in teams, slack is blocked at my workplace. 😭

Therefore, I want to be able to send failed tests to a teams webhook, if possible but I am unable to find documentation for this. I was thinking if I should use the exec resource and use that to send a failed event to teams, but I cannot figure out how to get run output from last resource in the same Canary. I have been working with this:

apiVersion: canaries.flanksource.com/v1
kind: Canary
metadata:
  name: pod-exit-code-check
  namespace: canarychecker
  #labels:
  #  "Expected-Fail": "false"
spec:
  schedule: "@every 1h"
  kubernetesResource:
    - name: "pod exit code"
      description: "Create pod & check its exit code"
      namespace: canarychecker
      resources:
        - apiVersion: v1
          kind: Pod
          metadata:
            name: "hello-world-{{strings.ToLower (random.Alpha 10)}}"
            #name: exit-code-check
            namespace: canarychecker
          spec:
            restartPolicy: Never
            containers:
              - name: hello-world
                image: hello-world:linux
      waitFor:
        expr: "dyn(resources).all(r, k8s.isHealthy(r))"
        interval: "1s"
        timeout: "20s"
      checkRetries:
        delay: 2s
        timeout: 5m
      checks:
        - kubernetes:
            - name: exit-code-check
              kind: Pod
              namespaceSelector:
                name: canarychecker
              resource:
                name: "{{(index .resources 0).Object.metadata.name}}"
              test:
                expr: >
                  size(results) == 1 &&
                  results[0].Object.status.containerStatuses[0].state.terminated.exitCode == 0
  exec:
    - description: send alert to teams
      script: |
        curl -H 'Content-Type: application/json' -d '{"text": "Hello World"}' <webhook url>
      name: send-alert-to-teams

Best regards.

DanielCastronovo commented 3 weeks ago

Same here, i would like to create a slack messages when they are a monitor in error state