aboutsummaryrefslogtreecommitdiffstats
path: root/monit.py
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2014-05-11 18:16:19 +0200
committerMatthias P. Braendli <matthias.braendli@mpb.li>2014-05-11 18:16:19 +0200
commit6525e843832e058cb3097fc4fbe0166071bb4136 (patch)
tree599ad459e2cf5c25a36378e4e418ca7a47c2c807 /monit.py
parent7513cf3dde274e945420e3e56fe4c66985f9f225 (diff)
downloadmmbtools-monit-6525e843832e058cb3097fc4fbe0166071bb4136.tar.gz
mmbtools-monit-6525e843832e058cb3097fc4fbe0166071bb4136.tar.bz2
mmbtools-monit-6525e843832e058cb3097fc4fbe0166071bb4136.zip
First version of monit tool
Diffstat (limited to 'monit.py')
-rwxr-xr-xmonit.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/monit.py b/monit.py
new file mode 100755
index 0000000..dd8adbe
--- /dev/null
+++ b/monit.py
@@ -0,0 +1,46 @@
+#!python
+import json
+import socket
+from datetime import datetime
+from flask import Flask
+from flask import render_template
+app = Flask(__name__)
+
+SOCK_RECV_SIZE = 10240
+
+def get_state():
+ """Create a connection to the dabmux stats server
+ and ask for the state
+
+ returns: state"""
+
+ sock = socket.socket()
+ sock.connect(("localhost", 12720))
+
+ version = json.loads(sock.recv(SOCK_RECV_SIZE))
+
+ if not version['service'].startswith("ODR-DabMux"):
+ return "Wrong version: '{}'\n".format(version['service'])
+
+ sock.send("state\n")
+ state_data = json.loads(sock.recv(SOCK_RECV_SIZE))
+ sock.close()
+
+ return state_data
+
+@app.route('/')
+def index_state():
+ state_json = get_state()
+
+ inputs = [{'name':name, 'state':state_json[name]['state']} for name in state_json]
+
+ now = str(datetime.now())
+
+ return render_template("index.html",
+ inputs=inputs,
+ name="test mux",
+ date=now)
+
+if __name__ == '__main__':
+ app.run(debug=True)
+