Skip to content

Commit

Permalink
15339 FIX check_sql: activate thick mode for oracle connections
Browse files Browse the repository at this point in the history
With [Werk #16023](https://checkmk.com/werk/16023) we switched the
library used to connect to oracle databases from `cx_Oracle` to
`oracledb`. For `cx_Oracle` it was mandatory to install "Oracle Instant
Client". The newer `oracledb` library has two modes: A stand alone thin
mode and a thick mode that needs the "Oracle Instant Client".

In order to fully replace `cx_Oracle`, `oracledb` needs to be in thick
mode. This is something we have not considered for Werk #16023.

With this Werk we now try to switch into the thick mode, and if this
does not work, we use thin mode. If you execute `check_sql` with `-v`
switch you will see a message if `oracledb` could not switch into thick
mode.

`oracledb` searches for the "Oracle Instant Client" in several standard
location. `check_sql` will find the installation if the files (among
other things `*.so` and `*.jar`) from the "Oracle Instant Client" files
are directly in `~local/lib/` in your site.

SUP-19387

Change-Id: I0349197f239b2cc18c15ee8f11c05a61044bad04
  • Loading branch information
BenediktSeidl committed Aug 13, 2024
1 parent 537cf9d commit 6537732
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .werks/15339.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[//]: # (werk v2)
# check_sql: activate thick mode for oracle connections

key | value
---------- | ---
date | 2024-08-08T09:40:54+00:00
version | 2.4.0b1
class | fix
edition | cre
component | checks
level | 1
compatible | yes

With [Werk #16023](https://checkmk.com/werk/16023) we switched the library used
to connect to oracle databases from `cx_Oracle` to `oracledb`. For `cx_Oracle`
it was mandatory to install "Oracle Instant Client". The newer `oracledb` library has
two modes: A stand alone thin mode and a thick mode that needs the "Oracle
Instant Client".

In order to fully replace `cx_Oracle`, `oracledb` needs to be in thick mode.
This is something we have not considered for Werk #16023.

With this Werk we now try to switch into the thick mode, and if this does not
work, we use thin mode. If you execute `check_sql` with `-v` switch you will see
a message if `oracledb` could not switch into thick mode.

`oracledb` searches for the "Oracle Instant Client" in several standard location.
`check_sql` will find the installation if the files (among other things `*.so`
and `*.jar`) from the "Oracle Instant Client" files are directly in
`~local/lib/` in your site.
13 changes: 13 additions & 0 deletions active_checks/check_sql
Original file line number Diff line number Diff line change
Expand Up @@ -282,6 +282,19 @@ def oracle_connect(host: str, port: int, db_name: str, user: str, pwd: str) -> A
except ImportError as exc:
bail_out(3, "%s. Please install it via 'pip install oracledb'." % exc)

try:
oracledb.init_oracle_client()
except oracledb.DatabaseError as dbe:
# this seems to be the official way to differentiate between exceptions:
# https://python-oracledb.readthedocs.io/en/latest/user_guide/exception_handling.html#exception
if dbe.args[0].full_code == "DPI-1047":
LOG.info(
"Could not activate thick mode, will continue and use thin mode instead. "
"https://python-oracledb.readthedocs.io/en/latest/user_guide/initialization.html#initializing-python-oracledb"
)
else:
raise

cstring = f"{user}/{pwd}@{host}:{port}/{db_name}"
return oracledb.connect(cstring)

Expand Down

0 comments on commit 6537732

Please sign in to comment.