feat: add role fingerprints to syslog#861
Merged
Merged
Conversation
Feature: Add a fingerprint string to the system log to indicate when the role began successfully, and when the role finished successfully. The fingerprint string indicates the role name, a timestamp, and the platform. Reason: Users can see when the role was used and if it was used successfully. This information from the system log can be collected by log scanners and aggregators for further analysis. Result: The role logs fingerprints to the system log. This also adds a test to check if the fingerprints were written upon a successful role invocation. Signed-off-by: Rich Megginson <rmeggins@redhat.com>
Reviewer's GuideAdds a new sr_fingerprint Ansible module to emit timestamped role fingerprints to syslog, integrates it at role begin and success points in the network role, and introduces a journalctl-based test that validates the fingerprints are written when syslog is available, along with associated sanity-ignore updates. Sequence diagram for role fingerprints being written to syslogsequenceDiagram
actor Admin
participant AnsibleController
participant NetworkRole
participant SrFingerprintModule
participant Syslog
Admin->>AnsibleController: Run playbook using network role
AnsibleController->>NetworkRole: Execute tasks
rect rgb(235, 245, 255)
NetworkRole->>SrFingerprintModule: Record role begin fingerprint
SrFingerprintModule->>SrFingerprintModule: _local_iso8601_no_microseconds
alt check_mode enabled
SrFingerprintModule-->>AnsibleController: exit_json changed=False, message (not logged)
else normal execution
SrFingerprintModule->>Syslog: module.log(begin fingerprint + timestamp)
SrFingerprintModule-->>AnsibleController: exit_json changed=False
end
end
AnsibleController->>NetworkRole: Continue network configuration tasks
NetworkRole->>NetworkRole: Configure network, re-test connectivity
rect rgb(235, 245, 255)
NetworkRole->>SrFingerprintModule: Record role success fingerprint
SrFingerprintModule->>SrFingerprintModule: _local_iso8601_no_microseconds
alt check_mode enabled
SrFingerprintModule-->>AnsibleController: exit_json changed=False, message (not logged)
else normal execution
SrFingerprintModule->>Syslog: module.log(success fingerprint + timestamp)
SrFingerprintModule-->>AnsibleController: exit_json changed=False
end
end
Syslog-->>Admin: Fingerprint entries visible via journalctl or log aggregator
Class diagram for the new sr_fingerprint Ansible moduleclassDiagram
class SrFingerprintModule {
+_local_iso8601_no_microseconds() str
+run_module() void
+main() void
}
class AnsibleModule {
+params dict
+check_mode bool
+log(message str) void
+exit_json(changed bool, message str) void
}
class DatetimeModule {
+datetime
+timezone
}
class TimeModule {
+strftime(format str, t) str
+localtime() tuple
}
SrFingerprintModule ..> AnsibleModule : uses
SrFingerprintModule ..> DatetimeModule : uses
SrFingerprintModule ..> TimeModule : fallback uses
SrFingerprintModule : +_local_iso8601_no_microseconds() str
SrFingerprintModule : +run_module() void
SrFingerprintModule : +main() void
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The role name string
system_role:networkis hard-coded in multiple places (fingerprint tasks and tests); consider centralizing it in a variable to avoid divergence if the role name ever changes. - The
sr_fingerprintmodule’s_local_iso8601_no_microsecondshelper callsdatetime.datetime.now()twice; you can reuse the initialnowobject to avoid redundant system calls and keep the logic simpler. - The journal check shell command chains
grepand custom error messages; you might want to factor this into a small helper script or a command template variable to make it easier to maintain and less fragile if the grep patterns need to evolve.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The role name string `system_role:network` is hard-coded in multiple places (fingerprint tasks and tests); consider centralizing it in a variable to avoid divergence if the role name ever changes.
- The `sr_fingerprint` module’s `_local_iso8601_no_microseconds` helper calls `datetime.datetime.now()` twice; you can reuse the initial `now` object to avoid redundant system calls and keep the logic simpler.
- The journal check shell command chains `grep` and custom error messages; you might want to factor this into a small helper script or a command template variable to make it easier to maintain and less fragile if the grep patterns need to evolve.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #861 +/- ##
==========================================
- Coverage 43.11% 42.71% -0.41%
==========================================
Files 12 13 +1
Lines 3124 3158 +34
==========================================
+ Hits 1347 1349 +2
- Misses 1777 1809 +32 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Contributor
Author
|
[citest] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Feature: Add a fingerprint string to the system log to indicate when the role began
successfully, and when the role finished successfully. The fingerprint string indicates
the role name, a timestamp, and the platform.
Reason: Users can see when the role was used and if it was used successfully. This
information from the system log can be collected by log scanners and aggregators
for further analysis.
Result: The role logs fingerprints to the system log.
This also adds a test to check if the fingerprints were written upon a successful
role invocation.
Signed-off-by: Rich Megginson rmeggins@redhat.com
Summary by Sourcery
Add syslog fingerprinting for the network system role and verify it via tests.
New Features:
Tests: