diff --git a/README.md b/README.md index 646e1a8..c30f45e 100644 --- a/README.md +++ b/README.md @@ -122,6 +122,39 @@ Example Pod Spec: value: "true" ``` +## Wechat Notifications + +Incoming WebHooks require that you set the WECHAT_URL and WECHAT_KEY environmental variables as part of your PodSpec. + +The URL should look something like: https://pushbear.ftqq.com/sub?key=3488-876437815599e06514b2bbc3864bc96a&text=SpotTermination&desp=SpotInstanceDetainInfo + +Wechat Setup: +* You get the WECHAT_KEY by [pushbear](http://pushbear.ftqq.com/admin/) +* You bind WECHAT_KEY to a QR code after you create a [Wechat Service account](https://mp.weixin.qq.com/?lang=en_US). +* API Docs: http://pushbear.ftqq.com/admin/ ; https://mp.weixin.qq.com/?lang=en_US + +Example Pod Spec: + +``` + env: + - name: POD_NAME + valueFrom: + fieldRef: + fieldPath: metadata.name + - name: NAMESPACE + valueFrom: + fieldRef: + fieldPath: metadata.namespace + - name: WECHAT_URL + value: "https://pushbear.ftqq.com/sub" + - name: WECHAT_KEY + value: "3488-876437815599e06514b2bbc3864bc96a" + - name: CLUSTER + value: development + - name: DETACH_ASG + value: "true" +``` + ## AutoScaling Detachment **This feature currently only supports simple autoscaling - no spot fleet or similar.** diff --git a/entrypoint.sh b/entrypoint.sh index 5dbfa93..d684de9 100755 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -128,6 +128,18 @@ if [ "${SEMATEXT_URL}" != "" ]; then curl -s -X POST --data "{\"message\":\"${MESSAGE}\",\"title\":\"Spot Termination ${CLUSTER_INFO}\",\"host\":\"${NODE_NAME}\",\"Instance\":\"${INSTANCE_ID}\",\"Instance Type\":\"${INSTANCE_TYPE}\", \"Availability Zone\":\"${AZ}\", \"type\":\"aws_spot_instance_terminated\"}" "${SEMATEXT_URL}" fi +# Notify Wechat incoming-webhook +# Docs: http://pushbear.ftqq.com/admin/#/api +# Setup: app +# +# You will have to set Wechat as an environment variable via PodSpec. +# The URL should look something like: +# - China: https://pushbear.ftqq.com/sub?key=3488-876437815599e06514b2bbc3864bc96a&text=SpotTermination&desp=SpotInstanceDetainInfo +if [ "${WECHAT_URL}" != "" ]; then + desp=`echo "$MESSAGE" | sed s/[[:space:]]//g` + curl -s "${WECHAT_URL}?key=${WECHAT_KEY}&text=SpotTermination&desp=${desp}" +fi + # Detach from autoscaling group, which will cause faster replacement # We do this in parallel with the drain (see the & at the end of the command). if [ "${DETACH_ASG}" != "false" ] && [ "${ASG_NAME}" != "" ]; then