Skip to content

Commit 3fc1029

Browse files
committed
Add the id attribute to BeaconCollectedEvent, which is minion ID.
Signed-off-by: Pedro Algarvio <[email protected]>
1 parent df36094 commit 3fc1029

File tree

3 files changed

+12
-0
lines changed

3 files changed

+12
-0
lines changed

changelog/68.improvement.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@ Several improvements to the project
22

33
* When loading plugin configs, catch `KeyError` on unavailable plugins and list all available.
44
* Pass the event tag and stamp explicitly when calling `saf.utils.eventbus._construct_event()`
5+
* Add the `id` attribute to `BeaconCollectedEvent`, which is minion ID.

pyproject.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ ignore = [
8181
"PERF203", # `try`-`except` within a loop incurs performance overhead"
8282
"PERF401", # Use a list comprehension to create a transformed list
8383
"PERF402", # Use `list` or `list.copy` to create a copy of a list
84+
"FIX002", # Line contains TODO"
85+
"TD003", # Missing issue link on the line following this TODO"
8486
]
8587
ignore-init-module-imports = true
8688
builtins = [

src/saf/collect/beacons.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ class BeaconCollectedEvent(CollectedEvent):
4646
"""
4747

4848
beacon: str
49+
id: str # noqa: A003
4950
tag: str
5051
stamp: datetime
5152
raw_data: Dict[str, Any]
@@ -84,8 +85,16 @@ async def collect(*, ctx: PipelineRunContext[BeaconsConfig]) -> AsyncIterator[Be
8485
tags = {f"salt/beacon/*/{beacon}/*" for beacon in config.beacons}
8586
log.info("The beacons collect plugin is configured to listen to tags: %s", tags)
8687
async for salt_event in eventbus.iter_events(opts=ctx.salt_config.copy(), tags=tags):
88+
if "beacon_name" not in salt_event.raw_data:
89+
# TODO @s0undt3ch: We're listening master side, and the payload is not the same... Fix it?
90+
continue
91+
daemon_id = salt_event.data.get("id")
92+
if daemon_id is None:
93+
tag_parts = salt_event.tag.split("/")
94+
daemon_id = tag_parts[2]
8795
yield BeaconCollectedEvent(
8896
beacon=salt_event.raw_data["beacon_name"],
97+
id=daemon_id,
8998
tag=salt_event.tag,
9099
stamp=salt_event.stamp,
91100
data=salt_event.data,

0 commit comments

Comments
 (0)