Skip to content

Commit

Permalink
Merge branch '2378-automatic-event-registration' into develop
Browse files Browse the repository at this point in the history
Issue #2378
PR #3867
  • Loading branch information
mssalvatore committed Nov 15, 2023
2 parents ec82892 + 3b32f34 commit 2161257
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 78 deletions.
61 changes: 15 additions & 46 deletions monkey/common/agent_event_serializers/register.py
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)
43 changes: 11 additions & 32 deletions monkey/common/agent_events/register.py
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)

0 comments on commit 2161257

Please sign in to comment.