While updating and testing my Automated Lab Deployment Script for VMware Cloud Foundation (VCF), I often found myself checking whether the bringup process has completed or not using the Cloud Builder UI.
Ideally, I could configure some type of notification that would alert me immediately when the deployment has finished or if it ran into an issue and has failed.
Since Cloud Builder is just a Photon OS VM, that gave me an idea for a quick workaround ... 🤔
I can just setup a basic shell script that would run periodically using cron and when it detects the deployment has finished, it would then send a notification using the solution of my choice.
Step 1 - Copy the following content below into a file called vcf-bringup-notification.sh (or whatever name you wish to use). In my example, I will be sending a notification to Google Chat Space using an incoming webhook and you can do the same with Microsoft Teams or Slack, but you will need to make some edits to MESSAGE variable based on the required format.
#!/bin/bash WEBHOOK_URL="FILL_ME_IN" grep 'End of Orchestration' /var/log/vmware/vcf/bringup/*.log > /dev/null 2>&1 if [ $? -eq 0 ]; then BRINGUP_LOGENTRY=$(grep 'End of Orchestration' /var/log/vmware/vcf/bringup/*.log | head -1 | awk '{print $1}') BRINGUP_COMPLETE_TIME=$(echo ${BRINGUP_LOGENTRY#*.log:}) MESSAGE="{\"text\":\"VCF Bringup Completed at ${BRINGUP_COMPLETE_TIME}\"}" echo ${MESSAGE} > /tmp/file curl -X POST -H 'Content-Type: application/json' ${WEBHOOK_URL} -d @/tmp/file rm -f /var/spool/cron/root fi
Note: I would recommend testing the shell script separately before proceeding to the next step.
Step 2 - SSH to the Cloud Builder appliance using the "admin" account and then switch to the root user by running the following command:
su -
Step 3 - Add the following below to /var/spool/cron/root and add the following entry, which will run our script every 15 minutes. If you would like to change the interval, you can use crontab.guru to help with the configuration.
*/15 * * * * /root/vcf-bringup-notification.sh
The script should now run on the desired interval and only when it detects that the deployment has finished, will it then call the webhook and then clean itself up by removing the cronjob. If the deployment is still running, then nothing happens and it will re-run based on your schedule.
Here is an example output when the deployment is successful and the notification it send to a Google Chat Space
If you are using my latest Automated Lab Deployment Script for VMware Cloud Foundation (VCF), I have already included this capability as part of enhancing my deployment script. If you look at L114-117, you can now define and create your own notification shell script and it will automatically upload that to the Cloud Builder appliance and configure the cronjob for you!
Michael Zenzmaier says
hello william,
i'm working on the same toppic at the same time, but it's already getting quite late here in europe. 🙂
I would like to share an approach/thought.
Wouldn't it also be "simply" possible to build out your API query L803-L833 and use the "requests" to query the API status?
I don't (yet) have the skills to do this, but it should work?
Thanks for your great work, keep it up.
William Lam says
Yes, that did cross my mind but the challenge is that Mgmt Domain bring up is usually couple of hours which means you’ve got a long period where something could happen on machine running the check. The cronjob would remove the risk and you can even use Cloud Builder API to track same info, but I opted for a quick/dirty solution 🙂