]> git.ipfire.org Git - pbs.git/commitdiff
monitorings: Implement controls to force check
authorMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 May 2023 13:11:45 +0000 (13:11 +0000)
committerMichael Tremer <michael.tremer@ipfire.org>
Tue, 23 May 2023 13:11:45 +0000 (13:11 +0000)
Signed-off-by: Michael Tremer <michael.tremer@ipfire.org>
src/templates/monitorings/show.html
src/web/__init__.py
src/web/monitorings.py

index f44f152be1533b0ccc95224d5c431eebfc83d788..50449c27189a24542b62cbcb085e8faa9186c88d 100644 (file)
                <section class="section">
                        <div class="container">
                                <div class="buttons">
-                                       <a class="button is-light" href="{{ monitoring.url }}/check">
+                                       <form id="check" method="POST" action="{{ monitoring.url }}/check">
+                                               {% raw xsrf_form_html() %}
+                                       </form>
+
+                                       <button class="button is-light" type="submit" form="check">
                                                {{ _("Check Now") }}
-                                       </a>
+                                       </button>
 
                                        <a class="button is-warning" href="{{ monitoring.url }}/edit">
                                                {{ _("Edit") }}
index 11a6a1231533f15a15fbceaf3e32870144248993..1dba2b1afe46ecf50a997c774c325d79a7d48ef9 100644 (file)
@@ -204,6 +204,7 @@ class Application(tornado.web.Application):
 
                        # Distro Monitorings
                        (r"/distros/([A-Za-z0-9\-\.]+)/monitorings/([\w\-_]+)", monitorings.ShowHandler),
+                       (r"/distros/([A-Za-z0-9\-\.]+)/monitorings/([\w\-_]+)/check", monitorings.CheckHandler),
 
                        # Mirrors
                        (r"/mirrors",                                    mirrors.IndexHandler),
index 68b5bc407c05d64514b9d7b2721607f57974809e..570192de695d1b8a2caab776bae8ac79c3f917de 100644 (file)
@@ -38,6 +38,26 @@ class ShowHandler(base.BaseHandler):
                self.render("monitorings/show.html", monitoring=monitoring)
 
 
+class CheckHandler(base.BaseHandler):
+       async def post(self, slug, name):
+               # Fetch the distribution
+               distro = self.backend.distros.get_by_slug(slug)
+               if not distro:
+                       raise tornado.web.HTTPError(404, "Could not find distro %s" % slug)
+
+               # Fetch the monitoring
+               monitoring = self.backend.monitorings.get_by_distro_and_name(distro, name)
+               if not monitoring:
+                       raise tornado.web.HTTPError(404, "Could not find monitoring for %s in %s" % (name, distro))
+
+               # Perform check
+               with self.db.transaction():
+                       await monitoring.check()
+
+               # Redirect back
+               self.redirect(monitoring.url)
+
+
 class ReleasesListModule(ui_modules.UIModule):
        def render(self, releases, show_empty=True):
                return self.render_string("monitorings/modules/releases-list.html",