事前準備
slackのアプリケーションからIncomming Webhooksを作って Webhook URL
を取得
コード
today=$(date "+%Y%m%d")
month=$(date "+%Y%m")
slack_webhook_url="https://hooks.slack.com/services/*******/*******/*****************"
function slack_info () {
title=${1}
text=${2}
PAYLOAD=`cat << EOS
payload={
"username": "sushi",
"attachments": [{
"color": "#00FF00",
"title": "[INFO] ${today} ${title}",
"text": "${text}"
}],
"icon_emoji": ":sushi:"
}
EOS`
curl -X POST --data-urlencode "${PAYLOAD}" ${slack_webhook_url}
}
function slack_error () {
title=${1}
text=${2}
PAYLOAD=`cat << EOS
payload={
"username": "sushi",
"attachments": [{
"color": "#D00000",
"title": "[ERROR] ${today} ${title}",
"text": "${text}"
}],
"icon_emoji": ":sushi:"
}
EOS`
curl -X POST --data-urlencode "${PAYLOAD}" ${slack_webhook_url}
}