Skip to content

Instantly share code, notes, and snippets.

@lorentzca
Last active October 20, 2016 01:09
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 lorentzca/fbd848527bb4892893dbd6ea32d5da23 to your computer and use it in GitHub Desktop.
Save lorentzca/fbd848527bb4892893dbd6ea32d5da23 to your computer and use it in GitHub Desktop.
サーバヒットポイントが0以下になったらシャットダウンする(見た目だけ)
#!/bin/bash
hp=$(curl -s -X GET \
-H "X-Api-Key: $MACKEREL_APIKEY" \
https://mackerel.io/api/v0/hosts/$MACKEREL_HOSTID/metadata/HP | jq -r .HP)
damage=$(expr $RANDOM % 500)
remaining_hp=$(expr $hp - $damage)
hostname=$1
echo HP is $hp
echo $damage damage!
echo remaining HP is $remaining_hp
if [ $remaining_hp -le 0 ]; then
echo
ssh $hostname 'echo $(hostname) is shutting down...'
curl -s -X PUT \
-H "X-Api-Key: $MACKEREL_APIKEY" \
-H "Content-Type:application/json" \
-d "{\"HP\": \"999\"}" \
https://mackerel.io/api/v0/hosts/$MACKEREL_HOSTID/metadata/HP > /dev/null
else
curl -s -X PUT \
-H "X-Api-Key: $MACKEREL_APIKEY" \
-H "Content-Type:application/json" \
-d "{\"HP\": \"$remaining_hp\"}" \
https://mackerel.io/api/v0/hosts/$MACKEREL_HOSTID/metadata/HP > /dev/null
fi
@lorentzca
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment