-
Notifications
You must be signed in to change notification settings - Fork 786
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch '2378-automatic-event-registration' into develop
- Loading branch information
Showing
2 changed files
with
26 additions
and
78 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,22 @@ | ||
from common.agent_events import ( | ||
AgentShutdownEvent, | ||
CPUConsumptionEvent, | ||
CredentialsStolenEvent, | ||
DefacementEvent, | ||
ExploitationEvent, | ||
FileEncryptionEvent, | ||
FingerprintingEvent, | ||
HostnameDiscoveryEvent, | ||
HTTPRequestEvent, | ||
OSDiscoveryEvent, | ||
PasswordRestorationEvent, | ||
PingScanEvent, | ||
PropagationEvent, | ||
RAMConsumptionEvent, | ||
TCPScanEvent, | ||
) | ||
import inspect | ||
|
||
import common.agent_events | ||
|
||
from . import AgentEventSerializerRegistry, PydanticAgentEventSerializer | ||
|
||
|
||
def register_common_agent_event_serializers( | ||
event_serializer_registry: AgentEventSerializerRegistry, | ||
): | ||
event_serializer_registry[AgentShutdownEvent] = PydanticAgentEventSerializer(AgentShutdownEvent) | ||
event_serializer_registry[CPUConsumptionEvent] = PydanticAgentEventSerializer( | ||
CPUConsumptionEvent | ||
) | ||
event_serializer_registry[CredentialsStolenEvent] = PydanticAgentEventSerializer( | ||
CredentialsStolenEvent | ||
) | ||
event_serializer_registry[DefacementEvent] = PydanticAgentEventSerializer(DefacementEvent) | ||
event_serializer_registry[ExploitationEvent] = PydanticAgentEventSerializer(ExploitationEvent) | ||
event_serializer_registry[FileEncryptionEvent] = PydanticAgentEventSerializer( | ||
FileEncryptionEvent | ||
) | ||
event_serializer_registry[FingerprintingEvent] = PydanticAgentEventSerializer( | ||
FingerprintingEvent | ||
) | ||
event_serializer_registry[HTTPRequestEvent] = PydanticAgentEventSerializer(HTTPRequestEvent) | ||
event_serializer_registry[HostnameDiscoveryEvent] = PydanticAgentEventSerializer( | ||
HostnameDiscoveryEvent | ||
) | ||
event_serializer_registry[OSDiscoveryEvent] = PydanticAgentEventSerializer(OSDiscoveryEvent) | ||
event_serializer_registry[PasswordRestorationEvent] = PydanticAgentEventSerializer( | ||
PasswordRestorationEvent | ||
) | ||
event_serializer_registry[PingScanEvent] = PydanticAgentEventSerializer(PingScanEvent) | ||
event_serializer_registry[PropagationEvent] = PydanticAgentEventSerializer(PropagationEvent) | ||
event_serializer_registry[RAMConsumptionEvent] = PydanticAgentEventSerializer( | ||
RAMConsumptionEvent | ||
) | ||
event_serializer_registry[TCPScanEvent] = PydanticAgentEventSerializer(TCPScanEvent) | ||
# Note: The code to identify all agent events here duplicates the code from | ||
# common.agent_events.register_common_agent_events(). This is difficult to rectify at the | ||
# present time without introducing a circular import. This should be fixable once #3799 is | ||
# completed and agent events are moved to the monkeyevents package. | ||
for _, event_class in inspect.getmembers(common.agent_events, inspect.isclass): | ||
if event_class is common.agent_events.AbstractAgentEvent: | ||
continue | ||
|
||
if not issubclass(event_class, common.agent_events.AbstractAgentEvent): | ||
continue | ||
|
||
event_serializer_registry[event_class] = PydanticAgentEventSerializer(event_class) |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,18 @@ | ||
from common.agent_events import ( | ||
AgentShutdownEvent, | ||
CPUConsumptionEvent, | ||
CredentialsStolenEvent, | ||
DefacementEvent, | ||
ExploitationEvent, | ||
FileEncryptionEvent, | ||
FingerprintingEvent, | ||
HostnameDiscoveryEvent, | ||
HTTPRequestEvent, | ||
OSDiscoveryEvent, | ||
PasswordRestorationEvent, | ||
PingScanEvent, | ||
PropagationEvent, | ||
RAMConsumptionEvent, | ||
TCPScanEvent, | ||
) | ||
import inspect | ||
|
||
import common.agent_events | ||
|
||
from . import AgentEventRegistry | ||
|
||
|
||
def register_common_agent_events( | ||
agent_event_registry: AgentEventRegistry, | ||
): | ||
agent_event_registry.register(AgentShutdownEvent) | ||
agent_event_registry.register(CPUConsumptionEvent) | ||
agent_event_registry.register(CredentialsStolenEvent) | ||
agent_event_registry.register(DefacementEvent) | ||
agent_event_registry.register(ExploitationEvent) | ||
agent_event_registry.register(FileEncryptionEvent) | ||
agent_event_registry.register(FingerprintingEvent) | ||
agent_event_registry.register(HostnameDiscoveryEvent) | ||
agent_event_registry.register(HTTPRequestEvent) | ||
agent_event_registry.register(OSDiscoveryEvent) | ||
agent_event_registry.register(PasswordRestorationEvent) | ||
agent_event_registry.register(PingScanEvent) | ||
agent_event_registry.register(PropagationEvent) | ||
agent_event_registry.register(RAMConsumptionEvent) | ||
agent_event_registry.register(TCPScanEvent) | ||
for _, event_class in inspect.getmembers(common.agent_events, inspect.isclass): | ||
if event_class is common.agent_events.AbstractAgentEvent: | ||
continue | ||
|
||
if not issubclass(event_class, common.agent_events.AbstractAgentEvent): | ||
continue | ||
|
||
agent_event_registry.register(event_class) |