]> git.ipfire.org Git - thirdparty/bacula.git/commitdiff
baculum: Add age parameter to jobs and objects endpoints
authorMarcin Haba <marcin.haba@bacula.pl>
Mon, 5 Dec 2022 15:24:01 +0000 (16:24 +0100)
committerMarcin Haba <marcin.haba@bacula.pl>
Mon, 9 Jan 2023 12:34:42 +0000 (13:34 +0100)
gui/baculum/protected/API/Pages/API/Jobs.php
gui/baculum/protected/API/Pages/API/Objects.php
gui/baculum/protected/API/openapi_baculum.json

index 4c101d1ed8055bd51aac8d2b479adbdc6afa6973..cf1d95832d1a75451701591a19568555d76818d2 100644 (file)
@@ -49,6 +49,7 @@ class Jobs extends BaculumAPIServer {
                $endtime_to = $this->Request->contains('endtime_to') && $misc->isValidInteger($this->Request['endtime_to']) ? (int)$this->Request['endtime_to'] : null;
                $realendtime_from = $this->Request->contains('realendtime_from') && $misc->isValidInteger($this->Request['realendtime_from']) ? (int)$this->Request['realendtime_from'] : null;
                $realendtime_to = $this->Request->contains('realendtime_to') && $misc->isValidInteger($this->Request['realendtime_to']) ? (int)$this->Request['realendtime_to'] : null;
+               $age = $this->Request->contains('age') && $misc->isValidInteger($this->Request['age']) ? (int)$this->Request['age'] : null;
                $order_by = $this->Request->contains('order_by') && $misc->isValidColumn($this->Request['order_by']) ? $this->Request['order_by']: 'JobId';
                $order_direction = $this->Request->contains('order_direction') && $misc->isValidOrderDirection($this->Request['order_direction']) ? $this->Request['order_direction']: 'DESC';
 
@@ -145,6 +146,12 @@ class Jobs extends BaculumAPIServer {
                                        'vals' => date('Y-m-d H:i:s', $starttime_to)
                                ];
                        }
+               } elseif (!empty($age)) { // Job age (now() - age)
+                       $params['Job.StartTime'] = [];
+                       $params['Job.StartTime'][] = [
+                               'operator' => '>=',
+                               'vals' => date('Y-m-d H:i:s', (time() - $age))
+                       ];
                }
 
                // End time range
index 97e1b9fdbee94acd7eb70ea2925bf21d2f826af8..0be7449c90ffffb890a05f46297b4dcb06271a21 100644 (file)
@@ -53,6 +53,7 @@ class Objects extends BaculumAPIServer {
                $endtime_to = $this->Request->contains('endtime_to') && $misc->isValidInteger($this->Request['endtime_to']) ? (int)$this->Request['endtime_to'] : null;
                $realendtime_from = $this->Request->contains('realendtime_from') && $misc->isValidInteger($this->Request['realendtime_from']) ? (int)$this->Request['realendtime_from'] : null;
                $realendtime_to = $this->Request->contains('realendtime_to') && $misc->isValidInteger($this->Request['realendtime_to']) ? (int)$this->Request['realendtime_to'] : null;
+               $age = $this->Request->contains('age') && $misc->isValidInteger($this->Request['age']) ? (int)$this->Request['age'] : null;
                $order_by = $this->Request->contains('order_by') && $misc->isValidColumn($this->Request['order_by']) ? $this->Request['order_by']: 'ObjectId';
                $order_direction = $this->Request->contains('order_direction') && $misc->isValidOrderDirection($this->Request['order_direction']) ? $this->Request['order_direction']: 'DESC';
 
@@ -178,6 +179,12 @@ class Objects extends BaculumAPIServer {
                                        'vals' => date('Y-m-d H:i:s', $starttime_to)
                                ];
                        }
+               } elseif (!empty($age)) { // Job age (now() - age)
+                       $params['Job.StartTime'] = [];
+                       $params['Job.StartTime'][] = [
+                               'operator' => '>=',
+                               'vals' => date('Y-m-d H:i:s', (time() - $age))
+                       ];
                }
 
                // End time range
index bbad2f0b17f0ef68eef0edb770005d15727511c9..5dc391b7f83406eccc49780604fd6f6d2fbbd29f 100644 (file)
                                                        "type": "integer"
                                                }
                                        },
+                                       {
+
+                                               "name": "age",
+                                               "in": "query",
+                                               "required": false,
+                                               "description": "Job age in seconds (used is start time). starttime_from and starttime_to take precedence over this parameter.",
+                                               "schema": {
+                                                       "type": "integer"
+                                               }
+                                       },
                                        {
                                                "name": "order_by",
                                                "in": "query",
                                                "schema": {
                                                        "type": "integer"
                                                }
+                                       },
+                                       {
+
+                                               "name": "age",
+                                               "in": "query",
+                                               "required": false,
+                                               "description": "Job age in seconds (used is start time). starttime_from and starttime_to take precedence over this parameter.",
+                                               "schema": {
+                                                       "type": "integer"
+                                               }
                                        }
                                ]
                        }