Skip to content

Commit

Permalink
Merge pull request #38 from DasyDong/add-wechat-notice
Browse files Browse the repository at this point in the history
Support wechat notification
  • Loading branch information
egeland authored Jan 10, 2020
2 parents 8eeeefa + e449177 commit 601fec5
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.**
Expand Down
12 changes: 12 additions & 0 deletions entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 601fec5

Please sign in to comment.