Conversation
Test results 27 files 27 suites 45m 33s ⏱️ Results for commit 4201fc3. ♻️ This comment has been updated with latest results. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #3665 +/- ##
==========================================
+ Coverage 62.95% 62.96% +0.01%
==========================================
Files 611 611
Lines 45150 45163 +13
Branches 43 43
==========================================
+ Hits 28424 28438 +14
+ Misses 16716 16715 -1
Partials 10 10 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
d07d922 to
bfa049c
Compare
lunkwill42
left a comment
There was a problem hiding this comment.
This does the job and LGTM :)
| def create_alert_history_for_device(device, count=1): | ||
| for day in range(count): | ||
| activity = AlertHistory( | ||
| device=device, | ||
| event_type_id='boxState', | ||
| alert_type_id=1, | ||
| source_id='pping', | ||
| start_time=datetime(2025, 1, day + 1), | ||
| end_time=datetime(2025, 1, day + 10), | ||
| value=42, | ||
| ) | ||
| activity.save() | ||
| return AlertHistory.objects.filter(device=device) |
There was a problem hiding this comment.
This will litter the test database with records, by itself, though.
It might help that it is always used in conjunction with a fixture that depends on the db fixture, but in isolation this will potentially leave a lot of stuff in the db.
Not a showstopper, but it could bite us down the line. Maybe this too should be a fixture?
There was a problem hiding this comment.
I added the "db" fixture to the test that calls this function, that should fix it right?
There's also the option to leave alert history intact when dumping the db from a remote production server. Something like this would do it: diff --git a/tools/dump-remote-db.sh b/tools/dump-remote-db.sh
--- a/tools/dump-remote-db.sh
+++ b/tools/dump-remote-db.sh
@@ -10,4 +10,4 @@ echo "Dumping NAV database from $REMOTE"
# This filters potentially huge amounts of old log data and also user alert
# profiles (so as not to start sending notifications to real users from a dev
# environment):
-ssh "$REMOTE" navpgdump --only-open-arp --only-open-cam -e alertprofile -e alerthist
+ssh "$REMOTE" navpgdump --only-open-arp --only-open-cam -e alertprofile |
bfa049c to
4201fc3
Compare
|



Scope and purpose
Resolves #1996
This PR adds support for searching for serial numbers that are no longer associated with equipment in the database, such as Netboxes, modules or power supplies. These are named "Inactive Devices", as they are not registered on any component in the system. This is necessary to enable users of NAV to find alert history events for devices that have been "disconnected" from a component.
Screenshots
How to test
Adding alerts to an inactive device
Your local database is unlikely to contain any history for inactive devices, as the alert history is empty by default when dumping from a production database. I solved this by finding an unused device and adding a few alerts manually. You can use this python snippet (when using
django-admin shell)Querying the database for inactive devices
You can query the database by using the shell and the
Devicemodel, or with a sql query. Here are the two options.Contributor Checklist
Every pull request should have this checklist filled out, no matter how small it is.
More information about contributing to NAV can be found in the
Hacker's guide to NAV.
<major>.<minor>.x). For a new feature or other additions, it should be based onmaster.