Skip to content

Add endpoint for the NetboxEntity model #3404

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

Merged
merged 11 commits into from
Aug 14, 2025
Merged

Add endpoint for the NetboxEntity model #3404

merged 11 commits into from
Aug 14, 2025

Conversation

stveit
Copy link
Contributor

@stveit stveit commented Jul 3, 2025

Fixes #3378

Quick implementation of an endpoint for getting NetboxEntity data.

Filters can easily be expanded by adding more fields to filterset_fields.
The data you get out can be modified via the serializer. I've added an Inline serializer for device so you get the serialnumber directly for each entity since that will probably be useful for syncing to netbox. If you need more netbox data then that can be added as inline in a similar way

Added two simple tests. Not huge test coverage but will at least act as a blueprint to make more tests if needed

@stveit stveit force-pushed the netboxentity-endpoint branch from b87ccd6 to 9c45bd1 Compare July 3, 2025 13:53
Copy link

github-actions bot commented Jul 3, 2025

Test results

   12 files     12 suites   11m 59s ⏱️
2 210 tests 2 210 ✅ 0 💤 0 ❌
6 105 runs  6 105 ✅ 0 💤 0 ❌

Results for commit b746445.

♻️ This comment has been updated with latest results.

@stveit stveit force-pushed the netboxentity-endpoint branch 2 times, most recently from 9c730db to d7eab32 Compare July 4, 2025 11:07
@stveit stveit force-pushed the netboxentity-endpoint branch from d7eab32 to d223a05 Compare July 4, 2025 11:08
Copy link

sonarqubecloud bot commented Jul 4, 2025

Quality Gate Passed Quality Gate passed

Issues
0 New issues
2 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

@stveit stveit marked this pull request as ready for review July 4, 2025 11:09
Copy link
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just nitpicks

Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Just minimal doc nitpicks, methinks...

@lunkwill42
Copy link
Member

lunkwill42 commented Aug 4, 2025

Though, I must confess I'm not a fan of throwing around the magic numbers of entPhysicalClass outside of the NAV DB storage or MIB system.

I might be interested in having the NetboxEntity model updated to use a choice mapping for the field, so the MIB enumerations can easily be translated to symbolic names from the MIB, even in the API (I find it a bit weird that API clients would need to contend with the fact that chassis = 3).

It's hard for us to control whether the MIB is updated and adds new enumerations values, though, and I'm not sure if Django models can specify that a field is allowed to take integers we have no mapping for... any idea, @hmpf ?

@hmpf
Copy link
Contributor

hmpf commented Aug 4, 2025

It's hard for us to control whether the MIB is updated and adds new enumerations values, though, and I'm not sure if Django models can specify that a field is allowed to take integers we have no mapping for... any idea, @hmpf ?

Not enough context. What's mapping to what? In Django there's hardcoded choices with IntegerField(choices=..), postgres has enums (and AFAIK there's no good wrapper for that in Django as of now) and SQL has lookup tables, but then you need to fill the table with new values all the time. Using a lookup table is the most braindead and safe answer if you expect new values. With Django you don't even need a foreign key but can use a validator that speaks manually to the table (bleah).

I don't have the context to know how many tables or if proxying would work or if any other data is needed per table.

@hmpf
Copy link
Contributor

hmpf commented Aug 4, 2025

A lookup table can be (natural key=primary key, mappings*) or (primary key, natural key, mappings*), the latter would hide the actual magical number but the field would need its own index.

@hmpf
Copy link
Contributor

hmpf commented Aug 5, 2025

On reload/restart of nav you could have something that looks up the magic number and its mappings in the relevant MIB(s) and alters the lookup table accordingly.

Copy link

sonarqubecloud bot commented Aug 5, 2025

Quality Gate Passed Quality Gate passed

Issues
0 New issues
2 Accepted issues

Measures
0 Security Hotspots
No data about Coverage
0.0% Duplication on New Code

See analysis details on SonarQube Cloud

Copy link
Contributor

@johannaengland johannaengland left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy, but leaving this in "Ready for Review" for @lunkwill42 or @hmpf for the entPhysicalClass details

@johannaengland johannaengland requested a review from hmpf August 8, 2025 08:59
Copy link
Member

@lunkwill42 lunkwill42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@stveit stveit merged commit d055a1f into master Aug 14, 2025
14 checks passed
Copy link

codecov bot commented Aug 14, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 0.00%. Comparing base (f31f832) to head (b746445).
⚠️ Report is 115 commits behind head on master.

Additional details and impacted files
@@      Coverage Diff       @@
##   master   #3404   +/-   ##
==============================
==============================

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@lunkwill42 lunkwill42 deleted the netboxentity-endpoint branch August 18, 2025 08:43
@lunkwill42
Copy link
Member

A lookup table can be (natural key=primary key, mappings*) or (primary key, natural key, mappings*), the latter would hide the actual magical number but the field would need its own index.

Upon closer examination, I don't think we need the lookup table after all. We already have a value mapping in the Django Model field, NetboxEntity.physical_mapping - and apparently Django doesn't restrict the value to the set of defined choices.

We should probably modify the endpoint slightly to include also the human-readable name of the classifier, @stveit

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.

Add an API endpoint to fetch entity information for IP devices
4 participants