Skip to content

Examples for Slack, Teams, Webex, Discord Notifications and k8s events

In these examples, we will configure Sveltos to send a notification whenever all the add-ons and applications listed in the ClusterProfile are deployed to the clusters matching the cluster label selector set to env=fv.

Once the defined conditions are met, a notification will be generated and send out.

Slack

---
apiVersion: lib.projectsveltos.io/v1beta1
kind: ClusterHealthCheck
metadata:
  name: production
spec:
  clusterSelector:
    matchLabels:
      env: fv
  livenessChecks:
  - name: addons
    type: Addons
  notifications:
  - name: slack
    type: Slack
    notificationRef:
      apiVersion: v1
      kind: Secret
      name: slack
      namespace: default

The above slack secret contains the Slack channel and the token.

$ kubectl create secret generic slack \
  --from-literal=SLACK_CHANNEL_ID=<your channel id> \
  --from-literal=SLACK_TOKEN=<your token> \
  --type=addons.projectsveltos.io/cluster-profile

Webex

---
apiVersion: lib.projectsveltos.io/v1beta1
kind: ClusterHealthCheck
metadata:
  name: production
spec:
  clusterSelector:
    matchLabels:
      env: fv
  livenessChecks:
  - name: addons
    type: Addons
  notifications:
  - name: webex
    type: Webex
    notificationRef:
      apiVersion: v1
      kind: Secret
      name: webex
      namespace: default

The above Webex secret contains the Webex room id and the token.

$ kubectl create secret generic webex \
  --from-literal=WEBEX_ROOM_ID=<your channel id> \
  --from-literal=WEBEX_TOKEN=<your token> \
  --type=addons.projectsveltos.io/cluster-profile

Teams

---
apiVersion: lib.projectsveltos.io/v1beta1
kind: ClusterHealthCheck
metadata:
  name: production
spec:
  clusterSelector:
    matchLabels:
      env: fv
  livenessChecks:
  - name: addons
    type: Addons
  notifications:
  - name: teams
    type: Teams
    notificationRef:
      apiVersion: v1
      kind: Secret
      name: teams
      namespace: default

The above Teams secret contains the Teams webhook URL.

$ kubectl create secret generic teams \
  --from-literal=TEAMS_WEBHOOK_URL="<your URL>" \
  --type=addons.projectsveltos.io/cluster-profile

Discord

---
apiVersion: lib.projectsveltos.io/v1beta1
kind: ClusterHealthCheck
metadata:
  name: production
spec:
  clusterSelector:
    matchLabels:
      env: fv
  livenessChecks:
  - name: addons
    type: Addons
  notifications:
  - name: discord
    type: Discord
    notificationRef:
      apiVersion: v1
      kind: Secret
      name: discord
      namespace: default

The above discord secret contains the Discord channel id and the token.

$ kubectl create secret generic discord \
  --from-literal=DISCORD_CHANNEL_ID=<your channel id> \
  --from-literal=DISCORD_TOKEN=<your token> \
  --type=addons.projectsveltos.io/cluster-profile

Kubernetes event

---
apiVersion: lib.projectsveltos.io/v1beta1
kind: ClusterHealthCheck
metadata:
  name: production
spec:
  clusterSelector:
    matchLabels:
      env: fv
  livenessChecks:
  - name: addons
    type: Addons

To list the events generated by Sveltos, use the below command.

$ kubectl get events -n default --field-selector reason=ClusterHealthCheck
LAST SEEN   TYPE      REASON               OBJECT                  MESSAGE
31s         Normal    ClusterHealthCheck   clusterhealthcheck/hc   cluster Capi:default/sveltos-management-workload...
16s         Warning   ClusterHealthCheck   clusterhealthcheck/hc   cluster Capi:default/sveltos-management-workload...

Tip

The Event type will be set to: type: Normal when the add-ons are deployed.

The Event message contains the below information on the cluster: 1. Cluster type: Capi or Sveltos 1. Cluster namespace 1. Cluster name