monitoring
This commit is contained in:
parent
cf5285e14a
commit
35f2394f5f
3 changed files with 59 additions and 1 deletions
9
check_git.sh
Executable file
9
check_git.sh
Executable file
|
@ -0,0 +1,9 @@
|
||||||
|
#!/bin/bash
|
||||||
|
|
||||||
|
if git diff-index --quiet HEAD --; then
|
||||||
|
# no change
|
||||||
|
exit 0
|
||||||
|
else
|
||||||
|
# change
|
||||||
|
exit 1
|
||||||
|
fi
|
48
monitor.py
Executable file
48
monitor.py
Executable file
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/env python
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import requests
|
||||||
|
import time
|
||||||
|
import json
|
||||||
|
|
||||||
|
def fread(filename):
|
||||||
|
"""Read file and close the file."""
|
||||||
|
with open(filename, "r") as f:
|
||||||
|
return f.read()
|
||||||
|
|
||||||
|
def get_nb_of_comments():
|
||||||
|
req_url = params["stacosys_url"] + "/comments/count"
|
||||||
|
query_params = dict(
|
||||||
|
token=params["stacosys_token"]
|
||||||
|
)
|
||||||
|
resp = requests.get(url=req_url, params=query_params)
|
||||||
|
return 0 if not resp.ok else int(resp.json()["count"])
|
||||||
|
|
||||||
|
def exit_program():
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
# Default parameters.
|
||||||
|
params = {
|
||||||
|
"stacosys_token": "",
|
||||||
|
"stacosys_url": "",
|
||||||
|
"external_check": "",
|
||||||
|
}
|
||||||
|
|
||||||
|
# If params.json exists, load it.
|
||||||
|
if os.path.isfile("params.json"):
|
||||||
|
params.update(json.loads(fread("params.json")))
|
||||||
|
|
||||||
|
external_check_cmd = params["external_check"]
|
||||||
|
initial_count = get_nb_of_comments()
|
||||||
|
print(f"Comments = {initial_count}")
|
||||||
|
while True:
|
||||||
|
# check number of comments every 60 seconds
|
||||||
|
for _ in range(15):
|
||||||
|
time.sleep(60)
|
||||||
|
if initial_count != get_nb_of_comments():
|
||||||
|
exit_program()
|
||||||
|
# check if git repo changed every 15 minutes
|
||||||
|
if external_check_cmd and os.system(external_check_cmd):
|
||||||
|
exit_program()
|
|
@ -4,5 +4,6 @@
|
||||||
"author": "Yax",
|
"author": "Yax",
|
||||||
"site_url": "https://blogduyax.madyanne.fr",
|
"site_url": "https://blogduyax.madyanne.fr",
|
||||||
"stacosys_token": "9fb3fc042c572cb831005fd16186126765140fa2bd9bb2d4a28e47a9457dc26c",
|
"stacosys_token": "9fb3fc042c572cb831005fd16186126765140fa2bd9bb2d4a28e47a9457dc26c",
|
||||||
"stacosys_url": "http://stacosys:8100"
|
"stacosys_url": "http://stacosys:8100",
|
||||||
|
"external_check": "./check_git.sh"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue