Last active
April 8, 2020 12:45
-
-
Save m4c3/e3d8e3730e7a5575e84008a66c472bfa to your computer and use it in GitHub Desktop.
VCenter Alarm Action Script that creates downtimes in CheckMK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# this script creates downtimes in checkmk based on vmware vcenter alarm actions | |
# put this script in /var/local/ on your vcenter appliance | |
# | |
# requires the python3 compatible downtime handler from | |
# https://raw.githubusercontent.com/tribe29/checkmk/master/doc/treasures/downtime.python3.py | |
# in /var/local/ | |
USER="automation" | |
PASS="secret" | |
URL="https://host/site/check_mk/" | |
COMMENT="automatic VCSA Downtime" | |
DURATION="43200" | |
# logs to /storage/log/vmware/messages | |
logger "CheckMK-Downtime VMWARE_ALARM_EVENT_HOST: $VMWARE_ALARM_EVENT_HOST" | |
logger "CheckMK-Downtime VMWARE_ALARM_TRIGGERINGSUMMARY: $VMWARE_ALARM_TRIGGERINGSUMMARY" | |
echo "$VMWARE_ALARM_TRIGGERINGSUMMARY" | head -n 1 | grep -iE 'enter|shut down' -q | |
if [ $? -eq 0 ] | |
then | |
# set downtime | |
logger "CheckMK-Downtime set: $VMWARE_ALARM_EVENT_HOST" | |
/var/local/downtime -u "$USER" -S "$PASS" -U "$URL" -c "$COMMENT" -d "$DURATION" -s "$VMWARE_ALARM_EVENT_HOST" | |
fi | |
echo "$VMWARE_ALARM_TRIGGERINGSUMMARY" | head -n 1 | grep -i exit -q | |
if [ $? -eq 0 ] | |
then | |
# remove downtime | |
sleep 2m | |
logger "CheckMK-Downtime remove: $VMWARE_ALARM_EVENT_HOST" | |
/var/local/downtime -u "$USER" -S "$PASS" -U "$URL" -r "$VMWARE_ALARM_EVENT_HOST" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment