Skip to content

Instantly share code, notes, and snippets.

@tatsuru
Forked from i2tsuki/awsevent2gcal
Last active May 25, 2018 04:12
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tatsuru/dcf7edf3ebed6afff38765bb9875f930 to your computer and use it in GitHub Desktop.
Save tatsuru/dcf7edf3ebed6afff38765bb9875f930 to your computer and use it in GitHub Desktop.
AWS のイベントを calendar に登録するくん
#!/bin/sh
set -eux
PROFILE="default"
RESP="$(aws --profile ${PROFILE} --region "us-east-1" health describe-events --query 'events[?eventTypeCategory==`scheduledChange` && statusCode == `upcoming`]')"
LENGTH="$(echo ${RESP} | jq 'length')"
for i in $(seq 0 $(($LENGTH-1)))
do
START_TIME=$(echo ${RESP} | jq -r ".[${i}].startTime")
END_TIME=$(echo ${RESP} | jq -r ".[${i}].endTime")
DURATION=$(echo $(( (${END_TIME} - ${START_TIME})/60 )))
if [ $DURATION -lt 60 ] ; then
DURATION=60
fi
START_TIME=$(date -d "@${START_TIME}" +"%Y-%m-%d %H:%M")
END_TIME=$(date -d "@${END_TIME}" +"%Y-%m-%d %H:%M")
EVENT_NAME=$(echo ${RESP} | jq -r ".[${i}].eventTypeCode")
ARN=$(echo ${RESP} | jq -r ".[${i}].arn")
gcalcli add --calendar 'システムプラットフォーム部' --title "【AWS Event】${EVENT_NAME}" --where "" --when "${START_TIME}" --duration "${DURATION}" --description "https://phd.aws.amazon.com/phd/home#/event-log?eventID=${ARN}" --reminder "0m"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment