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 8055b2e commit 4da834a
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 1 deletion.
19 changes: 19 additions & 0 deletions .werks/17213
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
Title: oracle_sql: Fix ValueError: could not convert string to float: ''
Class: fix
Compatible: compat
Component: checks
Date: 1731419724
Edition: cre
Level: 1
Version: 2.2.0p37

The agent plugin <code>mk_oracle</code> reports <code>elapsed:' for the elapsed time, if the</code>perl<code>or</code>bc<code>call fail.
In the past, the plugin</code>oracle_sql` crashes with

C+:
elif key == "elapsed":
instance.elapsed = float(line[1])
ValueError: could not convert string to float: ''
C-:

With this Werk, the crash is fixed. The missing metric <code>elapsed_time</code> will be omitted.
3 changes: 2 additions & 1 deletion checks/oracle_sql
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ def parse_oracle_sql(info):
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 4da834a

Please sign in to comment.