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

Help needed for error: no module named 'mysql'

Could anyone help me with this error?

 

RodrigoBiaggio_0-1633103452931.png

 

 

import mysql.connector
from mysql.connector import Error
import requests
from ruxit.api.base_plugin import RemoteBasePlugin
import logging

class PluginDBQuerySQL(RemoteBasePlugin):
def initialize(self, **kwargs):
logger.info("Config: %s", self.config)
self.url = self.config["url"]

try:
con = mysql.connector.connect(host='localhost', database='database', user='biaggio', password='')

consulta_sql = "select * from database.tb_activegate"
cursor = con.cursor()
cursor.execute(consulta_sql)
linhas = cursor.fetchall()
totalLinhas = cursor.rowcount

def query(self, **kwargs😞
#Create topology
url = self.url + "/topology"
topology = requests.get(url).json()
for group_t in topology:
group_name = group_t['name']
group = self.topology_builder.create_group(group_name, group_name)
for device_t in group_t['devices']:
device_name = device_t['name']
device = group.create_device(device_name, device_name)
logger.info("Topology: group name=%s, device name=%s", group.name, device.name)
#Collect stats
stats = device_t['stats']
device.absolute(key='totalLinhas', value=stats['counter'])

except Error as e:
print("Erro ao acessar tabela", e)
finally:
if (con.is_connected()):
con.close()
cursor.close()
print("Conexao fechada")



 

Dynatrace Professional
3 REPLIES 3

Mike_L
Dynatrace Guru
Dynatrace Guru

How does the install_requires look like in the plugin.json and are you building the extension with oneagent_build_plugin?

Mike

Mike

Hi @Mike_L 

 

I put the: 

"install_requires": [
"mysql-connector"

 Now it's OK for mysql, but now it returns the message to the logger module.

 

RodrigoBiaggio_0-1633108438108.png

 

I'm making the plugin with the activegate SDK

Dynatrace Professional

You never initiated a variable that you're using in your script. Did you mean to add

logger = logging.getLogger(__name__)

maybe?

Mike

Featured Posts