Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tree Search Does Not Properly Search All Trees #4849

Closed
browniebraun opened this issue Jun 29, 2022 · 8 comments
Closed

Tree Search Does Not Properly Search All Trees #4849

browniebraun opened this issue Jun 29, 2022 · 8 comments
Labels
bug Undesired behaviour confirmed Bug is confirm by dev team resolved A fixed issue tree Issues related to the graph tree
Milestone

Comments

@browniebraun
Copy link
Member

Describe the bug

We are using a global, script generated tree with following schema:

World
-> region
-> country
-> state
-> city
-> site
-> Cacti Device Type
-> Device

First off, the search will find matching objects. It doesn't matter if it is part of the device, site or city name, BUT
all elements belonging to a matching items will not be available in most cases.

Example:

You search for "Dear" and Cacti builds following tree:
->World
-> North America
-> US
-> Michigan
-> Dearborn

Leaf sites and assigned device types and devices are not part of the result. Matching City name "Dearborn" is not clickable and does not allow to load underlying elements with another call.

@browniebraun browniebraun added bug Undesired behaviour unverified Some days we don't have a clue labels Jun 29, 2022
@browniebraun
Copy link
Member Author

v.1.2.22

@TheWitness
Copy link
Member

@browniebraun did this work before? Any Javascript errors?

@TheWitness
Copy link
Member

I'm seeing a similar issue.

@TheWitness
Copy link
Member

You might want to upload an animation screen2gif @browniebraun

@TheWitness TheWitness changed the title Tree Search insufficient Tree Search Does Not Properly Search All Trees Jun 30, 2022
TheWitness added a commit that referenced this issue Jun 30, 2022
Tree Search does not properly search all Trees
@TheWitness TheWitness added this to the v1.2.22 milestone Jun 30, 2022
@TheWitness TheWitness added resolved A fixed issue tree Issues related to the graph tree confirmed Bug is confirm by dev team and removed unverified Some days we don't have a clue labels Jun 30, 2022
@browniebraun
Copy link
Member Author

browniebraun commented Jul 1, 2022

@TheWitness
Hi Larry,
Sorry for my late response. I have just found some time to review the updated SQL query and did a few test runs. From my point of view it has to be changed as shown below:

                $matching = db_fetch_assoc_prepared("SELECT gti.parent, gti.graph_tree_id
                        FROM graph_tree_items AS gti
                        LEFT JOIN host AS h
                        ON h.id = gti.host_id
                        LEFT JOIN graph_templates_graph AS gtg
                        ON gtg.local_graph_id = gti.local_graph_id
                        LEFT JOIN sites AS s
                        ON s.id = gti.site_id
                        WHERE (gtg.local_graph_id > 0 AND gtg.title_cache LIKE ?)
                        OR (h.description LIKE ? AND gti.host_id > 0)
                        OR (h.hostname LIKE ? AND gti.host_id > 0)
                        OR (gti.title LIKE ?)
                        OR (s.name LIKE ? AND gti.site_id > 0)
                        GROUP BY gti.parent, gti.graph_tree_id",
                        array($filter, $filter, $filter, $filter, $filter));

Your query did not work for me, but maybe I'm generating the tree with over 5000 items not correctly in my script.
I'm setting the site_id in table graph_tree_items, too.
Building a concatenated LEFT JOIN of sites and host table will exclude all sites automatically where hosts not matching and not deliver the correct results.

In my case instead of h.site_id, gti.site_id should be used for the JOIN statement with sites and a GROUP BY afterwards to get rid of the duplicates.

This is working faultlessly for my environment.

Regards
-Andi

@browniebraun
Copy link
Member Author

browniebraun commented Jul 1, 2022

Addendum:

  • Matching Sites are clickable, but cannot be opened like folders to show assigned host types and hosts belonging to a site.
  • A search pattern should have a minimum of 3 characters before being triggered or the trigger delay in JS has to be increased. On huge environments you are faced with timeouts if a search has been fired forcing Cacti to search for a singe character everywhere. This happens if you are too slow in pressing the delete button like I'm. ;)

@TheWitness
Copy link
Member

Commit it then. But make sure the other route works too.

@TheWitness
Copy link
Member

Addendum:

  • Matching Sites are clickable, but cannot be opened like folders to show assigned host types and hosts belonging to a site.
  • A search pattern should have a minimum of 3 characters before being triggered or the trigger delay in JS has to be increased. On huge environments you are faced with timeouts if a search has been fired forcing Cacti to search for a singe character everywhere. This happens if you are too slow in pressing the delete button like I'm. ;)

This is likely due to the site oriented tree logic. Commit you changes and then I can have a look or keep working through it.

TheWitness added a commit that referenced this issue Jul 6, 2022
- Change the query to be more inclusive
- Use sub-queries for performance
- Start at 3 characters
- Don't show 'only' results to allow proper site navigation
@github-actions github-actions bot locked and limited conversation to collaborators Nov 28, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Undesired behaviour confirmed Bug is confirm by dev team resolved A fixed issue tree Issues related to the graph tree
Projects
None yet
Development

No branches or pull requests

2 participants