Introduced orphaned state between offline and deletion
After 7 days of being offline, a router enters the orphaned state with a grey icon. It is only deleted after a longer period of 180 days. Signed-off-by: Adrian Schmutzler <freifunk@adrianschmutzler.de>
This commit is contained in:
parent
6f61cc6fdc
commit
3fd731a5a2
|
@ -17,6 +17,10 @@
|
|||
<Filter>([status] = 'unknown')</Filter>
|
||||
<PointSymbolizer file="static/img/router_yellow.svg" allow-overlap="true" />
|
||||
</Rule>
|
||||
<Rule>
|
||||
<Filter>([status] = 'orphaned')</Filter>
|
||||
<PointSymbolizer file="static/img/router_grey.svg" allow-overlap="true" />
|
||||
</Rule>
|
||||
</Style>
|
||||
<Style name="color" filter-mode="first">
|
||||
<Rule>
|
||||
|
|
|
@ -18,7 +18,8 @@ CONFIG = {
|
|||
"vpn_netif_l2tp": "l2tp",
|
||||
"vpn_netif_aux": "fffauxVPN",
|
||||
"offline_threshold_minutes": 20,
|
||||
"orphan_threshold_days": 120,
|
||||
"orphan_threshold_days": 7,
|
||||
"delete_threshold_days": 180,
|
||||
"router_stat_days": 7,
|
||||
"event_num_entries": 20,
|
||||
}
|
||||
|
@ -232,13 +233,15 @@ def import_nodewatcher_xml(mysql, mac, xml):
|
|||
#events.append(event)
|
||||
|
||||
def detect_offline_routers(mysql):
|
||||
# Offline after X minutes (online -> offline)
|
||||
|
||||
threshold=mysql.formatdt(utcnow() - datetime.timedelta(minutes=CONFIG["offline_threshold_minutes"]))
|
||||
now=mysql.utcnow()
|
||||
|
||||
result = mysql.fetchall("""
|
||||
SELECT id
|
||||
FROM router
|
||||
WHERE last_contact < %s AND status <> 'offline'
|
||||
WHERE last_contact < %s AND status <> 'offline' AND status <> 'orphaned'
|
||||
""",(threshold,))
|
||||
|
||||
rdata = []
|
||||
|
@ -252,12 +255,26 @@ def detect_offline_routers(mysql):
|
|||
mysql.execute("""
|
||||
UPDATE router
|
||||
SET status = 'offline', clients = 0
|
||||
WHERE last_contact < %s AND status <> 'offline'
|
||||
WHERE last_contact < %s AND status <> 'offline' AND status <> 'orphaned'
|
||||
""",(threshold,))
|
||||
mysql.commit()
|
||||
|
||||
def detect_orphaned_routers(mysql):
|
||||
# Orphan after X days (offline -> orphaned)
|
||||
|
||||
threshold=mysql.formatdt(utcnow() - datetime.timedelta(days=CONFIG["orphan_threshold_days"]))
|
||||
|
||||
mysql.execute("""
|
||||
UPDATE router
|
||||
SET status = 'orphaned'
|
||||
WHERE last_contact < %s AND status = 'offline'
|
||||
""",(threshold,))
|
||||
mysql.commit()
|
||||
|
||||
def delete_orphaned_routers(mysql):
|
||||
threshold=mysql.formatdt(utcnow() - datetime.timedelta(days=CONFIG["orphan_threshold_days"]))
|
||||
# Deleted after X days (orphaned -> deletion)
|
||||
|
||||
threshold=mysql.formatdt(utcnow() - datetime.timedelta(days=CONFIG["delete_threshold_days"]))
|
||||
|
||||
mysql.execute("""
|
||||
DELETE r, e, i, nb, net FROM router AS r
|
||||
|
|
|
@ -26,18 +26,20 @@ def total_clients(mysql,selecthood=None):
|
|||
|
||||
def router_status(mysql,selecthood=None):
|
||||
if selecthood:
|
||||
return mysql.fetchdict("""
|
||||
tmp = mysql.fetchdict("""
|
||||
SELECT status, COUNT(id) AS count
|
||||
FROM router
|
||||
WHERE hood = %s
|
||||
GROUP BY status
|
||||
""",(selecthood,),"status","count")
|
||||
else:
|
||||
return mysql.fetchdict("""
|
||||
tmp = mysql.fetchdict("""
|
||||
SELECT status, COUNT(id) AS count
|
||||
FROM router
|
||||
GROUP BY status
|
||||
""",(),"status","count")
|
||||
tmp["sum"] = sum(tmp.values())
|
||||
return tmp
|
||||
|
||||
def total_clients_hood(mysql):
|
||||
return mysql.fetchdict("""
|
||||
|
|
|
@ -95,6 +95,7 @@ def alfred():
|
|||
mysql.commit()
|
||||
r.headers['X-API-STATUS'] = "ALFRED data imported"
|
||||
#detect_offline_routers(mysql)
|
||||
#detect_orphaned_routers(mysql)
|
||||
#delete_orphaned_routers(mysql)
|
||||
#delete_old_stats(mysql)
|
||||
#record_global_stats(mysql)
|
||||
|
|
|
@ -143,6 +143,7 @@ def status2css(status):
|
|||
"created": "primary",
|
||||
"netmon": "primary",
|
||||
"update": "primary",
|
||||
"orphaned": "default",
|
||||
}
|
||||
return "label label-%s" % status_map.get(status, "default")
|
||||
|
||||
|
|
|
@ -0,0 +1,71 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
xmlns:dc="http://purl.org/dc/elements/1.1/"
|
||||
xmlns:cc="http://creativecommons.org/ns#"
|
||||
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
|
||||
xmlns:svg="http://www.w3.org/2000/svg"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 14 14"
|
||||
id="svg4142"
|
||||
version="1.1"
|
||||
inkscape:version="0.91 r13725"
|
||||
sodipodi:docname="router_grey.svg">
|
||||
<defs
|
||||
id="defs4144" />
|
||||
<sodipodi:namedview
|
||||
id="base"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#666666"
|
||||
borderopacity="1.0"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pageshadow="2"
|
||||
inkscape:zoom="22.627417"
|
||||
inkscape:cx="3.7021802"
|
||||
inkscape:cy="7.5625001"
|
||||
inkscape:document-units="px"
|
||||
inkscape:current-layer="layer1"
|
||||
showgrid="false"
|
||||
units="px"
|
||||
inkscape:window-width="1436"
|
||||
inkscape:window-height="858"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="19"
|
||||
inkscape:window-maximized="1"
|
||||
width="14in" />
|
||||
<metadata
|
||||
id="metadata4147">
|
||||
<rdf:RDF>
|
||||
<cc:Work
|
||||
rdf:about="">
|
||||
<dc:format>image/svg+xml</dc:format>
|
||||
<dc:type
|
||||
rdf:resource="http://purl.org/dc/dcmitype/StillImage" />
|
||||
<dc:title />
|
||||
</cc:Work>
|
||||
</rdf:RDF>
|
||||
</metadata>
|
||||
<g
|
||||
inkscape:label="Ebene 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1"
|
||||
transform="translate(0,-1038.3621)">
|
||||
<circle
|
||||
style="fill:#999999;fill-opacity:1"
|
||||
id="path4690"
|
||||
cx="7"
|
||||
cy="1045.3621"
|
||||
r="6.6121397" />
|
||||
<circle
|
||||
style="fill:#000000;fill-opacity:1"
|
||||
id="path4134"
|
||||
cx="7"
|
||||
cy="1045.3621"
|
||||
r="2.0780513" />
|
||||
</g>
|
||||
</svg>
|
After Width: | Height: | Size: 1.9 KiB |
|
@ -77,7 +77,7 @@
|
|||
<td class="success">{{ router_status.online or 0 }}</td>
|
||||
<td class="danger">{{ router_status.offline or 0 }}</td>
|
||||
<td class="warning">{{ router_status.unknown or 0 }}</td>
|
||||
<td class="active">{{ (router_status.online or 0) + (router_status.offline or 0) + (router_status.unknown or 0) }}</td>
|
||||
<td class="active">{{ router_status.sum or 0 }}</td>
|
||||
<td class="info">{{ clients }}</td>
|
||||
<td class="stats"><a href="{{ url_for('global_statistics') }}">Global</a></td>
|
||||
</tr>
|
||||
|
|
|
@ -16,6 +16,7 @@ start_time = time.time()
|
|||
|
||||
mysql = FreifunkMySQL()
|
||||
detect_offline_routers(mysql)
|
||||
detect_orphaned_routers(mysql)
|
||||
delete_orphaned_routers(mysql)
|
||||
#delete_old_stats(mysql) # Only execute once daily, takes 2 minutes
|
||||
record_global_stats(mysql)
|
||||
|
|
Loading…
Reference in New Issue