VEBA mascot - Otto the Orca

VMware Event Broker Appliance – Part IV – Deploying the Slack Function (Knative)

In Part III of this series, we deployed the Knative Powershell echo function. In this post, we will deploy the Knative Powershell Slack function.

The PowerShell Slack function lets you send a Slack notification for any event that happens in vCenter. It does this by using Slack’s webhook feature.

First, we need a webhook configured in Slack. You can check out the first half of my post on using Slack webhooks with VMC for help creating a Slack webhook.

Next we build our Docker image

docker build -t kremerpatrick/kn-ps-slack:1.0 .

Then push our Docker image

docker push kremerpatrick/kn-ps-slack:1.0

Now we test our container using the same split window technique we learned in Part III. In the left window we start our container. Note that you should replace the webhook URL in the command below with the URL you get from Slack.

NOTE: This syntax for Windows differs from the syntax for Linux. This is called out in the README for this function in the repo, but note that the use of quotations in SLACK_SECRET are different for Windows than on Linux.

docker run -e FUNCTION_DEBUG=true -e PORT=8080 -e SLACK_SECRET="{'SLACK_WEBHOOK_URL': ''}" -it --rm -p 8080:8080 kremerpatrick/kn-ps-slack:1.0

In the right window, we run test.ps1


We now see debug output in the left window – the function has been invoked and apparently succeeded.

We check our Slack channel and the notification succeeded!

Now that we know the function works, we need to push it to VEBA. First we need to securely store our Webhook URL. For this, we use Kubernetes secrets

We open up the file named secret and paste in our Slack webhook URL.

We create our secret. This syntax looks a bit odd. slack-secret is the Kubernetes secret name. SLACK_SECRET is the environment variable used in handler.ps1. secret is the name of the file that contains the secret.

kubectl -n vmware-functions create secret generic slack-secret --from-file=SLACK_SECRET=secret

Edit function.yaml and replace the URL with the Docker ID that we pushed the image into.

We scroll down to the Trigger section of function.yaml and find that the event that we are triggering on is VMPoweredOffEvent. We will need to power off a virtual machine to trigger this function.

We deploy the function

kubectl apply -f function.yaml

Now that the pod is deployed, we should power off a VM and see if the function triggers

The message pops up in Slack. Success!

1 comment

Leave a Reply

Your email address will not be published. Required fields are marked *