diff --git a/.werks/17213.md b/.werks/17213.md new file mode 100644 index 00000000000..1b4689d1623 --- /dev/null +++ b/.werks/17213.md @@ -0,0 +1,21 @@ +[//]: # (werk v2) +# oracle_sql: Fix ValueError: could not convert string to float: '' + +key | value +---------- | --- +date | 2024-11-12T13:55:24+00:00 +version | 2.3.0p21 +class | fix +edition | cre +component | checks +level | 1 +compatible | yes + +The agent plugin `mk_oracle` reports `elapsed:' for the elapsed time, if the `perl` or `bc` call fail. +In the past, the plugin `oracle_sql` crashes with +``` + elif key == "elapsed": + instance.elapsed = float(line[1]) +ValueError: could not convert string to float: '' +``` +With this Werk, the crash is fixed. The missing metric `elapsed_time` will be omitted. diff --git a/cmk/base/legacy_checks/oracle_sql.py b/cmk/base/legacy_checks/oracle_sql.py index faf19611840..02a434c6e80 100644 --- a/cmk/base/legacy_checks/oracle_sql.py +++ b/cmk/base/legacy_checks/oracle_sql.py @@ -88,7 +88,8 @@ def parse_perfdata(line): instance[key] = int(line[1]) elif key == "elapsed": - instance[key] = float(line[1]) + if line[1] != "": + instance[key] = float(line[1]) else: instance["parsing_error"].setdefault( diff --git a/tests/unit/checks/test_oracle_sql.py b/tests/unit/checks/test_oracle_sql.py index f8aea140dd4..07357a55bea 100644 --- a/tests/unit/checks/test_oracle_sql.py +++ b/tests/unit/checks/test_oracle_sql.py @@ -59,6 +59,25 @@ ["elapsed", "0.29444"], ] +# In SUP-21227 it was reported that the line 'elapsed:' shows up in the agent output. We did not +# obtain an agent output, but this could happen if `perl -MTime::HiRes=time -wle 'print time'` +# fails. This table was copied from INFO_4 and modified to match the ticket. +INFO_5 = [ + ["[[[yoble1|NBA SESSIONS]]]"], + ["long", "Avara SEP_ID", " 301"], + [ + "details", + "Active sessions", + " 0 (warn/crit at 10/20) / Inactive sessions", + " 0 (warn/crit at 10/40)", + ], + ["perfdata", "sessions_active=0;10;20"], + ["perfdata", "sessions_inactive=0;10;40"], + ["perfdata", "sessions_maxage=0"], + ["exit", "0"], + ["elapsed", ""], +] + @pytest.mark.parametrize( "info,expected", @@ -154,6 +173,27 @@ } }, ), + ( + INFO_5, + { + "YOBLE1 SQL NBA SESSIONS": { + "details": [ + "Active sessions: 0 (warn/crit at " + "10/20) / Inactive sessions: 0 " + "(warn/crit at 10/40)" + ], + "elapsed": None, + "exit": 0, + "long": ["Avara SEP_ID: 301"], + "parsing_error": {}, + "perfdata": [ + ("sessions_active", 0, 10, 20), + ("sessions_inactive", 0, 10, 40), + ("sessions_maxage", 0), + ], + } + }, + ), ], ) def test_oracle_sql_parse(info, expected):