centreon / centreon-plugins

Collection of standard plugins to discover and gather cloud-to-edge metrics and status across your whole IT infrastructure.
https://www.centreon.com
Apache License 2.0
311 stars 274 forks source link

apps::protocols::http::plugin --http-peer-addr #5002

Open cmertz-sop opened 6 months ago

cmertz-sop commented 6 months ago

--http-peer-addr arguement doesn't work as expected

When I use --http-peer-addr the get address should be replaced by toto.my.domain.com but it isn't the case, in debug mode it is still the ip adress who is used .

/usr/lib/centreon/plugins//centreon_protocol_http.pl --plugin=apps::protocols::http::plugin --mode=response --hostname=ip_address --proto='https' --port='' --urlpath='/WSWebClient/Default.aspx' --warning='' --critical='' --http-peer-addr='toto.my.domain.com' --debug CRITICAL: 404 Not Found | 'time'=0.114s;;;0; 'size'=19B;;;0; ======> request send GET https://ip_address/WSWebClient/Default.aspx User-Agent: centreon::plugins::backend::http::useragent

======> response done HTTP/1.1 404 Not Found Date: Mon, 29 Apr 2024 15:28:28 GMT Content-Length: 19 Content-Type: text/plain; charset=utf-8 Client-Date: Mon, 29 Apr 2024 15:28:28 GMT Client-Peer: 172.21.0.110:443 Client-Response-Num: 1 Client-SSL-Cert-Issuer: /DC=com/DC=soprema/DC=ad/CN=SRVEUCAA02-CA Client-SSL-Cert-Subject: /CN=*ad..soprema.com Client-SSL-Cipher: TLS_AES_256_GCM_SHA384 Client-SSL-Socket-Class: IO::Socket::SSL Client-SSL-Version: TLSv1_3 X-Content-Type-Options: nosniff

404 page not found

lucie-dubrunfaut commented 3 months ago

Hello :)

If I understand correctly the request should have been :

======> request send
GET https://toto.my.domain.com/WSWebClient/Default.aspx
User-Agent: centreon::plugins::backend::http::useragent

======> response done

and this would have been a functional request in your case?

From what I found the --http-peer-addr option is involved in two calls during plugin initialization: First at line 47 when calling lwp mode, the option is checked line 188 and then in http plugin at line 54 when calling curl mode, the option is checked line 350 :

if (defined($options{request}->{http_peer_addr}) && $options{request}->{http_peer_addr} ne '') {
        $url =~ /^(?:http|https):\/\/(.*?)(\/|\:|$)/;
        $self->{curl_easy}->setopt(
            $self->{constant_cb}->(name => 'CURLOPT_RESOLVE'),
            [$1 . ':' . $options{request}->{port_force} . ':' . $options{request}->{http_peer_addr}]
        );
    }  

in your case the url won't match I think the "http" or "https" is missing in the option (maybe we should add something about it in the option help). Could you test with "http//toto.my.domain.com" or "https//toto.my.domain.com" in the option --http-peer-addr?