api/alfred and router.html: Retrieve and show traffic control status

This only works for routers with updated nodewatcher.

This requires changes to the MySQL database!

Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
Adrian Schmutzler 2018-02-10 14:52:06 +01:00
parent 6188443dc9
commit 146d64da19
3 changed files with 23 additions and 8 deletions

View File

@ -76,6 +76,9 @@ mysql.execute("""
`w2_airtime` float DEFAULT NULL,
`w5_airtime` float DEFAULT NULL,
`wan_uplink` tinyint(1) NOT NULL,
`tc_enabled` tinyint(1) DEFAULT NULL,
`tc_in` float DEFAULT NULL,
`tc_out` float DEFAULT NULL,
`cpu` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`chipset` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
`hardware` varchar(200) COLLATE utf8_unicode_ci NOT NULL,

View File

@ -151,14 +151,16 @@ def import_nodewatcher_xml(mysql, mac, xml, banned, netifdict):
UPDATE router
SET status = %s, hostname = %s, last_contact = %s, sys_time = %s, sys_uptime = %s, sys_memfree = %s, sys_membuff = %s, sys_memcache = %s,
sys_loadavg = %s, sys_procrun = %s, sys_proctot = %s, clients = %s, clients_eth = %s, clients_w2 = %s, clients_w5 = %s,
w2_active = %s, w2_busy = %s, w5_active = %s, w5_busy = %s, w2_airtime = %s, w5_airtime = %s, wan_uplink = %s, cpu = %s, chipset = %s, hardware = %s, os = %s,
w2_active = %s, w2_busy = %s, w5_active = %s, w5_busy = %s, w2_airtime = %s, w5_airtime = %s, wan_uplink = %s, tc_enabled = %s, tc_in = %s, tc_out = %s,
cpu = %s, chipset = %s, hardware = %s, os = %s,
batman = %s, kernel = %s, nodewatcher = %s, firmware = %s, firmware_rev = %s, description = %s, position_comment = %s, community = %s, hood = %s, v2 = %s,
status_text = %s, contact = %s, lng = %s, lat = %s, neighbors = %s, reset = %s
WHERE id = %s
""",(
ru["status"],ru["hostname"],ru["last_contact"],ru["sys_time"],ru["sys_uptime"],ru["memory"]["free"],ru["memory"]["buffering"],ru["memory"]["caching"],
ru["sys_loadavg"],ru["processes"]["runnable"],ru["processes"]["total"],ru["clients"],ru["clients_eth"],ru["clients_w2"],ru["clients_w5"],
ru["w2_active"],ru["w2_busy"],ru["w5_active"],ru["w5_busy"],ru["w2_airtime"],ru["w5_airtime"],ru["has_wan_uplink"],ru["cpu"],ru["chipset"],ru["hardware"],ru["os"],
ru["w2_active"],ru["w2_busy"],ru["w5_active"],ru["w5_busy"],ru["w2_airtime"],ru["w5_airtime"],ru["has_wan_uplink"],ru["tc_enabled"],ru["tc_in"],ru["tc_out"],
ru["cpu"],ru["chipset"],ru["hardware"],ru["os"],
ru["batman_adv"],ru["kernel"],ru["nodewatcher"],ru["firmware"],ru["firmware_rev"],ru["description"],ru["position_comment"],ru["community"],ru["hood"],ru["v2"],
ru["status_text"],ru["contact"],ru["lng"],ru["lat"],ru["visible_neighbours"],reset,router_id,))
@ -207,14 +209,16 @@ def import_nodewatcher_xml(mysql, mac, xml, banned, netifdict):
mysql.execute("""
INSERT INTO router (status, hostname, created, last_contact, sys_time, sys_uptime, sys_memfree, sys_membuff, sys_memcache,
sys_loadavg, sys_procrun, sys_proctot, clients, clients_eth, clients_w2, clients_w5,
w2_active, w2_busy, w5_active, w5_busy, w2_airtime, w5_airtime, wan_uplink, cpu, chipset, hardware, os,
w2_active, w2_busy, w5_active, w5_busy, w2_airtime, w5_airtime, wan_uplink, tc_enabled, tc_in, tc_out,
cpu, chipset, hardware, os,
batman, kernel, nodewatcher, firmware, firmware_rev, description, position_comment, community, hood, v2,
status_text, contact, lng, lat, neighbors)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
""",(
ru["status"],ru["hostname"],created,ru["last_contact"],ru["sys_time"],ru["sys_uptime"],ru["memory"]["free"],ru["memory"]["buffering"],ru["memory"]["caching"],
ru["sys_loadavg"],ru["processes"]["runnable"],ru["processes"]["total"],ru["clients"],ru["clients_eth"],ru["clients_w2"],ru["clients_w5"],
None,None,None,None,None,None,ru["has_wan_uplink"],ru["cpu"],ru["chipset"],ru["hardware"],ru["os"],
None,None,None,None,None,None,ru["has_wan_uplink"],ru["tc_enabled"],ru["tc_in"],ru["tc_out"],
ru["cpu"],ru["chipset"],ru["hardware"],ru["os"],
ru["batman_adv"],ru["kernel"],ru["nodewatcher"],ru["firmware"],ru["firmware_rev"],ru["description"],ru["position_comment"],ru["community"],ru["hood"],ru["v2"],
ru["status_text"],ru["contact"],ru["lng"],ru["lat"],ru["visible_neighbours"],))
router_id = mysql.cursor().lastrowid
@ -642,13 +646,13 @@ def evalxpathint(tree,p,default=0):
tmp = int(tree.xpath(p)[0])
return tmp
def evalxpathbool(tree,p):
tmp = False
def evalxpathbool(tree,p,default=False):
tmp = default
with suppress(IndexError):
tmp = tree.xpath(p)[0]
if tmp:
return (tmp.lower()=="true" or tmp=="1")
return False
return default
def parse_nodewatcher_xml(xml):
try:
@ -700,6 +704,9 @@ def parse_nodewatcher_xml(xml):
or len(tree.xpath("/data/interface_data/%s" % CONFIG["vpn_netif"])) > 0
or len(tree.xpath("/data/interface_data/*[starts-with(name(), '%s')]" % CONFIG["vpn_netif_l2tp"])) > 0
or len(tree.xpath("/data/interface_data/%s" % CONFIG["vpn_netif_aux"])) > 0),
"tc_enabled": evalxpathbool(tree,"/data/traffic_control/wan/enabled/text()",None),
"tc_in": evalxpathfloat(tree,"/data/traffic_control/wan/in/text()",None),
"tc_out": evalxpathfloat(tree,"/data/traffic_control/wan/out/text()",None),
# software
"os": "%s (%s)" % (evalxpath(tree,"/data/system_data/distname/text()"),
evalxpath(tree,"/data/system_data/distversion/text()")),

View File

@ -165,6 +165,11 @@
<span style="color:#d90000"> &nbsp; - &nbsp; Router BLOCKED by KeyXchange!</span>
{%- endif -%}
</td></tr>
{%- if router.tc_enabled != None %}
<tr><th>Traffic control</th><td><span class="{{ "glyphicon glyphicon-ok" if router.tc_enabled else "glyphicon glyphicon-remove" }}"></span>
{%- if router.tc_enabled %} &nbsp; (up: {{ router.tc_out }} kBit/s, down: {{ router.tc_in }} kBit/s){%- endif -%}
</td></tr>
{%- endif -%}
<tr><th>Clients</th><td><span class="clientinfo">{{ router.clients }}</span>
{%- if router.clients_eth or router.clients_w2 or router.clients_w5 %}
&nbsp; (Ethernet: <span class="clientinfo">{{ router.clients_eth }}</span>{%- if router.clients_w2 != None %}, 2.4 GHz: <span class="clientinfo">{{ router.clients_w2 }}</span>{%- endif -%}{%- if router.clients_w5 != None %}, 5 GHz: <span class="clientinfo">{{ router.clients_w5 }}</span>{%- endif -%})