This repository has been archived by the owner on Nov 18, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joshua Deare
committed
Sep 28, 2016
1 parent
982a5a2
commit 49ffc42
Showing
4 changed files
with
46 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
#!/usr/bin/env python | ||
|
||
from BaseHTTPServer import BaseHTTPRequestHandler | ||
import sys, yaml, socket | ||
import requests | ||
|
||
f = open(sys.argv[1], "r") | ||
config = yaml.load(f.read()) | ||
f.close() | ||
|
||
class StatusHandler(BaseHTTPRequestHandler): | ||
def do_GET(self): | ||
return self.do_ANY() | ||
def do_OPTIONS(self): | ||
return self.do_ANY() | ||
def do_ANY(self): | ||
base_url = "http://localhost:" + str(config["api_port"]) | ||
is_leader_resp = requests.get(base_url + "/ha/is_leader") | ||
running_as_leader_resp = requests.get( | ||
base_url + "/service/running_as_leader") | ||
is_healthy_resp = requests.get(base_url + "/service/is_healthy") | ||
if is_healthy_resp.json()["data"]["is_healthy"] and \ | ||
is_leader_resp.json()["data"]["is_leader"] and \ | ||
running_as_leader_resp.json()["data"]["running_as_leader"]: | ||
self.send_response(200) | ||
else: | ||
self.send_response(503) | ||
self.end_headers() | ||
self.wfile.write('\r\n') | ||
return | ||
|
||
try: | ||
from BaseHTTPServer import HTTPServer | ||
host, port = config["haproxy_status"]["listen"].split(":") | ||
server = HTTPServer((host, int(port)), StatusHandler) | ||
print 'listening on %s:%s' % (host, port) | ||
server.serve_forever() | ||
except KeyboardInterrupt: | ||
print('^C received, shutting down server') | ||
server.socket.close() |
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
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
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