Last active
October 20, 2016 01:09
-
-
Save lorentzca/fbd848527bb4892893dbd6ea32d5da23 to your computer and use it in GitHub Desktop.
サーバヒットポイントが0以下になったらシャットダウンする(見た目だけ)
This file contains 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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
see https://ghost.ponpokopon.me/enjoy-mackerel-metadata/