[monitoring-plugins] Added ability to correctly check redirects with ...

Sven Nierlein git at monitoring-plugins.org
Sun Sep 18 20:50:10 CEST 2022


    Module: monitoring-plugins
    Branch: master
    Commit: 8f54442c68cf5bfaffc33b8e618462e82771478b
    Author: Eric Wunderlin <wunde005 at umn.edu>
 Committer: Sven Nierlein <sven at nierlein.org>
      Date: Mon Apr 11 12:52:02 2016 -0500
       URL: https://www.monitoring-plugins.org/repositories/monitoring-plugins/commit/?id=8f54442

Added ability to correctly check redirects with reference format //test.server.com/folder

Referenced redirect of the format //www.server.com/folder would result
in check_http trying to contact http://hostname:80//www.server.com/folder
instead of http://www.server.com/folder. Referenced redirect of this format
is listed in rfc3986 ( https://tools.ietf.org/html/rfc3986 ). It should
work as expected now.

---

 plugins/check_http.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/plugins/check_http.c b/plugins/check_http.c
index f8ec853..36f3b25 100644
--- a/plugins/check_http.c
+++ b/plugins/check_http.c
@@ -1364,6 +1364,9 @@ check_http (void)
 #define HD3 URI_HTTP "://" URI_HOST ":" URI_PORT
 #define HD4 URI_HTTP "://" URI_HOST
 #define HD5 URI_PATH
+/* relative reference redirect like //www.site.org/test https://tools.ietf.org/html/rfc3986 */
+#define HD6 "//" URI_HOST "/" URI_PATH
+
 
 void
 redir (char *pos, char *status_line)
@@ -1440,6 +1443,21 @@ redir (char *pos, char *status_line)
       use_ssl = server_type_check (type);
       i = server_port_check (use_ssl);
     }
+    else if (sscanf (pos, HD6, addr, url) == 2) {
+      //get type from
+      if(use_ssl){
+        //i = server_port_check (use_ssl);
+        strcpy (type,"https");
+      }
+      //else if(sscanf(server_url,URI_HTTP,type)==1 ){
+      //}
+      else{
+         strcpy (type, server_type);
+      }
+      xasprintf (&url, "/%s", url);
+      use_ssl = server_type_check (type);
+      i = server_port_check (use_ssl);
+    }
 
     /* URI_PATH */
     else if (sscanf (pos, HD5, url) == 1) {



More information about the Commits mailing list