all lists on lists.proxmox.com
 help / color / mirror / Atom feed
From: Hannes Laimer <h.laimer@proxmox.com>
To: pmg-devel@lists.proxmox.com
Subject: [pmg-devel] [PATCH pmg-api v2] fix #2452: pmgqm support 1-24h timespans for status/send
Date: Fri,  8 Aug 2025 12:28:36 +0200	[thread overview]
Message-ID: <20250808102836.50441-1-h.laimer@proxmox.com> (raw)

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
I didn't find a section for this in the docs(maybe I missed it), if
there is one, and depending on what it says maybe we have to update that
as well. (I can send a followup in that case)

since v1:
 - update default templates
 - 1..24h instead of 1..23h (thought `today` would be 24h, but it's not)

 src/PMG/CLI/pmgqm.pm                |  8 ++++----
 src/PMG/Utils.pm                    | 10 ++++++++--
 src/templates/spamreport-short.tt   |  4 +++-
 src/templates/spamreport-verbose.tt |  4 +++-
 4 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/src/PMG/CLI/pmgqm.pm b/src/PMG/CLI/pmgqm.pm
index 23968f2..41f9f1a 100755
--- a/src/PMG/CLI/pmgqm.pm
+++ b/src/PMG/CLI/pmgqm.pm
@@ -90,9 +90,9 @@ __PACKAGE__->register_method({
         additionalProperties => 0,
         properties => {
             timespan => {
-                description => "Select time span.",
+                description => "Select time span. Accepts 'today', 'yesterday', 'week' or '1h'..'24h' for the last N hours.",
                 type => 'string',
-                enum => ['today', 'yesterday', 'week'],
+                pattern => '^(today|yesterday|week|([1-9]|1[0-9]|2[0-4])h)$',
                 default => 'today',
                 optional => 1,
             },
@@ -167,9 +167,9 @@ __PACKAGE__->register_method({
                 },
             ),
             timespan => {
-                description => "Select time span.",
+                description => "Select time span. Accepts 'today', 'yesterday', 'week' or '1h'..'24h' for the last N hours.",
                 type => 'string',
-                enum => ['today', 'yesterday', 'week'],
+                pattern => '^(today|yesterday|week|([1-9]|1[0-9]|2[0-4])h)$',
                 default => 'today',
                 optional => 1,
             },
diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index 890096f..ddfa732 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -1392,13 +1392,19 @@ sub finalize_report {
 sub lookup_timespan {
     my ($timespan) = @_;
 
-    my (undef, undef, undef, $mday, $mon, $year) = localtime(time());
+    my $now = time();
+    my (undef, undef, undef, $mday, $mon, $year) = localtime($now);
     my $daystart = timelocal(0, 0, 0, $mday, $mon, $year);
 
     my $start;
     my $end;
 
-    if ($timespan eq 'today') {
+    if ($timespan =~ m/^(\d{1,2})h$/) {
+        my $hours = int($1);
+        die "invalid hour timespan '$timespan'\n" if $hours < 1 || $hours > 24;
+        $end = $now;
+        $start = $end - $hours * 3600;
+    } elsif ($timespan eq 'today') {
         $start = $daystart;
         $end = $start + 86400;
     } elsif ($timespan eq 'yesterday') {
diff --git a/src/templates/spamreport-short.tt b/src/templates/spamreport-short.tt
index 5c88389..53c6b15 100644
--- a/src/templates/spamreport-short.tt
+++ b/src/templates/spamreport-short.tt
@@ -1,6 +1,8 @@
 [%- IF timespan == 'week' -%]
 [%- SET title = "Weekly Spam Report for '${pmail}' - ${date}'" -%]
-[%- ELSE %]
+[%- ELSIF timespan.substr(timespan.length - 1) == 'h' -%]
+[%- SET title = "Spam Report (last ${timespan}) for '${pmail}' - ${date}" -%]
+[%- ELSE -%]
 [%- SET title = "Daily Spam Report for '${pmail}' - ${date}" -%]
 [%- END -%]
 <html>
diff --git a/src/templates/spamreport-verbose.tt b/src/templates/spamreport-verbose.tt
index 2b2915d..9b7032e 100644
--- a/src/templates/spamreport-verbose.tt
+++ b/src/templates/spamreport-verbose.tt
@@ -1,6 +1,8 @@
 [%- IF timespan == 'week' -%]
 [%- SET title = "Weekly Spam Report for '${pmail}' - ${date}'" -%]
-[%- ELSE %]
+[%- ELSIF timespan.substr(timespan.length - 1) == 'h' -%]
+[%- SET title = "Spam Report (last ${timespan}) for '${pmail}' - ${date}" -%]
+[%- ELSE -%]
 [%- SET title = "Daily Spam Report for '${pmail}' - ${date}" -%]
 [%- END -%]
 
-- 
2.47.2



_______________________________________________
pmg-devel mailing list
pmg-devel@lists.proxmox.com
https://lists.proxmox.com/cgi-bin/mailman/listinfo/pmg-devel


             reply	other threads:[~2025-08-08 10:27 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-08-08 10:28 Hannes Laimer [this message]
2025-09-17 12:22 ` [pmg-devel] applied: " Thomas Lamprecht
2025-09-17 15:22 ` [pmg-devel] " Thomas Lamprecht

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250808102836.50441-1-h.laimer@proxmox.com \
    --to=h.laimer@proxmox.com \
    --cc=pmg-devel@lists.proxmox.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal