cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

No module named 'cx_Oracle'

hello can anyone help me with this error? I've already imported the package, but I'm still getting this message.

python

import logging
import cx_Oracle

from ruxit.api.base_plugin import RemoteBasePlugin

logger = logging.getLogger(__name__)

 

json

"install_requires": [
"cx_Oracle",
"requests>=2.6.0"
],

 

Dynatrace Professional
22 REPLIES 22

you may install the module. I just did and was able to run a plugin with the requirement.

 

pip install cx_Oracle

I already installed this module, but the error persists.

 

RodrigoBiaggio_1-1638195755862.png

 

RodrigoBiaggio_2-1638199395807.png

It is installed.

I believe the problem is that the plugin is being built using a newer version. It's getting cached.

Dynatrace Professional

To no avail the change. That wasn't the problem with the version. It is in the same version and the problem remains.

Dynatrace Professional

even, from within the gateway I can run a test script and it connects to the bank, so it's not a problem with the package. Everything is installed. I don't understand what is missing from my script, that Dynatrace is not understanding that the module exists.

 



{
"name": "custom.remote.python.integracao_interna_cc",
"version": "1.22",
"type": "python",
"entity": "CUSTOM_DEVICE",
"metricGroup": "tech.python.integracao_interna_cc",
"technologies": [
"Python"
],
"favicon": "https://jocumpr.com.br/wp-content/uploads/2021/08/logo-pix-icone-1024.png",
"source": {
"package": "custom_remote_python_integracao_interna_conta",
"className": "IntegracaoInternaCC",
"install_requires": [
"cx-Oracle",
"requests>=2.6.0"
],
"activation": "Remote"
},
"configUI": {
"displayName": "Filas Oracle AQ - Integração Interna CC"
},
"ui": {
"keymetrics": [
{
"key": "total_lancamentos_export_jsm",
"aggregation": "max",
"mergeaggregation": "sum",
"displayname": "Integração Interna CC - Total"
},

Do I need to put some lib in my plugin directory to build together?

 

Dynatrace Professional

@tibebe_m_digafe , Hi. Can you help with this? You mentioned that you ran your script and it worked. Is it possible for you to share this configuration?
Thank you

 
Dynatrace Professional

{
  "name": "custom.remote.python.oracle",
  "version": "1.0.0",
  "type": "python",
  "entity": "CUSTOM_DEVICE",
  "metricGroup": "tech.oracle",
  "technologies": ["PYTHON"],
  "install_requires": [
    "cx_Oracle",
    "requests>=2.6.0"
  ],
  "source": {
    "package": "oracle_plugin",
    "className": "Oracle",
    "activation": "Remote"
  },
  "ui" : {
    "keycharts" : [
    ],
    "charts" : [
    ]
  },
  "metrics": [
  ],
  "properties" : [
  ],
  "configUI": {
  }
}

using Python 3.6.12

installed packages

pip list
Package            Version
------------------ -------------------------
attrs              21.2.0
boto3              1.18.44
botocore           1.21.44
bottle             0.12.19
certifi            2021.5.30
cffi               1.14.6
charset-normalizer 2.0.6
check-tls-certs    0.12.0
click              8.0.1
colorama           0.4.4
cryptography       3.4.8
cx-Oracle          8.3.0
idna               3.2
importlib-metadata 4.8.1
jmespath           0.10.0
jsonschema         3.2.0
pip                21.2.4
plugin-sdk         1.223.105.20210824.140926
pycparser          2.20
pyOpenSSL          20.0.1
pyrsistent         0.18.0
python-dateutil    2.8.2
requests           2.26.0
s3transfer         0.5.0
setuptools         28.8.0
six                1.16.0
typing-extensions  3.10.0.2
urllib3            1.26.6
wheel              0.29.0
zipp               3.5.0

Mike_L
Dynatrace Champion
Dynatrace Champion

Hi, can you make sure that you're running oneagent_build_plugin with Python 3.6 64-bit? That way it'll download the correct binaries.

Mike



Good afternoon people!!

I have the correct version (3.6), I also have all these libraries installed.

Also, I installed oracle client on the server.

I can connect to the database if I access python directly from the prompt, making an import in cx_Oracle.

RodrigoBiaggio_0-1638302537423.png

RodrigoBiaggio_1-1638302599944.png


I understand that the error is in my code.

import logging
import cx_Oracle
import os
from ruxit.api.base_plugin import RemoteBasePlugin
logger = logging.getLogger(__name__)

class IntegracaoInternaCC(RemoteBasePlugin):

def query(self, **kwargs):

global con, total_lancamentos_export_jsm, state_integracao_interna_cc

state_integracao_interna_cc = 0.0
status_ok = "OK"
status_notok = "Bad"
try:
con = cx_Oracle.connect(user="", password="", dsn="")
cursor = con.cursor()
print("Successfully connected to Oracle Database")
consulta_sql = "select count(1) from cc_qcc_lanc_export_jms s where state <> 3;"
cursor.execute(consulta_sql)
resultado_query = (cursor.fetchall())

for linha in resultado_query:
total_lancamentos_export_jsm = (linha[0])
print("Total Registros", total_lancamentos_export_jsm)

if total_lancamentos_export_jsm == 0:
state_integracao_interna_cc = status_ok
print("Status:", state_integracao_interna_cc)
else:
state_integracao_interna_cc = status_notok
print("Status:", state_integracao_interna_cc)

group = self.topology_builder.create_group("Filas AQ", "Filas AQ")
device = group.create_element("Integração Conta Corrente", "Integração Conta Corrente")
group.report_property(key="Desenvolvedor", value="Rodrigo Biaggio")
group.report_property(key="Secondary technology", value="Oracle")
group.report_property(key="Integrações", value="AWS")
group.report_property(key="Descrição", value="Filas Oracle AQ - Conta e Standin")
device.report_property(key="Integrações", value="AWS")
device.report_property(key="Technology", value="Python")
device.add_endpoint(ip="", port=3306, dnsNames=[""])
device.relative(key='total_lancamentos_export_jsm', value=total_lancamentos_export_jsm)
group.absolute(key='total_lancamentos_export_jsm', value=total_lancamentos_export_jsm)
device.state_metric(key='state_integracao_interna_cc', value=state_integracao_interna_cc)

except cx_Oracle.DatabaseError as e:
print("Erro ao acessar tabela", e)

finally:
con.close()
print("Conexão ao banco encerrada")



Dynatrace Professional

It's failing on this line:

con.close()

because the connection cannot be created with empty connection parameters.

You can set it to None first and then check for None before trying to close the connection.

What user does the plugin run as? dtuserag, dtuser? If the plugin is run with any of these users it can justify not finding the oracle lib.

Dynatrace Professional

Hi,

dtuserag. You can do a oneagent_sim with sudo -u, that sometimes points out access issues.

Hi @Mike_L @tibebe_m_digafe 

 

I'm still trying to get the plugin to work.

I've already run simulate_plugin and it works. The problem occurs when deploying to Dynatrace.

 

At first, it was returning a message that the cx_Oracle module did not exist. I redid all the installation of gateway, SDK and Oracle client. Now, even though everything works fine inside the OS, when I deploy, it returns a message that the Oracle LIB was not found.

 

I put in my code to return the Oracle environment variables and also the LD_LIBRARY_PATH and the return is none, that is, it is not finding the variable.

 

SIMULATE_PLUGIN OK

RodrigoBiaggio_0-1638926514937.png

 

ERROR

RodrigoBiaggio_1-1638926547613.png

 

What is causing me confusion is the fact that my user has the variables, and dtuserag is not a user with bash, it doesn't login.

Which user does Dynatrace use, root or
the dtuserag? These variables must be defined for which users?

 

Thank you

 

Dynatrace Professional

Hi, Extensions run as dtuserag. The LD_LIBRARY_PATH needs to be present before the remote plugin module starts up. You can do this by adding

Environment=LD_LIBRARY_PATH=/path_to_accessible_libraries/oracle

Inside the [Service] section of the Remote Plugin Module service script. By default it is located at /etc/systemd/system/remotepluginmodule.service

Mike

@Mike_L , 

RodrigoBiaggio_0-1638966139119.png

RodrigoBiaggio_1-1638966268012.png

Hi, thanks for your reply.

I put all these two ways in, but it didn't work.

I also stopped / started the process

Is that correct, is it either of these two ways?

Dynatrace Professional

Hi,

It's the first one. Does the dtuserag have full access to that folder?

Mike

Yes, the user has access.

Mike, I'm stopping/starting the dynatrace service, running systemctl status dynatracegateway

Would that be enough for the module to load the path? I'm doing the restart and nothing happens. Is it possible for me to restart only the extension module?


Thank you


Dynatrace Professional

@Mike_L Or some log that I can check if it was applied or the current parameter return.

Dynatrace Professional

I did a test by changing the user from dtuserag to root. I restarted the Dynatrace service and it didn't reflect. In my code it still points out that the plugin is running with dtuserag.

 

RodrigoBiaggio_0-1638988660128.png

 

RodrigoBiaggio_1-1638988676885.png

 

Dynatrace Professional

The user needs to be set during installation using the USER parameter. The service to restart is remotepluginmodule.service

Okay Mike. The problem was solved.

What you suggested was correct, I hadn't done one of the steps, which is systemctl daemon-reload

after that, my plugin is OK.

Thank you very much for your help in this case.

Dynatrace Professional

No worries. You picked one of the most complicated libraries to use with an extension. It took quite some time for us to figure out how to use it correctly so don't be discouraged.