[pmg-devel] [PATCH pmg-api] fix #2452: pmgqm: allow <x>h to be used as a timespan

Hannes Laimer h.laimer at proxmox.com
Mon Aug 4 13:03:27 CEST 2025


Signed-off-by: Hannes Laimer <h.laimer at 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





More information about the pmg-devel mailing list