Created
October 2, 2023 20:54
-
-
Save Clivern/f72a3fe35f426fb6ce95c055329493bd to your computer and use it in GitHub Desktop.
Live status
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
import socket | |
import os | |
import json | |
try: | |
os.remove("/tmp/livestatus.sock") | |
except OSError: | |
pass | |
s = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | |
s.bind("/tmp/livestatus.sock") | |
s.listen() | |
while True: | |
conn, addr = s.accept() | |
request = conn.recv(1024) | |
print("Incoming Request: {}".format(request.decode())) | |
if request.decode() == "GET /hosts": | |
response = json.dumps({ | |
"hosts": [ | |
{"id": 1, "name": "ams1.dy"}, | |
{"id": 2, "name": "ams1.dp"} | |
] | |
}) | |
conn.sendall(response.encode()) | |
conn.close() | |
else: | |
response = json.dumps({ | |
"errorMessage": "Invalid request!" | |
}) | |
conn.sendall(response.encode()) | |
conn.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
client.py