-
Notifications
You must be signed in to change notification settings - Fork 23
/
check_gcp_maintenance_event.sh
executable file
·46 lines (42 loc) · 1.12 KB
/
check_gcp_maintenance_event.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/usr/bin/env bash
#
# Check GCP instance maintenance event
# https://cloud.google.com/compute/docs/storing-retrieving-metadata#maintenanceevents
#
# Usage: check_gcp_maintenance_event.sh
# -h, --help Display this screen
#
# (c) 2017, Benjamin Dos Santos <[email protected]>
# https://github.com/bdossantos/nagios-plugins
#
while [[ -n "$1" ]]; do
case $1 in
--help | -h)
sed -n '2,7p' "$0" | tr -d '#'
exit 3
;;
*)
echo "Unknown argument: $1"
exec "$0" --help
exit 3
;;
esac
shift
done
event=$(
curl -s -H 'Metadata-Flavor: Google' \
http://metadata.google.internal/computeMetadata/v1/instance/maintenance-event \
2>/dev/null
)
if [[ "$event" == 'MIGRATE_ON_HOST_MAINTENANCE' ]]; then
echo 'WARNING - Undergoing host maintenance, instance will be migrated'
exit 1
elif [[ "$event" == 'SHUTDOWN_ON_HOST_MAINTENANCE' ]]; then
echo 'WARNING - Undergoing host maintenance, instance will be shut down'
exit 1
elif [[ "$event" == 'NONE' ]]; then
echo 'OK - No scheduled host maintenance'
exit 0
fi
echo 'UNKNOWN - Could not fetch maintenance event'
exit 3