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

Update NetworkEquipment.php - Stacked switch Name with ID #17091

Merged
merged 4 commits into from May 21, 2024

Conversation

Mirkk
Copy link
Contributor

@Mirkk Mirkk commented May 8, 2024

Stacked switches got a name with the "description" (model) field added, all switches the same(!), which gives several issues in managing them, and has apparently no logic.

It seems that this was just a wrong copy-paste from the previous code line. Corrected with _$stack_number as a commonly used naming scheme.

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets no ticket

Stacked switches got a name with the "description" (model) field, all switches the same, which gives several issues in managing them.

It seems that this was just a wrong copy-paste from the previous code line. Corrected with _$SwitchID  as a common naming scheme.
@trasher
Copy link
Contributor

trasher commented May 13, 2024

Please provide inventory files examples.

@Mirkk
Copy link
Contributor Author

Mirkk commented May 16, 2024

networkequipment_0_797.zip
This is a SNMP inventory file for a stacked switch with 2 modules. I heavily reduced and changed it to remove confidential information, keeping only the relevant components "stack" and "chassis". This now generates 2 assets with the same name "SW00Test - 5130EI" and it is impossible to distinguish them, e.g. in a rack. With the fix it will be SW00Test_1 and SW00Test_2.
Works well for all stacks of 2,3,4 (mostly HP) i retrieved so far.
best, Mirko

@cedric-anne cedric-anne added this to the 10.0.16 milestone May 16, 2024
trasher and others added 3 commits May 17, 2024 08:36
Co-authored-by: Stanislas <skita@teclib.com>
@trasher
Copy link
Contributor

trasher commented May 17, 2024

I made another change. In our existing tests, name already contains the stack number, so the new name was something like "xyz - 1 - 1". I changed a bit the code to keep "xyz - 1" on that cases.

I also added a unit test based on provided file.

@stonebuzz stonebuzz self-requested a review May 17, 2024 07:20
@trasher
Copy link
Contributor

trasher commented May 17, 2024

@Mirkk are our changes OK for you?

@Mirkk
Copy link
Contributor Author

Mirkk commented May 17, 2024

Hi, thanks.
just my 2 cents as a php dummy:
With the associativity of ?? this piece is really hard to read, better you put some parentheses please :-)
Moreover isn't the risk to have a result with double "-": "hostname - - 1"?
For the solution itself It is not clear to me why adding the model name (that is it in fact) to the switch name. A single switch has just the hostname. I add another one and it gets also the model name, this is a quite strange behaviour.

As far as I understood from the linked ticket, It could be that "($switch->name ?? $switch->description)" is the stack number on some stacks. However if "$stack_number" is set (and is a number and not "") IMHO it should simply have the precedence, avoiding to add the model name. And you avoid also the check for not adding the number twice.

best
Mirko

@trasher
Copy link
Contributor

trasher commented May 17, 2024

The ?? notation is widely used in GLPI code. That's not a problem if you understand the code or not; it's only the result with your network devices that is important.

Existing ones in tests are not affected with latests changes; they were with your initial proposal.

@Mirkk
Copy link
Contributor Author

Mirkk commented May 17, 2024

Hi,
with this code the result in my case is "SW00Test - 5130EI - 1". Still I have the switch model "5130EI" in the name which is not usual in GLPI. Couldn't it be left out in this case where it is not a number and the stack_numer is present?
If this is not possible for other reasons of course it is fine also like this for my use cases. Thanks a lot!

@trasher
Copy link
Contributor

trasher commented May 20, 2024

Since the name/description is present in existing inventories, we have to keep it (and in place) in minor upgrades. Also, it may be something completely different than model or stack number as far as I know.

@Mirkk
Copy link
Contributor Author

Mirkk commented May 21, 2024

Ok, thanks for your work!

@trasher trasher merged commit 7f9c6c6 into glpi-project:10.0/bugfixes May 21, 2024
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants