Skip to content

Instantly share code, notes, and snippets.

@jgamblin
Last active July 27, 2018 21:48
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jgamblin/83f7eb018d7953497e30802ed23e2041 to your computer and use it in GitHub Desktop.
Save jgamblin/83f7eb018d7953497e30802ed23e2041 to your computer and use it in GitHub Desktop.
Post Digital Ocean Droplets To Slack
#!/bin/bash
DIGITALOCEAN=(Get Key From https://cloud.digitalocean.com/settings/api/tokens)
SLACK=(Get Key From https://my.slack.com/services/new/bot)
rm do.txt
curl -sXGET "https://api.digitalocean.com/v2/droplets" \
-H "Authorization: Bearer $DIGITALOCEAN" \
-H "Content-Type: application/json" |\
python -c 'import sys,json;data=json.loads(sys.stdin.read());\
print "ID\tName\tIP\tPrice\n";\
print "\n".join(["%s\t%s\t%s\t$%s"%(d["id"],d["name"],d["networks"]["v4"][0]["ip_address"],d["size"]["price_monthly"])\
for d in data["droplets"]])'| column -t > do.txt
curl -F file=@do.txt -F initial_comment="Running Droplets" -F channels=#do -F token=$SLACK https://slack.com/api/files.upload
rm do.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment