kopia lustrzana https://github.com/jbruce12000/kiln-controller
created watcher script, changed api endpt to /api/stats and get instead of post
rodzic
62c2d793aa
commit
8e5cf43167
|
@ -47,10 +47,18 @@ ovenWatcher = OvenWatcher(oven)
|
|||
def index():
|
||||
return bottle.redirect('/picoreflow/index.html')
|
||||
|
||||
@app.get('/api/stats')
|
||||
def handle_api():
|
||||
log.info("/api/stats command received")
|
||||
if hasattr(oven,'pid'):
|
||||
if hasattr(oven.pid,'pidstats'):
|
||||
return json.dumps(oven.pid.pidstats)
|
||||
|
||||
|
||||
@app.post('/api')
|
||||
def handle_api():
|
||||
log.info("/api is alive")
|
||||
log.info(bottle.request.json)
|
||||
|
||||
|
||||
# run a kiln schedule
|
||||
if bottle.request.json['cmd'] == 'run':
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
#!/usr/bin/env python
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
import datetime
|
||||
|
||||
# this monitors your kiln stats every N seconds
|
||||
# if X checks fail, an alert is sent to a slack channel
|
||||
# configure an incoming web hook on the slack channel
|
||||
# set slack_hook_url to that
|
||||
|
||||
def get_stats():
|
||||
try:
|
||||
r = requests.get(kiln_url)
|
||||
return r.json()
|
||||
except:
|
||||
return {}
|
||||
|
||||
def send_alert(msg):
|
||||
try:
|
||||
r = requests.post(slack_hook_url, json={'text': msg })
|
||||
except:
|
||||
pass
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
kiln_url = "http://0.0.0.0:8081/api/stats"
|
||||
slack_hook_url = "you must set this"
|
||||
|
||||
bad_check_limit = 6
|
||||
bad_checks = 0
|
||||
temp_error_limit = 10
|
||||
sleepfor = 10
|
||||
|
||||
while(True):
|
||||
stats = get_stats()
|
||||
|
||||
if 'time' not in stats:
|
||||
bad_checks = bad_checks + 1
|
||||
print("no data")
|
||||
if 'err' in stats:
|
||||
if abs(stats['err']) > temp_error_limit:
|
||||
bad_checks = bad_checks + 1
|
||||
print ("temp out of whack")
|
||||
if bad_checks >= bad_check_limit:
|
||||
print("ERR sending alert")
|
||||
msg = "error kiln needs help. %s" % stats
|
||||
send_alert(msg)
|
||||
bad_checks = 0
|
||||
else:
|
||||
print("OK %s" % datetime.datetime.now())
|
||||
|
||||
time.sleep(sleepfor)
|
||||
|
Ładowanie…
Reference in New Issue