public inbox for pmg-devel@lists.proxmox.com
 help / color / mirror / Atom feed
* [pmg-devel] [PATCH pmg-api] fix #2452: pmgqm: allow <x>h to be used as a timespan
@ 2025-08-04 11:03 Hannes Laimer
  2025-08-08 10:30 ` [pmg-devel] superseded: " Hannes Laimer
  0 siblings, 1 reply; 2+ messages in thread
From: Hannes Laimer @ 2025-08-04 11:03 UTC (permalink / raw)
  To: pmg-devel

Signed-off-by: Hannes Laimer <h.laimer@proxmox.com>
---
came up in enterprise support

 src/PMG/CLI/pmgqm.pm | 8 ++++----
 src/PMG/Utils.pm     | 4 ++++
 2 files changed, 8 insertions(+), 4 deletions(-)

diff --git a/src/PMG/CLI/pmgqm.pm b/src/PMG/CLI/pmgqm.pm
index 23968f2..9ff6097 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. <x>h refers to the past x hours.",
                 type => 'string',
-                enum => ['today', 'yesterday', 'week'],
+                pattern => '^(today|yesterday|week|(?:[1-9]|1[0-9]|2[0-3])h)$',
                 default => 'today',
                 optional => 1,
             },
@@ -167,9 +167,9 @@ __PACKAGE__->register_method({
                 },
             ),
             timespan => {
-                description => "Select time span.",
+                description => "Select time span. <x>h refers to the past x hours.",
                 type => 'string',
-                enum => ['today', 'yesterday', 'week'],
+                pattern => '^(today|yesterday|week|(?:[1-9]|1[0-9]|2[0-3])h)$',
                 default => 'today',
                 optional => 1,
             },
diff --git a/src/PMG/Utils.pm b/src/PMG/Utils.pm
index 890096f..d922e7c 100644
--- a/src/PMG/Utils.pm
+++ b/src/PMG/Utils.pm
@@ -1407,6 +1407,10 @@ sub lookup_timespan {
     } elsif ($timespan eq 'week') {
         $end = $daystart;
         $start = $end - 7 * 86400;
+    } elsif ($timespan =~ /^(\d+)h$/) {
+        my $hours = $1;
+        $end = time();
+        $start = $end - ($hours * 3600);
     } else {
         die "internal error";
     }
-- 
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] 2+ messages in thread

end of thread, other threads:[~2025-08-08 10:29 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-08-04 11:03 [pmg-devel] [PATCH pmg-api] fix #2452: pmgqm: allow <x>h to be used as a timespan Hannes Laimer
2025-08-08 10:30 ` [pmg-devel] superseded: " Hannes Laimer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
Service provided by Proxmox Server Solutions GmbH | Privacy | Legal