Created
April 10, 2019 06:54
-
-
Save latenssi/d204654567f94efc499f45534ae1091d to your computer and use it in GitHub Desktop.
Generate healthchecks
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
from __future__ import print_function | |
import os | |
import json | |
try: | |
from urllib.request import Request, urlopen # Python 3 | |
except ImportError: | |
from urllib2 import Request, urlopen # Python 2 | |
req = Request(os.getenv("HC_API_URL", "")) | |
req.add_header('X-Api-Key', os.getenv("HC_API_KEY", "")) | |
checks = [ | |
{"name": c["name"], "url":c["ping_url"]} | |
for c in json.load(urlopen(req))["checks"] | |
] | |
def generateCmd(name, url): | |
str = 'if [ -z `sudo docker ps -q --no-trunc | grep $(sudo docker-compose ps -q {name})` ]; ' | |
str += 'then curl -fsS --retry 3 {url}/fail; ' | |
str += 'else curl -fsS --retry 3 {url}; ' | |
str += 'fi' | |
return str.format(name=name, url=url) | |
cmds = [generateCmd(c["name"], c["url"]) for c in checks] | |
print("\n".join(cmds)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment