From 0e71cd5370bec8971db722385a746f995dc592d1 Mon Sep 17 00:00:00 2001
From: "Hahn Axel (hahn)" <axel.hahn@unibe.ch>
Date: Fri, 21 Mar 2025 09:40:25 +0100
Subject: [PATCH] update cert check validation

---
 public_html/appmonitor/plugins/checks/cert.php | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/public_html/appmonitor/plugins/checks/cert.php b/public_html/appmonitor/plugins/checks/cert.php
index 311e6d5..864fe10 100755
--- a/public_html/appmonitor/plugins/checks/cert.php
+++ b/public_html/appmonitor/plugins/checks/cert.php
@@ -57,7 +57,7 @@ class checkCert extends appmonitorcheck
             'url' => [
                 'type' => 'string',
                 'required' => true,
-                'description' => 'Url to check https://[server}[:{port}] or ssl://[server}[:{port}]',
+                'description' => 'Url to check https://[server}[:{port}] or ssl://[server}[:{port}]; autodetected on webserver with php but required on cli',
                 'default' => null,
                 'regex'=>'/^(https|ssl):\/\/[^\s]+/',
                 'example' => '',
@@ -86,6 +86,18 @@ class checkCert extends appmonitorcheck
         ],
     ];
 
+    /**
+     * Override explain()
+     * If https is used, url is not required because it can be autodetected from $_SERVER
+     */
+    public function explain(): array
+    {
+        if($_SERVER['HTTPS']??false && $_SERVER['SERVER_NAME']??false){
+            $this->_aDoc['parameters']['url']['required']=false;
+        }
+        return $this->_aDoc;
+    }
+
     /**
      * Get default group of this check
      * @return string
-- 
GitLab