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

Device Location drop down does not always populate correctly #5347

Closed
adilinden opened this issue Jun 2, 2023 · 13 comments
Closed

Device Location drop down does not always populate correctly #5347

adilinden opened this issue Jun 2, 2023 · 13 comments
Labels
bug Undesired behaviour confirmed Bug is confirm by dev team porting required Requires porting to develop resolved A fixed issue
Milestone

Comments

@adilinden
Copy link

adilinden commented Jun 2, 2023

Describe the bug

I am running Cacti 1.2.24.

The location table in the device form isn't populating with pre-defined values.

To Reproduce

Define different locations for different devices. Create a new device and the previously defined values won't show in the location drop down to select from.

Expected behavior

Have a choice of locations that have already been defined for other devices

Screenshots

image

Desktop (please complete the following information)

  • OS: Windows 11

  • Browser Edge

  • Version 113.0.1774.57 (Official build) (64-bit)

Smartphone (please complete the following information)

Additional context

I came across https://forums.cacti.net/viewtopic.php?t=60215 looking for a solution, it provided me some places to look for a solution. Here is what is have in the location column in my host table:

MariaDB [cacti]> SELECT location FROM host;
+---------------+
| location      |
+---------------+
|               |
| Core          |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Core          |
| Cellular Site |
| Cellular Site |
| Core          |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
| Cellular Site |
+---------------+
33 rows in set (0.000 sec)

Looking up the SQL query from the forum post it is in cacti/include/global_form.php around line 1199. It reads:

        'location' => array(
                'method' => 'drop_callback',
                'friendly_name' => __('Location'),
                'description' => __('The physical location of the Device.  This free form text can be a room, rack location, etc.'),
                'none_value' => __('None'),
                'sql' => 'SELECT DISTINCT location AS id, location AS name FROM host ORDER BY location',
                'action' => 'ajax_locations',
                'id' => '|arg1:location|',
                'value' => '|arg1:location|',
                ),

Running the SQL query on my Cacti install I get:

MariaDB [cacti]> SELECT DISTINCT location AS id, location AS name FROM host ORDER BY location;
+---------------+---------------+
| id            | name          |
+---------------+---------------+
|               |               |
| Cellular Site | Cellular Site |
| Core          | Core          |
+---------------+---------------+
3 rows in set (0.000 sec)

However the form in the UI with the modern theme does not populate with those values. Here is what I see when editing a device:

image

And this is what I see for a new device:

image

Looking at the HTML source of the page using the developer menu, I also only see the 'none' value predefine despite the SQL query returning two values in addition to the empty value.

image
@adilinden adilinden added bug Undesired behaviour unverified Some days we don't have a clue labels Jun 2, 2023
@netniV
Copy link
Member

netniV commented Jun 3, 2023

Check for any browser console level errors.

@TheWitness TheWitness added confirmed Bug is confirm by dev team and removed unverified Some days we don't have a clue labels Jun 3, 2023
TheWitness added a commit that referenced this issue Jun 3, 2023
Device form location drop down not populating
@TheWitness TheWitness added the resolved A fixed issue label Jun 3, 2023
@TheWitness TheWitness added this to the v1.2.25 milestone Jun 3, 2023
@TheWitness TheWitness changed the title Device form location drop down not populating Improve Device Location field population Jun 3, 2023
@TheWitness TheWitness added the porting required Requires porting to develop label Jun 4, 2023
@adilinden
Copy link
Author

Check for any browser console level errors.

Not seeing any errors in the browser console.

@TheWitness
Copy link
Member

Did you update to the latest changes?

@adilinden
Copy link
Author

Did you update to the latest changes?

Would it be fixed in 1.2.x branch? I tried the 1.2.x branch at initial install but wasn't able to proceed through the initial installation dialog. I instead checked out the 1.2.24 release and it worked just fine. That's why I am currently running 1.2.24 specifically.

@adilinden
Copy link
Author

adilinden commented Jun 7, 2023

Nevermind this last post. I missed to do a pull on my git checkout after switching to 1.2.x branch. The latest 1.2.x I can upgrade to just fine now.

@adilinden
Copy link
Author

adilinden commented Jun 7, 2023

Did you update to the latest changes?

I upgraded to latest in 1.2.x and it is still not populating the location field. Not for new devices nor when editing old devices. But now I am getting a server error in the console, not on page loading but when accessing the location drop down box.

image

Here is the error expanded:

image

@netniV
Copy link
Member

netniV commented Jun 8, 2023

If you check the logs tab, there will be a corresponding error at the same time. If you can provide that detail and the backtrace, that would be most useful.

@TheWitness
Copy link
Member

Yea, that's a bad error. Might be a plugin. You should disable one at a time and see if that improves things.

@TheWitness
Copy link
Member

What's you PHP version?

netniV added a commit that referenced this issue Jun 9, 2023
@netniV
Copy link
Member

netniV commented Jun 9, 2023

The error was addressed and should now work properly.

@adilinden
Copy link
Author

The error was addressed and should now work properly.

With that latest fix applied the error no longer occurs. However, the location still doesn't populate.

@adilinden
Copy link
Author

It is my understanding that I should be able to define a new value or pick an existing value from the location field. When I create a new site it pre-populates "None". I can type over "None" and provide my own value. Otherwise the location list is empty. I can only write one value into the location list, I cannot have multiple locations selected for the same single site.

My expectations is that the location dropdown list should be populated with all locations that have previously been used for any other site. For example, this is my actual list of sites and corresponding locations from the host table.

MariaDB [cacti]> select id,site_id,location from host order by location;
+----+---------+---------------+
| id | site_id | location      |
+----+---------+---------------+
|  1 |       0 |               |
| 20 |      19 | Cellular Site |
| 21 |      20 | Cellular Site |
| 22 |      21 | Cellular Site |
| 23 |      22 | Cellular Site |
| 24 |      23 | Cellular Site |
| 25 |      24 | Cellular Site |
| 27 |      25 | Cellular Site |
| 28 |       8 | Cellular Site |
| 29 |      26 | Cellular Site |
| 30 |      27 | Cellular Site |
| 31 |      28 | Cellular Site |
| 32 |      29 | Cellular Site |
| 33 |      30 | Cellular Site |
| 34 |      31 | Cellular Site |
| 19 |      18 | Cellular Site |
| 18 |      17 | Cellular Site |
| 17 |       8 | Cellular Site |
|  3 |       3 | Cellular Site |
|  4 |       4 | Cellular Site |
|  5 |       5 | Cellular Site |
|  7 |       6 | Cellular Site |
|  8 |       9 | Cellular Site |
|  9 |      10 | Cellular Site |
| 10 |      11 | Cellular Site |
| 16 |      16 | Cellular Site |
| 11 |      12 | Cellular Site |
| 12 |      13 | Cellular Site |
| 13 |      14 | Cellular Site |
| 15 |      15 | Cellular Site |
|  2 |       8 | Core          |
| 26 |       7 | Core          |
| 14 |       2 | Core          |
| 44 |      10 | Health Center |
| 43 |      21 | K-Net POP     |
| 42 |      37 | K-Net POP     |
| 41 |      36 | K-Net POP     |
| 40 |      35 | K-Net POP     |
| 39 |      34 | K-Net POP     |
| 37 |      33 | K-Net POP     |
| 36 |      27 | K-Net POP     |
| 35 |      32 | K-Net POP     |
| 46 |      18 | K-Net POP     |
| 45 |       8 | K-Net Tower   |
+----+---------+---------------+
44 rows in set (0.000 sec)

I see this list of distinct locations:

MariaDB [cacti]> select distinct location from host order by location;
+---------------+
| location      |
+---------------+
|               |
| Cellular Site |
| Core          |
| Health Center |
| K-Net POP     |
| K-Net Tower   |
+---------------+
6 rows in set (0.001 sec)

I modified the SQL query starting on line 229 in host.php to this:

        $locations = db_fetch_assoc_prepared('SELECT DISTINCT location
                FROM host
                WHERE location != ""
                AND location IS NOT NULL
                ORDER BY location',
                array($site_id, "%$term%"));

It now provides me the result I was expecting:

image

I am sorry, but I don't quite understand the ? in the original query and how it gets populated. It's been a few years since I worked with PHP.

@netniV
Copy link
Member

netniV commented Jun 9, 2023

So I believe that this is a bug because the settings array does not filter by a specific site. However, this may have been done to allow a speed increase for those systems with a lot of devices, so I created a config option to allow the current functionality to enabled.

One side effect is that when creating a new device, it will now shoe all locations where the broken functionality only showed None via the ajax calls.

@netniV netniV changed the title Improve Device Location field population Device form location drop down not populating correctly Jun 9, 2023
@netniV netniV changed the title Device form location drop down not populating correctly Device Location drop down does not always populate correctly Sep 3, 2023
@github-actions github-actions bot locked and limited conversation to collaborators Dec 3, 2023
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 porting required Requires porting to develop resolved A fixed issue
Projects
None yet
Development

No branches or pull requests

3 participants