Skip to content

Commit fcbdc54

Browse files
committed
fix(mysql-version): handle the new MariaDB 11.4 client banner and mariadbd
MariaDB 11.4 dropped the legacy `mysqld` symlink and renamed the `mariadb --version` client banner from `Distrib X.Y.Z, ...` to `from X.Y.Z, ...`. The plugin's old fallback regex `r'(?i)b (.*?),'` matched the `b ` in `mariadb` (the program name) instead of the one in `Distrib`, so on 11.4 and later it produced output like `MariaDB vfrom 11.4.10` and the printed version string was wrong (EOL detection still happened to work because `lib.version.version()` re-extracts the digits, but that was luck, not design). Rewrite `get_installed_version()` so it: - tries `mysqld`, `mariadbd`, `mariadb` and `mysql` in that order, picking the new MariaDB binaries up where the old symlinks no longer exist; - runs three explicit regexes against the output: - `Ver (\d+\.\d+\.\d+(?:-MariaDB)?)` for the `mysqld` and `mariadbd` server banners (also strips ugly package suffixes like `-1~trusty` and `-ubu2204`); - `Distrib (\S+?),` for the legacy `mysql --version` / `mariadb --version` Distrib banner; - `from (\d+\.\d+\.\d+(?:-MariaDB)?),` for the new MariaDB 11.4+ client banner. Add fixtures and TESTS for every MariaDB cycle that endoflife.date currently lists (5.5, 10.4, 10.5 x2, 10.6, 10.11, 11.4, 11.8, 12.0, 12.1, 12.2) plus the existing MySQL 8.0/8.4 captures. Eleven of the fifteen testcases hit a WARN state today, exercising the EOL code path against both very old (5.5) and brand-new (12.0) cycles. Bumps `__version__` to `2026041302`.
1 parent bcbe20d commit fcbdc54

File tree

10 files changed

+124
-51
lines changed

10 files changed

+124
-51
lines changed

check-plugins/mysql-version/mysql-version

Lines changed: 49 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -123,46 +123,58 @@ def parse_args():
123123
return args
124124

125125

126+
# Output formats this parser handles:
127+
#
128+
# mysqld Ver 8.0.45 for Linux on x86_64 (Source distribution)
129+
# mysqld Ver 10.11.15-MariaDB for Linux on x86_64 (MariaDB Server)
130+
# mysql Ver 14.14 Distrib 5.7.44, for Linux (x86_64) using EditLine wrapper
131+
# mariadb Ver 15.1 Distrib 10.5.x-MariaDB, for Linux on x86_64
132+
# mariadb from 11.4.10-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
133+
#
134+
# MariaDB 11.4 dropped the `mysqld` symlink and renamed the client
135+
# version banner from "Distrib X.Y.Z" to "from X.Y.Z", so the parser
136+
# also tries `mariadbd` and accepts both prefixes.
137+
_VERSION_REGEXES = (
138+
# `mysqld Ver X.Y.Z[-MariaDB] for ...` (the package suffix that
139+
# some distros append, e.g. `-1~trusty`, is stripped)
140+
r'Ver (\d+\.\d+\.\d+(?:-MariaDB)?)',
141+
# `mysql Ver 14.14 Distrib X.Y.Z[-MariaDB], for ...`
142+
# `mariadb Ver 15.1 Distrib 10.5.x-MariaDB, for ...`
143+
r'Distrib (\S+?),',
144+
# `mariadb from X.Y.Z[-MariaDB], client ...` (MariaDB 11.4+)
145+
r'from (\d+\.\d+\.\d+(?:-MariaDB)?),',
146+
)
147+
148+
149+
def _parse_version(stdout):
150+
"""Try every known version-string regex against `stdout` and
151+
return the first match, or `''` if none of them apply.
152+
"""
153+
for regex in _VERSION_REGEXES:
154+
m = re.search(regex, stdout)
155+
if m:
156+
return m.group(1).strip()
157+
return ''
158+
159+
126160
def get_installed_version(test_arg=None):
127-
# In test mode, read the fixture once and try both regexes
128-
# against it. The mysqld output matches the first one; the
129-
# mariadb / mysql client outputs match the second.
130161
if test_arg is not None:
131162
stdout, _, _ = lib.lftest.test(test_arg)
132-
stdout = stdout.strip()
133-
m = re.search(r'Ver (.*?) ', stdout)
134-
if m:
135-
return m.group(1).strip()
136-
m = re.search(r'(?i)b (.*?),', stdout)
137-
if m:
138-
return m.group(1).strip()
139-
return ''
140-
141-
success, result = lib.shell.shell_exec('mysqld --version')
142-
if success:
143-
stdout = result[0].strip()
144-
# where to find the version number in output?
145-
version_regex = r'Ver (.*?) '
146-
try:
147-
stdout = re.search(version_regex, stdout)
148-
return stdout.group(1).strip()
149-
except Exception:
150-
pass
151-
152-
success, result = lib.shell.shell_exec('mariadb --version')
153-
if not success:
154-
success, result = lib.shell.shell_exec('mysql --version')
155-
if not success:
156-
return ''
157-
158-
stdout = result[0].strip()
159-
# where to find the version number in output?
160-
version_regex = r'(?i)b (.*?),'
161-
try:
162-
stdout = re.search(version_regex, stdout)
163-
return stdout.group(1).strip()
164-
except Exception:
165-
return ''
163+
return _parse_version(stdout.strip())
164+
165+
# Try the server binary first under both its old name (`mysqld`)
166+
# and its current MariaDB name (`mariadbd`), then fall back to the
167+
# client binary under both its current name (`mariadb`) and its
168+
# legacy name (`mysql`).
169+
for command in ('mysqld --version', 'mariadbd --version',
170+
'mariadb --version', 'mysql --version'):
171+
success, result = lib.shell.shell_exec(command)
172+
if not success:
173+
continue
174+
version = _parse_version(result[0].strip())
175+
if version:
176+
return version
177+
return ''
166178

167179

168180
def main():

check-plugins/mysql-version/unit-test/run

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,21 @@
1111
"""Unit tests for the mysql-version check plugin.
1212
1313
The plugin probes for either MySQL Community Server or MariaDB by
14-
running `mysqld --version` first and falling back to
15-
`mariadb --version` / `mysql --version` if the server binary is not
16-
available. Two regexes parse the two output formats:
14+
running `mysqld`, `mariadbd`, `mariadb` or `mysql` with `--version`
15+
and parses the result. Three regexes cover three output formats:
1716
18-
- mysqld output: `mysqld Ver 10.11.15-MariaDB for Linux ...`
19-
`/usr/libexec/mysqld Ver 8.0.45 for Linux ...`
20-
- client output: `mysql Ver 15.1 Distrib 10.11.x-MariaDB, for ...`
17+
- `mysqld Ver X.Y.Z[-MariaDB] for ...` (mysqld and mariadbd)
18+
- `mysql Ver 14.14 Distrib X.Y.Z, for ...` (legacy mysql client)
19+
- `mariadb from X.Y.Z-MariaDB, client ...` (MariaDB 11.4+ client)
2120
22-
The fixtures in `stdout/` are the real `mysqld --version` strings
23-
captured from the Red Hat / CentOS Stream sclorg containers
24-
(`quay.io/sclorg/mariadb-105-c8s`, `mariadb-105-c9s`,
25-
`mariadb-1011-c10s`, `mysql-80-c8s`, `mysql-80-c9s`,
26-
`mysql-84-c10s`). Both the MariaDB-suffixed format and the
27-
upstream-MySQL format are covered.
21+
Fixtures in `stdout/` come from a mix of sources:
22+
23+
- `quay.io/sclorg/mysql-{80,84}-c{8,9,10}s` and
24+
`quay.io/sclorg/mariadb-{105,1011}-c{8,9,10}s` for the Red Hat /
25+
CentOS Stream packaging
26+
- `docker.io/library/mariadb:<tag>` for the older 5.5 and 10.4
27+
cycles plus the upstream-only 10.6, 11.4, 11.8, 12.0, 12.1 and
28+
12.2 MariaDB releases (no Red Hat container ships those yet)
2829
2930
Each testcase pins the expected Nagios state to whatever
3031
`lib.version.check_eol()` returned when these fixtures were saved
@@ -43,8 +44,20 @@ import lib.lftest
4344

4445

4546
TESTS = [
47+
# ---- MariaDB --------------------------------------------------
48+
{
49+
'id': 'warn-mariadb-5-5-eol',
50+
'test': 'stdout/mysqld-version-mariadb-5.5,,0',
51+
'assert-retc': STATE_WARN,
52+
'assert-in': ['MariaDB v5.5.64', 'EOL 2020-04-11', '[WARNING]'],
53+
},
54+
{
55+
'id': 'warn-mariadb-10-4-eol',
56+
'test': 'stdout/mysqld-version-mariadb-10.4,,0',
57+
'assert-retc': STATE_WARN,
58+
'assert-in': ['MariaDB v10.4.34', 'EOL 2024-06-18', '[WARNING]'],
59+
},
4660
{
47-
# MariaDB 10.5 reached EOL 2025-06-24.
4861
'id': 'warn-mariadb-10-5-c8s-eol',
4962
'test': 'stdout/mysqld-version-mariadb-10.5-c8s,,0',
5063
'assert-retc': STATE_WARN,
@@ -56,13 +69,53 @@ TESTS = [
5669
'assert-retc': STATE_WARN,
5770
'assert-in': ['MariaDB v10.5.29', 'EOL 2025-06-24', '[WARNING]'],
5871
},
72+
{
73+
# MariaDB 10.6 LTS, EOL 2026-07-06.
74+
'id': 'ok-mariadb-10-6-supported',
75+
'test': 'stdout/mysqld-version-mariadb-10.6,,0',
76+
'assert-retc': STATE_OK,
77+
'assert-in': ['MariaDB v10.6.25', 'EOL 2026-07-06'],
78+
},
5979
{
6080
# MariaDB 10.11 LTS, EOL 2028-02-16.
6181
'id': 'ok-mariadb-10-11-c10s-supported',
6282
'test': 'stdout/mysqld-version-mariadb-10.11-c10s,,0',
6383
'assert-retc': STATE_OK,
6484
'assert-in': ['MariaDB v10.11.15', 'EOL 2028-02-16'],
6585
},
86+
{
87+
# MariaDB 11.4 LTS via the new `mariadb --version` client
88+
# banner. Exercises the third parser regex (`from X.Y.Z,`).
89+
'id': 'ok-mariadb-11-4-client-banner-supported',
90+
'test': 'stdout/mariadb-version-client-11.4,,0',
91+
'assert-retc': STATE_OK,
92+
'assert-in': ['MariaDB v11.4.10', 'EOL 2029-05-29'],
93+
},
94+
{
95+
'id': 'ok-mariadb-11-8-client-banner-supported',
96+
'test': 'stdout/mariadb-version-client-11.8,,0',
97+
'assert-retc': STATE_OK,
98+
'assert-in': ['MariaDB v11.8.6', 'EOL 2028-06-04'],
99+
},
100+
{
101+
'id': 'warn-mariadb-12-0-near-eol',
102+
'test': 'stdout/mariadb-version-client-12.0,,0',
103+
'assert-retc': STATE_WARN,
104+
'assert-in': ['MariaDB v12.0.2', 'EOL 2025-11-18', '[WARNING]'],
105+
},
106+
{
107+
'id': 'warn-mariadb-12-1-near-eol',
108+
'test': 'stdout/mariadb-version-client-12.1,,0',
109+
'assert-retc': STATE_WARN,
110+
'assert-in': ['MariaDB v12.1.2', 'EOL 2026-02-13', '[WARNING]'],
111+
},
112+
{
113+
'id': 'warn-mariadb-12-2-near-eol',
114+
'test': 'stdout/mariadb-version-client-12.2,,0',
115+
'assert-retc': STATE_WARN,
116+
'assert-in': ['MariaDB v12.2.2', 'EOL 2026-05-13', '[WARNING]'],
117+
},
118+
# ---- MySQL ----------------------------------------------------
66119
{
67120
# MySQL 8.0 - full support already ended, hard EOL 2026-04-30.
68121
'id': 'warn-mysql-8-0-c8s-near-eol',
@@ -88,8 +141,8 @@ TESTS = [
88141
'assert-retc': STATE_OK,
89142
'assert-in': ['MySQL v8.4.8', 'EOL 2032-04-30'],
90143
},
144+
# ---- Edge case ------------------------------------------------
91145
{
92-
# Parser edge case: command not found.
93146
'id': 'unknown-garbage-output',
94147
'test': 'stdout/garbage-output,,0',
95148
'assert-retc': STATE_UNKNOWN,
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mariadb from 11.4.10-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mariadb from 11.8.6-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mariadb from 12.0.2-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mariadb from 12.1.2-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mariadb from 12.2.2-MariaDB, client 15.2 for debian-linux-gnu (x86_64) using EditLine wrapper
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mysqld Ver 10.4.34-MariaDB-1:10.4.34+maria~ubu2004 for debian-linux-gnu on x86_64 (mariadb.org binary distribution)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mysqld Ver 10.6.25-MariaDB-ubu2204 for debian-linux-gnu on x86_64 (mariadb.org binary distribution)
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
mysqld Ver 5.5.64-MariaDB-1~trusty for debian-linux-gnu on x86_64 (mariadb.org binary distribution)

0 commit comments

Comments
 (0)