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

Add a report of software upgrade logs #2466

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

johannaengland
Copy link
Contributor

@johannaengland johannaengland commented Aug 12, 2022

Closes #2457.

Sub-device id/name and sub-device serial number are still missing.

@johannaengland johannaengland self-assigned this Aug 12, 2022
@sonarcloud
Copy link

sonarcloud bot commented Aug 12, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@codecov
Copy link

codecov bot commented Aug 12, 2022

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 60.21%. Comparing base (282694b) to head (a9f14f2).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2466   +/-   ##
=======================================
  Coverage   60.21%   60.21%           
=======================================
  Files         601      601           
  Lines       43981    43981           
=======================================
  Hits        26481    26481           
  Misses      17500    17500           

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

@github-actions
Copy link

github-actions bot commented Aug 12, 2022

Test results

     12 files       12 suites   11m 34s ⏱️
3 318 tests 3 318 ✔️ 0 💤 0
9 429 runs  9 429 ✔️ 0 💤 0

Results for commit a9f14f2.

♻️ This comment has been updated with latest results.

@johannaengland
Copy link
Contributor Author

Any pointers for the missing information?

@johannaengland
Copy link
Contributor Author

The old software version is saved in the varmap. Is there any way to access that?

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.

This looks fine to me so far :)

The old software version is saved in the varmap. Is there any way to access that?

I can't recall what the attribute names are. Care to remind me? :)

@johannaengland
Copy link
Contributor Author

This looks fine to me so far :)

The old software version is saved in the varmap. Is there any way to access that?

I can't recall what the attribute names are. Care to remind me? :)

https://github.com/johannaengland/nav/blob/master/python/nav/ipdevpoll/shadows/__init__.py#L304

@lunkwill42
Copy link
Member

This looks fine to me so far :)

The old software version is saved in the varmap. Is there any way to access that?

I can't recall what the attribute names are. Care to remind me? :)

https://github.com/johannaengland/nav/blob/master/python/nav/ipdevpoll/shadows/__init__.py#L304

I checked this out, and, unfortunately (as I suspected): varmap items aren't automatically copied over from eventq to alerthist entries - which means that this information gets lost in the history log.

An eventengine plugin needs to explicitly copy over variables that we want to keep a historic record of. Otherwise, they're just around for the eventq/alertq for alert profile filter and alert message template expansion.

You can explicitly check the history of upgrade-type alert with something like this:

SELECT
    *
FROM
    alerthistvar
WHERE
    alerthistid IN (
        SELECT
            ah.alerthistid
        FROM
            alerthist ah
            JOIN alerttype at USING (alerttypeid)
        WHERE
            alerttype ILIKE '%upgrade'
        ORDER BY
            start_time DESC
        LIMIT 1);

An example of a plugin that copies over the varmap is this plugin (for maintenance events, see line 42 for the defining moment):

def _post_alert(self, event):
alert = AlertGenerator(event)
alert.alert_type = (
'onMaintenance' if event.state == event.STATE_START else 'offMaintenance'
)
alert.history_vars = dict(alert)
if alert.is_event_duplicate():
self._logger.info('Ignoring duplicate event')
else:
alert.post()

You can confirm this for maintenance events by re-using the above SQL:

SELECT
    *
FROM
    alerthistvar
WHERE
    alerthistid IN (
        SELECT
            ah.alerthistid
        FROM
            alerthist ah
            JOIN alerttype at USING (alerttypeid)
        WHERE
            alerttype ILIKE '%maintenance'
        ORDER BY
            start_time DESC
        LIMIT 1);

So: I think we need a new eventengine plugin before this PR makes sense. Are you up to the task? :)

@johannaengland
Copy link
Contributor Author

I have checked this manually in combination with #2515 and it works as expected.

Now only sub-device id/name and sub-device serial number are missing, any idea on how to get that?

@sonarcloud
Copy link

sonarcloud bot commented Dec 2, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

@sonarcloud
Copy link

sonarcloud bot commented Mar 22, 2023

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
No Duplication information No Duplication information

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.

Yes, this is still going in the right direction :)

To add more information about entities, you need to join the netboxentity table, which describes the internal entities in a device.

One silly detail may be that netboxentity uses raw entPhysicalClass values from ENTITY-MIB, and there is no translation table in the database, so you may need to translate the values back into strings in order for the sub-device listing to make sense (see the cisco_serials report for a short example that only translates two of the possible values)

@johannaengland johannaengland force-pushed the software-upgrade-report branch from 0f9f276 to a9f14f2 Compare April 30, 2024 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a report of software upgrade logs
2 participants