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 56031d8 commit bf972e5
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.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.
3 changes: 2 additions & 1 deletion cmk/base/legacy_checks/oracle_sql.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
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 @@ -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",
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit bf972e5

Please sign in to comment.