Skip to content

Commit 9501285

Browse files
committed
19026 NGINX web servers (Linux) plugin now supports IPv6
The NGINX web server (Linux) agent plugin now supports IPv6 addresses. Previously they could not be configured via the GUI and checks using IPv6 addresses (either due to auto-detection or manual configuration) failed. Jira: SUP-26587 Change-Id: I95b80790d8329a55fae8d368986ffcda8f408bd0
1 parent b74622b commit 9501285

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed

.werks/19026.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
[//]: # (werk v2)
2+
# NGINX web servers (Linux) plugin now supports IPv6
3+
4+
key | value
5+
---------- | ---
6+
date | 2026-01-08T09:25:39+00:00
7+
version | 2.4.0p19
8+
class | feature
9+
edition | cee
10+
component | agents
11+
level | 1
12+
compatible | yes
13+
14+
NGINX web server (Linux) agent plugin now supports IPv6 addresses.
15+
16+
Previously they could not be configured via the GUI and checks using IPv6 addresses (either due to auto-detection or manual configuration) failed.
17+
18+
With this update, users can configure IPv6 addresses for the NGINX agent plugin via the GUI without encountering errors. Checks using IPv6 addresses will now succeed automatically after the update, requiring no additional action.

agents/plugins/nginx_status.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
# create an nginx_status.cfg file in MK_CONFDIR and populate the servers
1818
# list to prevent executing the detection mechanism.
1919

20+
import ipaddress
2021
import os
2122
import re
2223
import sys
@@ -120,6 +121,21 @@ def try_detect_servers(ssl_ports):
120121
return results
121122

122123

124+
def _is_ip_v6_address(address: str) -> bool:
125+
"""Check if the given address is an IPv6 address."""
126+
try:
127+
return ipaddress.ip_address(address).version == 6
128+
except ValueError:
129+
return False
130+
131+
132+
def _make_url(proto: str, address: str, port: int, page: str) -> str:
133+
"""Construct a URL from its components, taking care of IPv6 addresses."""
134+
if _is_ip_v6_address(address):
135+
return "%s://[%s]:%s/%s" % (proto, address, port, page)
136+
return "%s://%s:%s/%s" % (proto, address, port, page)
137+
138+
123139
def main(): # pylint: disable=too-many-branches
124140
config_dir = os.getenv("MK_CONFDIR", "/etc/check_mk")
125141
config_file = config_dir + "/nginx_status.cfg"
@@ -155,7 +171,7 @@ def main(): # pylint: disable=too-many-branches
155171
if proto not in ["http", "https"]:
156172
raise ValueError("Scheme '%s' is not allowed" % proto)
157173

158-
url = "%s://%s:%s/%s" % (proto, address, port, page)
174+
url = _make_url(proto, address, port, page)
159175
# Try to fetch the status page for each server
160176
try:
161177
request = Request(url, headers={"Accept": "text/plain", "User-Agent": USER_AGENT})
@@ -164,9 +180,8 @@ def main(): # pylint: disable=too-many-branches
164180
if "SSL23_GET_SERVER_HELLO:unknown protocol" in str(e):
165181
# HACK: workaround misconfigurations where port 443 is used for
166182
# serving non ssl secured http
167-
url = "http://%s:%s/%s" % (address, port, page)
168183
fd = urlopen( # pylint: disable=consider-using-with
169-
url
184+
_make_url("http", address, port, page)
170185
) # nosec B310 # BNS:6b61d9
171186
else:
172187
raise

0 commit comments

Comments
 (0)