Summary: This thread explains how to resolve the “No module named cx_Oracle” error in Dynatrace extensions. It includes installation steps and compatibility considerations for Oracle database monitoring.
Hello can anyone help me with this error? I’ve already imported the package, but I’m still getting this message.
Python
<span>import </span>logging<br><span>import </span>cx_Oracle<br><br><span>from </span>ruxit.api.base_plugin <span>import </span>RemoteBasePlugin<br><br>logger = logging.getLogger(__name__)
Json
<span>"install_requires"</span><span>: </span>[<br> <span>"cx_Oracle"</span><span>,</span><span><br></span> <span>"requests>=2.6.0"<br></span>]<span>,</span>
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.
It is installed.
I believe the problem is that the plugin is being built using a newer version. It’s getting cached.
To no avail the change. That wasn’t the problem with the version. It is in the same version and the problem remains.
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.
{<br> <span>"name"</span><span>: </span><span>"custom.remote.python.integracao_interna_cc"</span><span>,<br></span> <span>"version"</span><span>: </span><span>"1.22"</span><span>,<br></span> <span>"type"</span><span>: </span><span>"python"</span><span>,<br></span> <span>"entity"</span><span>: </span><span>"CUSTOM_DEVICE"</span><span>,<br></span> <span>"metricGroup"</span><span>: </span><span>"tech.python.integracao_interna_cc"</span><span>,<br></span> <span>"technologies"</span><span>: </span>[<br> <span>"Python"<br></span> ]<span>,<br></span> <span>"favicon"</span><span>: </span><span>"https://jocumpr.com.br/wp-content/uploads/2021/08/logo-pix-icone-1024.png"</span><span>,<br></span> <span>"source"</span><span>: </span>{<br> <span>"package"</span><span>: </span><span>"custom_remote_python_integracao_interna_conta"</span><span>,<br></span> <span>"className"</span><span>: </span><span>"IntegracaoInternaCC"</span><span>,<br></span> <span>"install_requires"</span><span>: </span>[<br> <span>"cx-Oracle"</span><span>,<br></span> <span>"requests>=2.6.0"<br></span> ]<span>,<br></span> <span>"activation"</span><span>: </span><span>"Remote"<br></span> }<span>,<br></span> <span>"configUI"</span><span>: </span>{<br> <span>"displayName"</span><span>: </span><span>"Filas Oracle AQ - Integração Interna CC"<br></span> }<span>,<br></span> <span>"ui"</span><span>: </span>{<br> <span>"keymetrics"</span><span>: </span>[<br> {<br> <span>"key"</span><span>: </span><span>"total_lancamentos_export_jsm"</span><span>,<br></span> <span>"aggregation"</span><span>: </span><span>"max"</span><span>,<br></span> <span>"mergeaggregation"</span><span>: </span><span>"sum"</span><span>,<br></span> <span>"displayname"</span><span>: </span><span>"Integração Interna CC - Total"<br></span> }<span>,</span>
Do I need to put some lib in my plugin directory to build together?
@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
{
"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
November 30, 2021, 5:56pm
9
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.
I understand that the error is in my code.
<span>import </span>logging<br><span>import </span>cx_Oracle<br><span>import </span>os<br><span>from </span>ruxit.api.base_plugin <span>import </span>RemoteBasePlugin<br>logger = logging.getLogger(__name__)<br><br><span>class </span>IntegracaoInternaCC(RemoteBasePlugin):<br><br> <span>def </span><span>query</span>(<span>self</span><span>, </span>**kwargs):<br><br> <span>global </span>con<span>, </span>total_lancamentos_export_jsm<span>, </span>state_integracao_interna_cc<br><br> state_integracao_interna_cc = <span>0.0<br></span> status_ok = <span>"OK"<br></span> status_notok = <span>"Bad"<br></span> <span>try</span>:<br> con = cx_Oracle.connect(<span>user</span>=<span>""</span><span>, </span><span>password</span>=<span>""</span><span>, </span><span>dsn</span>=<span>""</span>)<br> cursor = con.cursor()<br> <span>print</span>(<span>"Successfully connected to Oracle Database"</span>)<br> consulta_sql = <span>"select count(1) from cc_qcc_lanc_export_jms s where state <> 3;"<br></span> cursor.execute(consulta_sql)<br> resultado_query = (cursor.fetchall())<br><br> <span>for </span>linha <span>in </span>resultado_query:<br> total_lancamentos_export_jsm = (linha[<span>0</span>])<br> <span>print</span>(<span>"Total Registros"</span><span>, </span>total_lancamentos_export_jsm)<br><br> <span>if </span>total_lancamentos_export_jsm == <span>0</span>:<br> state_integracao_interna_cc = status_ok<br> <span>print</span>(<span>"Status:"</span><span>, </span>state_integracao_interna_cc)<br> <span>else</span>:<br> state_integracao_interna_cc = status_notok<br> <span>print</span>(<span>"Status:"</span><span>, </span>state_integracao_interna_cc)<br><br> group = <span>self</span>.topology_builder.create_group(<span>"Filas AQ"</span><span>, </span><span>"Filas AQ"</span>)<br> device = group.create_element(<span>"Integração Conta Corrente"</span><span>, </span><span>"Integração Conta Corrente"</span>)<br> group.report_property(<span>key</span>=<span>"Desenvolvedor"</span><span>, </span><span>value</span>=<span>"Rodrigo Biaggio"</span>)<br> group.report_property(<span>key</span>=<span>"Secondary technology"</span><span>, </span><span>value</span>=<span>"Oracle"</span>)<br> group.report_property(<span>key</span>=<span>"Integrações"</span><span>, </span><span>value</span>=<span>"AWS"</span>)<br> group.report_property(<span>key</span>=<span>"Descrição"</span><span>, </span><span>value</span>=<span>"Filas Oracle AQ - Conta e Standin"</span>)<br> device.report_property(<span>key</span>=<span>"Integrações"</span><span>, </span><span>value</span>=<span>"AWS"</span>)<br> device.report_property(<span>key</span>=<span>"Technology"</span><span>, </span><span>value</span>=<span>"Python"</span>)<br> device.add_endpoint(<span>ip</span>=<span>""</span><span>, </span><span>port</span>=<span>3306</span><span>, </span><span>dnsNames</span>=[<span>""</span>])<br> device.relative(<span>key</span>=<span>'total_lancamentos_export_jsm'</span><span>, </span><span>value</span>=total_lancamentos_export_jsm)<br> group.absolute(<span>key</span>=<span>'total_lancamentos_export_jsm'</span><span>, </span><span>value</span>=total_lancamentos_export_jsm)<br> device.state_metric(<span>key</span>=<span>'state_integracao_interna_cc'</span><span>, </span><span>value</span>=state_integracao_interna_cc)<br><br> <span>except </span>cx_Oracle.DatabaseError <span>as </span>e:<br> <span>print</span>(<span>"Erro ao acessar tabela"</span><span>, </span>e)<br><br> <span>finally</span>:<br> con.close()<br> <span>print</span>(<span>"Conexão ao banco encerrada"</span>)
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.
Mike_L
November 30, 2021, 8:20pm
12
Hi,
dtuserag. You can do a oneagent_sim with sudo -u, that sometimes points out access issues.
Mike_L
November 30, 2021, 8:23pm
13
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.
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
ERROR
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
Mike_L
December 8, 2021, 9:25am
15
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 ,
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?
Mike_L
December 8, 2021, 12:33pm
17
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
@Mike_L Or some log that I can check if it was applied or the current parameter return.
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.