Add weechat session monitoring
This commit is contained in:
parent
b408cb8e9b
commit
d43e6174a2
5 changed files with 56 additions and 0 deletions
1
flask-monit/.gitignore
vendored
Normal file
1
flask-monit/.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
||||||
|
venv
|
40
flask-monit/monitor.py
Normal file
40
flask-monit/monitor.py
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
""" monitor
|
||||||
|
|
||||||
|
Monitor weechat sessions running and their relay availability """
|
||||||
|
|
||||||
|
import re
|
||||||
|
import subprocess
|
||||||
|
from flask import Flask, request
|
||||||
|
import settings
|
||||||
|
|
||||||
|
LOGGER_NAME = __name__
|
||||||
|
|
||||||
|
app = Flask(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/', methods=['GET'])
|
||||||
|
def home_view():
|
||||||
|
# We check whether weechat is running
|
||||||
|
url_regex = re.compile(
|
||||||
|
r'(?:https?://)?([^/:]*){}(?::[0-9]+)?/?'.format(
|
||||||
|
settings.URL_SUFFIX))
|
||||||
|
find_res = url_regex.match(request.base_url)
|
||||||
|
if find_res is None:
|
||||||
|
return 'Badly formed url\n', 400
|
||||||
|
user = find_res.group(1)
|
||||||
|
|
||||||
|
try:
|
||||||
|
output = subprocess.check_output(
|
||||||
|
['ps', '-u', user, '--format=cmd']).decode('utf-8')
|
||||||
|
lines = output.strip().split('\n')[1:]
|
||||||
|
for line in lines:
|
||||||
|
if line.strip() == settings.PS_COMMAND:
|
||||||
|
return 'OK\n', 200
|
||||||
|
except subprocess.CalledProcessError as exn:
|
||||||
|
return 'Internal error: {}\n'.format(exn), 500
|
||||||
|
return 'Weechat not running\n', 406
|
||||||
|
|
||||||
|
|
||||||
|
@app.before_first_request # FIXME this should be run on startup...
|
||||||
|
def startup_actions():
|
||||||
|
pass # Nothing needed for now
|
6
flask-monit/requirements.txt
Normal file
6
flask-monit/requirements.txt
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
click==6.7
|
||||||
|
Flask==1.0.2
|
||||||
|
itsdangerous==0.24
|
||||||
|
Jinja2==2.10
|
||||||
|
MarkupSafe==1.0
|
||||||
|
Werkzeug==0.14.1
|
4
flask-monit/settings.py
Normal file
4
flask-monit/settings.py
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
""" General-purpose settings """
|
||||||
|
|
||||||
|
PS_COMMAND = "weechat"
|
||||||
|
URL_SUFFIX = ".weechat.tobast.fr"
|
5
flask-monit/wsgi.py
Normal file
5
flask-monit/wsgi.py
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
sys.path.append(os.path.dirname(os.path.abspath(__file__)))
|
||||||
|
|
||||||
|
from monitor import app as application
|
Loading…
Reference in a new issue