update
This commit is contained in:
parent
d3c24b3362
commit
d9b437d40d
24
ajaxmonit.py
24
ajaxmonit.py
|
@ -29,11 +29,6 @@ payload['md5_pass'] = hexdigest
|
||||||
|
|
||||||
r = requests.post('http://192.168.1.1/index.cgi', data=payload, cookies=cookies)
|
r = requests.post('http://192.168.1.1/index.cgi', data=payload, cookies=cookies)
|
||||||
|
|
||||||
cnx = mysql.connector.connect(user='root', password='',
|
|
||||||
host='127.0.0.1',
|
|
||||||
database='monit')
|
|
||||||
cursor = cnx.cursor()
|
|
||||||
|
|
||||||
payload = {
|
payload = {
|
||||||
'cable_settings': 1,
|
'cable_settings': 1,
|
||||||
'active_page': 'page_cable_settings',
|
'active_page': 'page_cable_settings',
|
||||||
|
@ -56,6 +51,15 @@ while True:
|
||||||
rts = datetime.strptime(r.headers['Date'], '%a, %d %b %Y %H:%M:%S GMT')
|
rts = datetime.strptime(r.headers['Date'], '%a, %d %b %Y %H:%M:%S GMT')
|
||||||
uts = rts.strftime('%Y-%m-%d %H:%M:%S')
|
uts = rts.strftime('%Y-%m-%d %H:%M:%S')
|
||||||
|
|
||||||
|
print(uts, "Got page")
|
||||||
|
|
||||||
|
cnx = mysql.connector.connect(user='root', password='',
|
||||||
|
host='127.0.0.1',
|
||||||
|
database='monit')
|
||||||
|
cursor = cnx.cursor()
|
||||||
|
|
||||||
|
print(uts, "Connected to DB")
|
||||||
|
|
||||||
for x in range(0, 8):
|
for x in range(0, 8):
|
||||||
channel = {}
|
channel = {}
|
||||||
for f in fields['download']:
|
for f in fields['download']:
|
||||||
|
@ -63,7 +67,8 @@ while True:
|
||||||
if matches:
|
if matches:
|
||||||
channel[f] = matches.group(3).replace(' dBmV', '').replace(' dB', '').replace(' MHz', '')
|
channel[f] = matches.group(3).replace(' dBmV', '').replace(' dB', '').replace(' MHz', '')
|
||||||
try:
|
try:
|
||||||
print(uts, 0, x, channel['freq_val_dn'], channel['power_val_dn'], channel['snr_val_dn'])
|
#print(uts, 0, x, channel['freq_val_dn'], channel['power_val_dn'], channel['snr_val_dn'])
|
||||||
|
print(uts, "Inserting downstream to DB")
|
||||||
cursor.execute(add_ajax, (uts, 0, x, channel['freq_val_dn'], channel['power_val_dn'], channel['snr_val_dn']))
|
cursor.execute(add_ajax, (uts, 0, x, channel['freq_val_dn'], channel['power_val_dn'], channel['snr_val_dn']))
|
||||||
except (mysql.connector.IntegrityError, KeyError) as err:
|
except (mysql.connector.IntegrityError, KeyError) as err:
|
||||||
pass
|
pass
|
||||||
|
@ -75,10 +80,15 @@ while True:
|
||||||
if matches:
|
if matches:
|
||||||
channel[f] = matches.group(3).replace(' dBmV', '').replace(' MHz', '')
|
channel[f] = matches.group(3).replace(' dBmV', '').replace(' MHz', '')
|
||||||
try:
|
try:
|
||||||
print(uts, 1, channel['cannel_id_val_up'], channel['freq_val_up'], channel['power_val_up'])
|
#print(uts, 1, channel['cannel_id_val_up'], channel['freq_val_up'], channel['power_val_up'])
|
||||||
|
print(uts, "Inserting upstream to DB")
|
||||||
cursor.execute(add_ajax, (uts, 1, channel['cannel_id_val_up'], channel['freq_val_up'], channel['power_val_up'], None))
|
cursor.execute(add_ajax, (uts, 1, channel['cannel_id_val_up'], channel['freq_val_up'], channel['power_val_up'], None))
|
||||||
except (mysql.connector.IntegrityError, KeyError) as err:
|
except (mysql.connector.IntegrityError, KeyError) as err:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
cursor.close()
|
||||||
cnx.commit()
|
cnx.commit()
|
||||||
|
cnx.close()
|
||||||
|
print(uts, "DB connection closed")
|
||||||
|
print(uts, "Sleeping")
|
||||||
time.sleep(30)
|
time.sleep(30)
|
15
web.py
15
web.py
|
@ -7,9 +7,10 @@ import mysql.connector
|
||||||
import copy
|
import copy
|
||||||
|
|
||||||
app = Flask(__name__)
|
app = Flask(__name__)
|
||||||
cnx = mysql.connector.connect(user='root', password='',
|
|
||||||
host='127.0.0.1',
|
def dbconnect():
|
||||||
database='monit')
|
return mysql.connector.connect(user='root', password='',
|
||||||
|
host='127.0.0.1', database='monit')
|
||||||
|
|
||||||
@app.route('/')
|
@app.route('/')
|
||||||
def graph():
|
def graph():
|
||||||
|
@ -37,6 +38,8 @@ def downstream(name=None):
|
||||||
|
|
||||||
output = {'data': [], 'layout': {'title': title}}
|
output = {'data': [], 'layout': {'title': title}}
|
||||||
template = {'x': [], 'y': [], 'type': 'lines', 'name': '', 'uid': ''}
|
template = {'x': [], 'y': [], 'type': 'lines', 'name': '', 'uid': ''}
|
||||||
|
|
||||||
|
cnx = dbconnect()
|
||||||
cursor = cnx.cursor()
|
cursor = cnx.cursor()
|
||||||
|
|
||||||
for x in range(0, 8):
|
for x in range(0, 8):
|
||||||
|
@ -53,7 +56,7 @@ def downstream(name=None):
|
||||||
output['data'].append(recetor)
|
output['data'].append(recetor)
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
cnx.commit()
|
cnx.close()
|
||||||
|
|
||||||
return jsonify(output)
|
return jsonify(output)
|
||||||
|
|
||||||
|
@ -69,6 +72,8 @@ def upstream(name=None):
|
||||||
|
|
||||||
output = {'data': [], 'layout': {'title': title}}
|
output = {'data': [], 'layout': {'title': title}}
|
||||||
template = {'x': [], 'y': [], 'type': 'lines', 'name': '', 'uid': '', 'line': {'smoothing': 0.85}}
|
template = {'x': [], 'y': [], 'type': 'lines', 'name': '', 'uid': '', 'line': {'smoothing': 0.85}}
|
||||||
|
|
||||||
|
cnx = dbconnect()
|
||||||
cursor = cnx.cursor()
|
cursor = cnx.cursor()
|
||||||
|
|
||||||
for x in range(9, 11):
|
for x in range(9, 11):
|
||||||
|
@ -85,6 +90,6 @@ def upstream(name=None):
|
||||||
output['data'].append(recetor)
|
output['data'].append(recetor)
|
||||||
|
|
||||||
cursor.close()
|
cursor.close()
|
||||||
cnx.commit()
|
cnx.close()
|
||||||
|
|
||||||
return jsonify(output)
|
return jsonify(output)
|
Loading…
Reference in New Issue