Cacti / cacti

Cacti ™
http://www.cacti.net
GNU General Public License v2.0
1.63k stars 404 forks source link

When a Data Query has a space, indexes may not be properly escaped #5768

Closed prottoy396 closed 3 months ago

prottoy396 commented 4 months ago

Describe the bug Mikrotik Queue Traffic dont show in graph (also real time) if the Queue name has a space & ( _ ) inside

To Reproduce Steps to reproduce the behavior:

  1. Linux Cent OS 7, Tried several versions of cacti.
  2. Add a queue in mikrotik ex: XYZ ABC XY - which include space & ( ) inside the queue name
  3. Add a queue in mikrotik ex: XYZABC - which include no space & ( _ ) inside the queue name
  4. Now if I add queue graph for both queue; "XYZABC" will show traffic with no issue, Where as " XYZ ABC _ XY" will not show any data.
  5. Also I have noticed, the larger name of a queue graph, dont show the traffic, I am little confused actually, what is causing no traffic visible in queue.

Expected behavior Queue name with a space & ( _ ) should behave the same and get traffic info.

Screenshots image image image The Queue has traffic, but shows traffic_in & out 0 during troubleshoot, where another queue with no space always getting some value here instead of 0 always image

image Notice the RED and Green mark, I am pretty confused is it facing issue showing graph for the Queue Name which is a "larger name" or "Space and Special Character" in queue name. All these three queue has traffic in mikrotik, but only the smaller name maybe showing graph value in cacti, please check this bug

Plugin (please complete the following information):

Desktop (please complete the following information):

Additional context I am facing a issue for long. I have installed cacti 1.2.24 and 1.2.27 in a Cent OS 7 server. Tried installing each mikrotik plugin version on each server. My problem is

When I can creating any graph for Mikrotik Queue, it gets data if the Queue name has no (space & ( ) ) inside, but if there is any space & ( ) in the Queue name, there i got no graph at all in 5 min or 1 min even in real time. everything works fine with the queue name not having space & ( _ ).

Please suggest me what can i do now, already checked from several Mikrotik, tried to install several version of cacti and mikrotik plugin also.

TheWitness commented 3 months ago

Can you show the poller cache for the entries with the space. Post the image here.

Also, search the table "graph_local" for the "snmp_index" with the queue name and confirm that it includes the space.

TheWitness commented 3 months ago

Example poller cache entries:

image

prottoy396 commented 3 months ago

image image image

Mikrotik Real time - there is traffic image

Here what I am getting difference is CAPITAL and SMALL Letter, also this queue has no space - Still getting no graph, debug is also attached.

And I didnt get this - Also, search the table "graph_local" for the "snmp_index" with the queue name and confirm that it includes the space....

TheWitness commented 3 months ago

Reindex the device. It should fix the issue. It's a good thing to schedule reindexed periodically to pick up changes that are not uptime related.

prottoy396 commented 3 months ago

I have already done it from edit Device > Reindex

Didn't solved

TheWitness commented 3 months ago

Okay, interesting.

TheWitness commented 3 months ago

What is stored in the queues table?

prottoy396 commented 3 months ago

You mean mysql data table?

TheWitness commented 3 months ago

Yes. So, I think I know this is happening, and the workaround is no longer required. I'll propose a change in the next day or so. I just need to find enough time to write it.

prottoy396 commented 3 months ago

okay then, I am waiting 🫡

TheWitness commented 3 months ago

MikroTik_Device.xml.gz

Here is the updated Device Template. The files of interest are:

ss_mikrotik_interfaces.php ss_mikrotik_qtrees.php ss_mikrotik_queues.php

Everything else should be default. You should re-index as soon as you update the Device Package. Also, the Data Sources for the Objects that include spaces will need to be Edited and you will have to manually update the Index Value when editing the Data Sources for those with a space.

prottoy396 commented 3 months ago

I have downloaded the New Template to cacti/plugin/mikrotik/templete/ and imported it from cacti/cli/ > php import_package.php MikroTik_Device.xml.gz

Then I deleted the old graph, reindexed the device with verify all - then added the graph again. But getting null value yet, Sharing DataSRC debug and graph with Mikrotik Queue Live status.. If I am missing anything?

image image

TheWitness commented 3 months ago

Upload an image of the polar cache entries.

prottoy396 commented 3 months ago

image

Note : You may find the QsName diff, cause I have shorted it to give a try. This should be a issue I guess, I have deleted old graph, deleted that row from SQL table (plugin_mikrotik_queue), then Reindexed and added graph for the Brand new Short Name.

I notice that there is space in Data src name, Do I have to remote it?

TheWitness commented 3 months ago

There should be a space. The question is, is data streaming into the rrdfile?

prottoy396 commented 3 months ago

If I update a QueueName from Mikrotik, I need to manually delete the data from SQL plugin_mikrotik_queue, then re-index can bring the new QueueName, othewise it get duplicated in data query table from Device-Mikrotik Queue Traffic

TheWitness commented 3 months ago

I also need to review the data collectors themselves too.

TheWitness commented 3 months ago

Did the database entry not include the space? If so, I need to update the collector too.

prottoy396 commented 3 months ago

image

image

prottoy396 commented 3 months ago

Did the database entry not include the space? If so, I need to update the collector too.

Database entry also have the space image

TheWitness commented 3 months ago

I don't see a space there. I see underscores.

prottoy396 commented 3 months ago

You can try to zoom in, there is a space after _ EDxxx

TheWitness commented 3 months ago

Okay good. Can you test the script output? Go to the documentation and lookup testing the script server and follow those instructions. Let's see what output it generates.

prottoy396 commented 3 months ago

Maybe I am confused about which documentation you are talking about, I have already search for it but no luck. Can you please share the document reference here, I will check further

prottoy396 commented 3 months ago

Am I doing the right? image

prottoy396 commented 3 months ago

See What I found, I have added " " around the Queue name border and its getting value now. Any Line with space is working after I am adding the "". Maybe editing the code can solve it for good, There will be no Space/Special Character combination issue anymore

Actually the script is dividing the Single Queue name to Separate name due to Space.

image

TheWitness commented 3 months ago

Am I doing the right? image

Yes, this is correct. This tells us that the reindex is causing an issue. So, that's in the three scripts. I'll look again into it today.

TheWitness commented 3 months ago

See What I found, I have added " " around the Queue name border and its getting value now. Any Line with space is working after I am adding the "". Maybe editing the code can solve it for good, There will be no Space/Special Character combination issue anymore

Actually the script is dividing the Single Queue name to Separate name due to Space.

image

You should not have to do this ..

prottoy396 commented 3 months ago

Am I doing the right? image

Yes, this is correct. This tells us that the reindex is causing an issue. So, that's in the three scripts. I'll look again into it today.

Great!!! I will be waiting

TheWitness commented 3 months ago

Okay, I've tracked this one down. Transferring to a Cacti Issue, and I will be renaming it. If you are at 1.2.27, there are 4 files to update. Thanks for pushing me to get this resolved. I'm also removing the upper case conversion for the Queue Names, but separately.

TheWitness commented 3 months ago

@prottoy396, the issue is fixed now. Update and don't forget to re-populate the poller cache.

prottoy396 commented 3 months ago

@prottoy396, the issue is fixed now. Update and don't forget to re-populate the poller cache.

Yet its solved now, Working fine here too. Cheers 🍻