]> git.ipfire.org Git - ipfire.org.git/commitdiff
fireinfo: Show ASN map
authorMichael Tremer <michael.tremer@ipfire.org>
Sun, 7 Jan 2024 18:08:02 +0000 (18:08 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Sun, 7 Jan 2024 18:08:02 +0000 (18:08 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/backend/fireinfo.py
src/templates/fireinfo/admin.html
src/web/fireinfo.py

index 635cd08a80b7bd654ada908c6acffe9dfe8e863c..647e89d75978951288c8456237fbb5aa4d3ed60a 100644 (file)
@@ -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("""
index bc2676c011044355f7e24fa254cdf10bcb70da41..345d847d10ed6e6d6e3bebf903a2901706c63f0a 100644 (file)
                </div>
        </section>
 
+       {% if asn_map %}
+               <section class="section">
+                       <div class="container">
+                               <h4 class="title is-4">{{ _("Autonomous Systems") }}</h4>
+
+                               <table class="table is-fullwidth">
+                                       <tr>
+                                               <th>{{ _("Autonomous System") }}</th>
+                                               <th class="has-text-right">{{ _("Total Profiles") }}</th>
+                                               <th class="has-text-right">{{ _("Percentage") }}</th>
+                                       </tr>
+
+                                       {% for asn in sorted(asn_map, key=lambda asn: asn_map[asn], reverse=True) %}
+                                               {% set c, p = asn_map[asn] %}
+
+                                               <tr>
+                                                       <th scope="row">{{ asn }}</th>
+                                                       <td class="has-text-right">
+                                                               {{ c }}
+                                                       </td>
+                                                       <td class="has-text-right">
+                                                               {{ "%.2f%%" % (p * 100) }}
+                                                       </td>
+                                               </tr>
+                                       {% end %}
+                               </table>
+                       </div>
+               </section>
+       {% end %}
+
        {% if histogram %}
                <section class="section">
                        <div class="container">
index 78fe9e6b27d7efcf2163c363eb8f2f07f251c86a..0f11b7cb22cc62e0b02d4d0b03946490603c152a 100644 (file)
@@ -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)