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:
parent
6188443dc9
commit
146d64da19
|
@ -76,6 +76,9 @@ mysql.execute("""
|
||||||
`w2_airtime` float DEFAULT NULL,
|
`w2_airtime` float DEFAULT NULL,
|
||||||
`w5_airtime` float DEFAULT NULL,
|
`w5_airtime` float DEFAULT NULL,
|
||||||
`wan_uplink` tinyint(1) NOT 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,
|
`cpu` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
|
||||||
`chipset` 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,
|
`hardware` varchar(200) COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
|
|
@ -151,14 +151,16 @@ def import_nodewatcher_xml(mysql, mac, xml, banned, netifdict):
|
||||||
UPDATE router
|
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,
|
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,
|
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,
|
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
|
status_text = %s, contact = %s, lng = %s, lat = %s, neighbors = %s, reset = %s
|
||||||
WHERE id = %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["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["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["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,))
|
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("""
|
mysql.execute("""
|
||||||
INSERT INTO router (status, hostname, created, last_contact, sys_time, sys_uptime, sys_memfree, sys_membuff, sys_memcache,
|
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,
|
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,
|
batman, kernel, nodewatcher, firmware, firmware_rev, description, position_comment, community, hood, v2,
|
||||||
status_text, contact, lng, lat, neighbors)
|
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["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"],
|
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["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"],))
|
ru["status_text"],ru["contact"],ru["lng"],ru["lat"],ru["visible_neighbours"],))
|
||||||
router_id = mysql.cursor().lastrowid
|
router_id = mysql.cursor().lastrowid
|
||||||
|
@ -642,13 +646,13 @@ def evalxpathint(tree,p,default=0):
|
||||||
tmp = int(tree.xpath(p)[0])
|
tmp = int(tree.xpath(p)[0])
|
||||||
return tmp
|
return tmp
|
||||||
|
|
||||||
def evalxpathbool(tree,p):
|
def evalxpathbool(tree,p,default=False):
|
||||||
tmp = False
|
tmp = default
|
||||||
with suppress(IndexError):
|
with suppress(IndexError):
|
||||||
tmp = tree.xpath(p)[0]
|
tmp = tree.xpath(p)[0]
|
||||||
if tmp:
|
if tmp:
|
||||||
return (tmp.lower()=="true" or tmp=="1")
|
return (tmp.lower()=="true" or tmp=="1")
|
||||||
return False
|
return default
|
||||||
|
|
||||||
def parse_nodewatcher_xml(xml):
|
def parse_nodewatcher_xml(xml):
|
||||||
try:
|
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/%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/*[starts-with(name(), '%s')]" % CONFIG["vpn_netif_l2tp"])) > 0
|
||||||
or len(tree.xpath("/data/interface_data/%s" % CONFIG["vpn_netif_aux"])) > 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
|
# software
|
||||||
"os": "%s (%s)" % (evalxpath(tree,"/data/system_data/distname/text()"),
|
"os": "%s (%s)" % (evalxpath(tree,"/data/system_data/distname/text()"),
|
||||||
evalxpath(tree,"/data/system_data/distversion/text()")),
|
evalxpath(tree,"/data/system_data/distversion/text()")),
|
||||||
|
|
|
@ -165,6 +165,11 @@
|
||||||
<span style="color:#d90000"> - Router BLOCKED by KeyXchange!</span>
|
<span style="color:#d90000"> - Router BLOCKED by KeyXchange!</span>
|
||||||
{%- endif -%}
|
{%- endif -%}
|
||||||
</td></tr>
|
</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 %} (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>
|
<tr><th>Clients</th><td><span class="clientinfo">{{ router.clients }}</span>
|
||||||
{%- if router.clients_eth or router.clients_w2 or router.clients_w5 %}
|
{%- if router.clients_eth or router.clients_w2 or router.clients_w5 %}
|
||||||
(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 -%})
|
(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 -%})
|
||||||
|
|
Loading…
Reference in New Issue