all lists on lists.proxmox.com
 help / color / mirror / Atom feed
* [pmg-devel] [PATCH pmg-api v2] fix #2452: pmgqm support 1-24h timespans for status/send
@ 2025-08-08 10:28 Hannes Laimer
  2025-09-17 12:22 ` [pmg-devel] applied: " Thomas Lamprecht
  2025-09-17 15:22 ` [pmg-devel] " Thomas Lamprecht
  0 siblings, 2 replies; 3+ messages in thread
From: Hannes Laimer @ 2025-08-08 10:28 UTC (permalink / raw)
  To: pmg-devel

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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [pmg-devel] applied: [PATCH pmg-api v2] fix #2452: pmgqm support 1-24h timespans for status/send
  2025-08-08 10:28 [pmg-devel] [PATCH pmg-api v2] fix #2452: pmgqm support 1-24h timespans for status/send Hannes Laimer
@ 2025-09-17 12:22 ` Thomas Lamprecht
  2025-09-17 15:22 ` [pmg-devel] " Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2025-09-17 12:22 UTC (permalink / raw)
  To: pmg-devel, Hannes Laimer

On Fri, 08 Aug 2025 12:28:36 +0200, Hannes Laimer wrote:
> 

Applied, fleeced in a basic commit message though, thanks!

[1/1] fix #2452: pmgqm support 1-24h timespans for status/send
      commit: 24c6610fbb902f714a42b69903100bf05b388dd8


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [pmg-devel] [PATCH pmg-api v2] fix #2452: pmgqm support 1-24h timespans for status/send
  2025-08-08 10:28 [pmg-devel] [PATCH pmg-api v2] fix #2452: pmgqm support 1-24h timespans for status/send Hannes Laimer
  2025-09-17 12:22 ` [pmg-devel] applied: " Thomas Lamprecht
@ 2025-09-17 15:22 ` Thomas Lamprecht
  1 sibling, 0 replies; 3+ messages in thread
From: Thomas Lamprecht @ 2025-09-17 15:22 UTC (permalink / raw)
  To: Hannes Laimer, pmg-devel

Am 08.08.25 um 12:28 schrieb Hannes Laimer:
> 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)$',

Oh and FWIW, was fine as is, but it would have been a potential use case for
the relatively new oneOf schema support to split the enum and the more free
form variants into two different sub-schemas. Mostly mentioning it to ensure
it's known to a wider audience that using the oneOf schema would (or at least
should ;) be possible in the perl based APIs too.


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


^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2025-09-17 15:21 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-08 10:28 [pmg-devel] [PATCH pmg-api v2] fix #2452: pmgqm support 1-24h timespans for status/send Hannes Laimer
2025-09-17 12:22 ` [pmg-devel] applied: " Thomas Lamprecht
2025-09-17 15:22 ` [pmg-devel] " Thomas Lamprecht

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