From: Michael Tremer Date: Sun, 7 Jan 2024 18:08:02 +0000 (+0000) Subject: fireinfo: Show ASN map X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0450fa543216c376a7dad76f0f72e99a2332a8df;p=ipfire.org.git fireinfo: Show ASN map Signed-off-by: Michael Tremer --- diff --git a/src/backend/fireinfo.py b/src/backend/fireinfo.py index 635cd08a..647e89d7 100644 --- a/src/backend/fireinfo.py +++ b/src/backend/fireinfo.py @@ -1014,6 +1014,50 @@ class Fireinfo(Object): return { row.country_code : row.p for row in res } + def get_asn_map(self, when=None): + if when: + res = self.db.query(""" + SELECT + asn, + fireinfo_percentage( + COUNT(*), SUM(COUNT(*)) OVER () + ) AS p, + COUNT(*) AS c + FROM + fireinfo + WHERE + created_at <= %s + AND + ( + expired_at IS NULL + OR + expired_at > %s + ) + AND + asn IS NOT NULL + GROUP BY + asn + """, when, when) + else: + res = self.db.query(""" + SELECT + asn, + fireinfo_percentage( + COUNT(*), SUM(COUNT(*)) OVER () + ) AS p, + COUNT(*) AS c + FROM + fireinfo + WHERE + expired_at IS NULL + AND + asn IS NOT NULL + GROUP BY + asn + """) + + return { self.backend.location.get_as(row.asn) : (row.c, row.p) for row in res } + @property def cpu_vendors(self): res = self.db.query(""" diff --git a/src/templates/fireinfo/admin.html b/src/templates/fireinfo/admin.html index bc2676c0..345d847d 100644 --- a/src/templates/fireinfo/admin.html +++ b/src/templates/fireinfo/admin.html @@ -49,6 +49,36 @@ + {% if asn_map %} +
+
+

{{ _("Autonomous Systems") }}

+ + + + + + + + + {% for asn in sorted(asn_map, key=lambda asn: asn_map[asn], reverse=True) %} + {% set c, p = asn_map[asn] %} + + + + + + + {% end %} +
{{ _("Autonomous System") }}{{ _("Total Profiles") }}{{ _("Percentage") }}
{{ asn }} + {{ c }} + + {{ "%.2f%%" % (p * 100) }} +
+
+
+ {% end %} + {% if histogram %}
diff --git a/src/web/fireinfo.py b/src/web/fireinfo.py index 78fe9e6b..0f11b7cb 100644 --- a/src/web/fireinfo.py +++ b/src/web/fireinfo.py @@ -171,7 +171,11 @@ class AdminIndexHandler(BaseHandler): def get(self): with_data, total = self.backend.fireinfo.get_active_profiles() + # Fetch the ASN map + asn_map = self.backend.fireinfo.get_asn_map() + + # Fetch the histogram histogram = self.backend.fireinfo.get_profile_histogram() self.render("fireinfo/admin.html", with_data=with_data, total=total, - histogram=histogram) + asn_map=asn_map, histogram=histogram)