27 Oct 2021 05:35 PM - last edited on 19 Nov 2021 11:13 AM by MaciejNeumann
Guys, can anyone support me to understand the reason for these messages in my log, my plugin?
{
"name": "custom.remote.python.dict_cancelar_portabilidade",
"version": "1.00",
"type": "python",
"entity": "CUSTOM_DEVICE",
"metricGroup": "tech.python.cancelar.portabilidade",
"technologies": [
"Python"
],
"favicon": "https://jocumpr.com.br/wp-content/uploads/2021/08/logo-pix-icone-1024.png",
"source": {
"package": "custom_remote_python_cancelar_portabilidade_dict",
"className": "PluginPythonMySQL",
"install_requires": [
"mysql-connector",
"requests>=2.6.0"
],
"activation": "Remote"
},
"metrics": [
{
"entity": "CUSTOM_DEVICE",
"statetimeseries": {
"key": "count",
"states": ["OK", "Bad"],
"dimensions": [],
"unit": "Count",
"displayname": "Cancelar Portabilidade - Atraso"
}
}
],
"configUI": {
"displayName": "Cancelar Portabilidade - Atraso"
},
"ui": {
"keymetrics" : [
{
"key": "count",
"displayname": "",
"statemetric": true
}
],
"charts": [
{
"group": "Cancelar Portabilidade - Atraso",
"title": "Status Cancelamentos de Portabilidade",
"series": [
{
"key": "count",
"displayname": " ",
"seriestype": "bar",
"statecolors": ["#49b675", "#ff0000"],
"statechart": true
}
]
}
]
}
}
import mysql.connector
from mysql.connector import Error
from ruxit.api.base_plugin import RemoteBasePlugin
import logging
logger = logging.getLogger(__name__)
class PluginPythonMySQL(RemoteBasePlugin):
def query(self, **kwargs):
global cursor, con
resultado = "0"
statusOK = "OK"
statusNOTOK = "Bad"
try:
con = mysql.connector.connect(host='',
database='', user='', password='')
consulta_sql = ""
cursor = con.cursor()
cursor.execute(consulta_sql)
count = len(cursor.fetchall())
print(count)
if count == 0:
resultado = statusOK
print(resultado)
else:
resultado = statusNOTOK
print(resultado)
group = self.topology_builder.create_group("ANS DICT", "ANS DICT")
device = group.create_element("Cancelar Portabilidade - Atraso", "Cancelar Portabilidade - Atraso")
group.report_property(key="Versão Plugin", value="1.00")
group.report_property(key="Desenvolvedor", value="Rodrigo Biaggio")
group.report_property(key="Others Technologys", value="MySQL")
group.report_property(key="Serviço", value="Pix")
device.report_property("Database Name", "addressing")
device.report_property("Descrição", "Atraso no cancelamento de portabilidade")
device.add_endpoint("", 3306)
device.relative("resultado", 1)
group.absolute(key='count', value=count)
device.state_metric("count", resultado)
except Error as e:
print("Erro ao acessar tabela", e)
finally:
con = mysql.connector.connect(host='',
database='', user='', password='')
cur = con.cursor()
if con.is_connected():
con.close()
cur.close()
print("Coleta efetuada e conexão fechada")
Thanks
Solved! Go to Solution.
27 Oct 2021 10:37 PM
Not sure if it might be the only problem, but I would say that for the following line
device.relative("resultado", 1)
you have to define "resultado" in the json file.
28 Oct 2021 05:06 PM
@AntonioSousa, thanks but i have the metric inside my json. I believe this point is related to the fact that I don't see the data on my device.
28 Oct 2021 08:19 PM
I was referring to the first block that you posted, and that I suppose it's the json you are referring to? Because "resultado" is not defined there.
28 Oct 2021 08:32 PM
Sorry @AntonioSousa, I've already changed this json. Here is the correct one.
{
"name": "custom.remote.python.sincronismo_dict",
"version": "1.00",
"type": "python",
"entity": "CUSTOM_DEVICE",
"metricGroup": "tech.python.sincronismo.dict",
"technologies": [
"Python"
],
"favicon": "https://jocumpr.com.br/wp-content/uploads/2021/08/logo-pix-icone-1024.png",
"source": {
"package": "custom_remote_python_sincronismo",
"className": "Sincronismo",
"install_requires": [
"mysql-connector",
"requests>=2.6.0"
],
"activation": "Remote"
},
"configUI": {
"displayName": "DICT - Sincronismo"
},
"ui": {
"keymetrics": [
{
"key": "count",
"aggregation": "max",
"mergeaggregation": "sum",
"displayname": "Sincronismo"
},
{
"key": "resultado",
"displayname": "Status",
"statemetric": true
}
],
"keycharts": [
{
"group": "Status",
"title": "Status",
"series": [
{
"key": "resultado",
"displayname": "Status",
"seriestype": "bar",
"statecolors": [
"#00b33c",
"#ff3333"
],
"statechart": true
}
]
},
{
"group": "Sincronismo",
"title": "Sincronismo",
"series": [
{
"key": "count",
"displayname": "Total Atrasados",
"seriestype": "area",
"color": "#74cff7"
}
]
}
]
},
"metrics": [
{
"statetimeseries": {
"key": "resultado",
"states": [
"OK",
"Bad"
],
"displayname": "Status Sincronismo"
},
"entity": "CUSTOM_DEVICE"
},
{
"timeseries": {
"key": "count",
"unit": "Count",
"displayname": "Total Sincronismo",
"aggregation": "MAX"
},
"entity": "CUSTOM_DEVICE_GROUP",
"alert_settings": [
{
"alert_id": "custom_claim_alert",
"event_type": "ERROR_EVENT",
"event_name": "Existem Sincronismos em Atraso!!",
"description": "The {metricname} of {severity} is {alert_condition} the threshold of {threshold}",
"threshold": 0,
"alert_condition": "ABOVE",
"samples": 5,
"violating_samples": 1,
"dealerting_samples": 5
}
]
}
]
}
29 Oct 2021 12:30 AM
So, I believe the error remains the same?
In my code, I normally use it like this:
device.relative(key='resultado', value=1)
29 Oct 2021 01:34 PM
Yes, the same error. There is an problem in my code, I need to try to find out where it is.
There are some graphics that are not being populated. It must have some relationship.