@cryptotaxi247 / netdata-1 / commits / 0ee3d48d9

Python Dependency Migration - OracleDB Python Module (#15074)

Co-authored-by: Ilya Mashchenko <ilya@netdata.cloud>

Eric Andrechek committed May 22, 2023 at 16:14 UTC 0ee3d48d9367762709738b3f419f53c84dcc7750
3 files changed +39 -32
collectors/python.d.plugin/oracledb/README.md
+5 -10
@@ -13,8 +13,7 @@ Monitors the performance and health metrics of the Oracle database.
13
14 ## Requirements
15
16 -- `cx_Oracle` package.
17 -- Oracle Client (using `cx_Oracle` requires Oracle Client libraries to be installed).
16 +- `oracledb` package.
17
18 It produces following charts:
19
@@ -53,18 +52,13 @@ It produces following charts:
52
53 To use the Oracle module do the following:
54
56 -1. Install `cx_Oracle` package ([link](https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html)).
55 +1. Install `oracledb` package ([link](https://python-oracledb.readthedocs.io/en/latest/user_guide/installation.html)).
56
58 -2. Install Oracle Client libraries
59 - ([link](https://cx-oracle.readthedocs.io/en/latest/user_guide/installation.html#install-oracle-client)).
60 -
61 -3. Create a read-only `netdata` user with proper access to your Oracle Database Server.
57 +2. Create a read-only `netdata` user with proper access to your Oracle Database Server.
58
59 Connect to your Oracle database with an administrative user and execute:
60
65 -```
66 -ALTER SESSION SET "_ORACLE_SCRIPT"=true;
67 -
61 +```SQL
62 CREATE USER netdata IDENTIFIED BY <PASSWORD>;
63
64 GRANT CONNECT TO netdata;
@@ -88,6 +82,7 @@ local:
82 server: 'localhost:1521'
83 service: 'XE'
84
85 +
86 remote:
87 user: 'netdata'
88 password: 'secret'
collectors/python.d.plugin/oracledb/oracledb.chart.py
+31 -19
@@ -8,11 +8,17 @@ from copy import deepcopy
8 from bases.FrameworkServices.SimpleService import SimpleService
9
10 try:
11 - import cx_Oracle
11 + import oracledb as cx_Oracle
12
13 - HAS_ORACLE = True
13 + HAS_ORACLE_NEW = True
14 + HAS_ORACLE_OLD = False
15 except ImportError:
15 - HAS_ORACLE = False
16 + HAS_ORACLE_NEW = False
17 + try:
18 + import cx_Oracle
19 + HAS_ORACLE_OLD = True
20 + except ImportError:
21 + HAS_ORACLE_OLD = False
22
23 ORDER = [
24 'session_count',
@@ -187,7 +193,7 @@ CHARTS = {
193 },
194 }
195
190 -CX_CONNECT_STRING = "{0}/{1}@//{2}/{3}"
196 +CX_CONNECT_STRING_OLD = "{0}/{1}@//{2}/{3}"
197
198 QUERY_SYSTEM = '''
199 SELECT
@@ -330,18 +336,24 @@ class Service(SimpleService):
336 if self.conn:
337 self.conn.close()
338 self.conn = None
333 -
334 - try:
335 - self.conn = cx_Oracle.connect(
336 - CX_CONNECT_STRING.format(
337 - self.user,
338 - self.password,
339 - self.server,
340 - self.service,
341 - ))
342 - except cx_Oracle.DatabaseError as error:
343 - self.error(error)
344 - return False
339 + if HAS_ORACLE_NEW:
340 + try:
341 + self.conn = cx_Oracle.connect(f'{self.user}/{self.password}@tcps://{self.server}/{self.service}')
342 + except cx_Oracle.DatabaseError as error:
343 + self.error(error)
344 + return False
345 + else:
346 + try:
347 + self.conn = cx_Oracle.connect(
348 + CX_CONNECT_STRING_OLD.format(
349 + self.user,
350 + self.password,
351 + self.server,
352 + self.service,
353 + ))
354 + except cx_Oracle.DatabaseError as error:
355 + self.error(error)
356 + return False
357
358 self.alive = True
359 return True
@@ -350,15 +362,15 @@ class Service(SimpleService):
362 return self.connect()
363
364 def check(self):
353 - if not HAS_ORACLE:
354 - self.error("'cx_Oracle' package is needed to use oracledb module")
365 + if not HAS_ORACLE_NEW and not HAS_ORACLE_OLD:
366 + self.error("'oracledb' package is needed to use oracledb module")
367 return False
368
369 if not all([
370 self.user,
371 self.password,
372 self.server,
361 - self.service,
373 + self.service
374 ]):
375 self.error("one of these parameters is not specified: user, password, server, service")
376 return False
collectors/python.d.plugin/oracledb/oracledb.conf
+3 -3
@@ -63,9 +63,9 @@
63 #
64 # user: username # the username for the user account. Required.
65 # password: password # the password for the user account. Required.
66 -# server: localhost:1521 # the IP address or hostname of the Oracle Database Server. Required.
66 +# server: localhost:1521 # the IP address or hostname (and port) of the Oracle Database Server. Required.
67 # service: XE # the Oracle Database service name. Required. To view the services available on your server,
68 -# run this query: `SELECT value FROM v$parameter WHERE name='service_names'`.
68 +# run this query: `select SERVICE_NAME from gv$session where sid in (select sid from V$MYSTAT)`.
69 #
70 # ----------------------------------------------------------------------
71 # AUTO-DETECTION JOBS
@@ -81,4 +81,4 @@
81 # user: 'netdata'
82 # password: 'secret'
83 # server: '10.0.0.1:1521'
84 -# service: 'XE'
\ No newline at end of file
84 +# service: 'XE'