2.1.0p24 CEE: Apache Status: 400 Bad request

CMK version: 2.1.0p24
OS version: Ubuntu 20.04

Error message:
I have a fresh installation of apache on an Ubuntu 22.04. With default config for apache_status, the generated url inside the python script is http://*:80/server-status?auto which ends in HTTP-Error (*:80): 400 HTTP Error 400: Bad Request.

the ss output:

:~# ss -tlnp
State         Recv-Q        Send-Q               Local Address:Port                  Peer Address:Port        Process
LISTEN        0             4096                 127.0.0.53%lo:53                         0.0.0.0:*            users:(("systemd-resolve",pid=739,fd=14))
LISTEN        0             128                        0.0.0.0:22                         0.0.0.0:*            users:(("sshd",pid=890,fd=3))
LISTEN        0             50                         0.0.0.0:445                        0.0.0.0:*            users:(("smbd",pid=961,fd=46))
LISTEN        0             70                         0.0.0.0:33060                      0.0.0.0:*            users:(("mysqld",pid=962,fd=21))
LISTEN        0             151                        0.0.0.0:3306                       0.0.0.0:*            users:(("mysqld",pid=962,fd=32))
LISTEN        0             50                         0.0.0.0:139                        0.0.0.0:*            users:(("smbd",pid=961,fd=47))
LISTEN        0             511                              *:80                               *:*            users:(("apache2",pid=16757,fd=4),("apache2",pid=16756,fd=4),("apache2",pid=16755,fd=4))
LISTEN        0             128                           [::]:22                            [::]:*            users:(("sshd",pid=890,fd=4))
LISTEN        0             4096                             *:6556                             *:*            users:(("cmk-agent-ctl",pid=7011,fd=9))
LISTEN        0             50                            [::]:445                           [::]:*            users:(("smbd",pid=961,fd=44))
LISTEN        0             50                            [::]:139                           [::]:*            users:(("smbd",pid=961,fd=45))

Do I have to configure apache in order to get the apache_status check working?
In my opinion, the .py should also consider 127.0.0.1 if *:80 is seen.

    # Use localhost when listening globally
    if server_address == "0.0.0.0":  # nosec - B104
        server_address = "127.0.0.1"
    elif server_address == "::":
        server_address = "[::1]"
    elif ":" in server_address:
        server_address = "[%s]" % server_address

Thanks :slight_smile:

Of course mod_status has to be enabled. mod_status - Apache HTTP Server Version 2.4

It is. Normal reqeusts to a valid URL are successful:

:~# curl http://127.0.0.1:80/server-status?auto
127.0.0.1
ServerVersion: Apache/2.4.52 (Ubuntu)
ServerMPM: event
Server Built: 2023-03-08T17:32:01
CurrentTime: Wednesday, 15-Mar-2023 10:23:02 CET
RestartTime: Wednesday, 15-Mar-2023 09:31:17 CET
ParentServerConfigGeneration: 1
ParentServerMPMGeneration: 0
ServerUptimeSeconds: 3104
ServerUptime: 51 minutes 44 seconds
Load1: 0.06
Load5: 0.03
Load15: 0.00
Total Accesses: 55
Total kBytes: 34
Total Duration: 0
CPUUser: .05
CPUSystem: .04
CPUChildrenUser: 0
CPUChildrenSystem: 0
CPULoad: .00289948
Uptime: 3104
ReqPerSec: .0177191
BytesPerSec: 11.2165
BytesPerReq: 633.018
DurationPerReq: 0
BusyWorkers: 1
IdleWorkers: 49
Processes: 2
Stopping: 0
BusyWorkers: 1
IdleWorkers: 49
ConnsTotal: 0
ConnsAsyncWriting: 0
ConnsAsyncKeepAlive: 0
ConnsAsyncClosing: 0
Scoreboard: ________________________W_________________________....................................................................................................

vs Plugin generated URL:

:~# curl http://*:80/server-status?auto
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>400 Bad Request</title>
</head><body>
<h1>Bad Request</h1>
<p>Your browser sent a request that this server could not understand.<br />
</p>
<hr>
<address>Apache/2.4.52 (Ubuntu) Server at 127.0.1.1 Port 80</address>
</body></html>

This is still an issue. I setup apache2 on Ubuntu 22.04 with default options.

The CMK script executes ss -tlnp 2>/dev/null and gets (cut from me):

LISTEN        0             511                                *:80                              *:*            users:(("apache2",pid=47991,fd=4),("apache2",pid=47990,fd=4),("apache2",pid=1035,fd=4))
LISTEN        0             511                                *:443                             *:*            users:(("apache2",pid=47991,fd=6),("apache2",pid=47990,fd=6),("apache2",pid=1035,fd=6))

long story short, the script goes to the last if/else block and return the server_address as is.

The calculated URLs are now:

http://*:80/server-status?auto
https://*:443/server-status?auto

which are invalid.

Is this a case the plugin has to catch?

    # Use localhost when listening globally
    if server_address == "0.0.0.0" or server_address == "*":  # nosec - B104
        server_address = "127.0.0.1"
    elif server_address == "::":
        server_address = "[::1]"
    elif ":" in server_address:
        server_address = "[%s]" % server_address

is fixing the check with default Apache config (note the or inside first if).

Anyone who could confirm the “fix” or prove it wrong?

@robin.gierse maybe?

Maybe something is wrong at my end but I cant tell.

This is fixed in 2.2: apache_status: Fix missing &quot;[::]&quot; if listen globally via command &#039;ss&#039;