Skip to content

Commit

Permalink
17213 FIX oracle_sql: Fix ValueError: could not convert string to flo…
Browse files Browse the repository at this point in the history
…at: ''

SUP-21227

Change-Id: I1f087eb3b63bf001429d519637d3991cecad33e4
  • Loading branch information
SoloJacobs committed Nov 13, 2024
1 parent 1772f35 commit 3bc5d8b
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
21 changes: 21 additions & 0 deletions .werks/17213.md
Original file line number Diff line number Diff line change
@@ -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.4.0b1
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.
3 changes: 2 additions & 1 deletion cmk/plugins/oracle/agent_based/oracle_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,8 @@ def parse_oracle_sql(string_table: StringTable) -> Section:
instance.exit = int(line[1])

elif key == "elapsed":
instance.elapsed = float(line[1])
if line[1] != "":
instance.elapsed = float(line[1])

else:
instance.parsing_error.setdefault(
Expand Down
40 changes: 40 additions & 0 deletions tests/unit/checks/test_oracle_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,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",
Expand Down Expand Up @@ -159,6 +178,27 @@
)
},
),
(
INFO_5,
{
"YOBLE1 SQL NBA SESSIONS": Instance(
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={},
metrics=[
Metric(name="sessions_active", value=0, levels=(10, 20), boundaries=None),
Metric(name="sessions_inactive", value=0, levels=(10, 40), boundaries=None),
Metric(name="sessions_maxage", value=0, levels=None, boundaries=None),
],
)
},
),
],
)
def test_oracle_sql_parse(info, expected):
Expand Down

0 comments on commit 3bc5d8b

Please sign in to comment.