Created
March 19, 2016 10:33
-
-
Save ueki-kazuki/1aef18aa201c386f27de to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
export TZ="Asia/Tokyo" | |
CHATWORK_API_KEY="YOUR_CHATWORK_API_KEY" | |
CHATWORK_URL="https://api.chatwork.com/v1" | |
CHATWORK_TOKEN_KEY="X-ChatWorkToken" | |
CHATWORK_ROOM_ID="ROOM_ID_TO_POST" | |
link="http://status.aws.amazon.com/" | |
function proc { | |
entries_json=$(curl -s $link/data.json | jq '.archive | map(select(now - (.date|tonumber) < 5*60))') | |
len=$(echo $entries_json | jq 'length') | |
echo " $len entries" | |
if [ $len -gt 0 ] | |
then | |
for i in $( seq 0 $(($len - 1)) ) | |
do | |
entry=$(echo $entries_json | jq ".[$i]") | |
service=$(echo $entry | jq -r '.service_name') | |
title=$(echo $entry | jq -r '.summary') | |
date=$(echo $entry | jq '.date | tonumber') | |
content=$(echo $entry | jq -r '.description') | |
localtime=$(echo "${date}" | jq -r '. + 9 * 60 * 60|strftime("%Y-%m-%d %H:%M:%S %Z")') | |
ue_content=$(echo "${content}" | ruby -r cgi -e 'puts CGI.unescapeHTML($stdin.gets)') | |
ue_content=$(echo "${ue_content}" | sed 's/ / /g') | |
ue_content=$(echo "${ue_content}" | sed -e 's,<div>,[info],g' -e 's,</div>,[/info],g') | |
ue_content=$(echo "${ue_content}" | sed -e 's/<[^>]*>//g') | |
_body=$(echo -e "${localtime}\n${ue_content}\n${link}") | |
echo "${_body}" | |
curl -s -X POST -H "${CHATWORK_TOKEN_KEY}:${CHATWORK_API_KEY}" -d "body=[info][title][AWS障害] ${title} (${service})[/title]${_body}[/info]" "${CHATWORK_URL}/rooms/${CHATWORK_ROOM_ID}/messages" | |
echo | |
done | |
fi | |
} | |
proc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment