Lowered code dup in get_result_event

This commit is contained in:
Shay Nehmad 2019-09-16 15:08:22 +03:00
parent dd9a4b2d10
commit 76c642e4b3
1 changed files with 10 additions and 13 deletions

View File

@ -3,6 +3,10 @@ from common.data.zero_trust_consts import EVENT_TYPE_MONKEY_NETWORK, STATUS_FAIL
from monkey_island.cc.models.zero_trust.aggregate_finding import AggregateFinding from monkey_island.cc.models.zero_trust.aggregate_finding import AggregateFinding
from monkey_island.cc.models.zero_trust.event import Event from monkey_island.cc.models.zero_trust.event import Event
COMM_AS_NEW_USER_FAILED_FORMAT = "Monkey on {} couldn't communicate as new user. Details: {}"
COMM_AS_NEW_USER_SUCCEEDED_FORMAT = \
"New user created by Monkey on {} successfully tried to communicate with the internet. Details: {}"
def test_new_user_communication(current_monkey, success, message): def test_new_user_communication(current_monkey, success, message):
AggregateFinding.create_or_add_to_existing( AggregateFinding.create_or_add_to_existing(
@ -24,16 +28,9 @@ def get_attempt_event(current_monkey):
def get_result_event(current_monkey, message, success): def get_result_event(current_monkey, message, success):
if success: message_format = COMM_AS_NEW_USER_SUCCEEDED_FORMAT if success else COMM_AS_NEW_USER_FAILED_FORMAT
event_to_append = Event.create_event(
return Event.create_event(
title="Communicate as new user", title="Communicate as new user",
message="New user created by Monkey on {} successfully tried to communicate with the internet. " message=message_format.format(current_monkey.hostname, message),
"Details: {}".format(current_monkey.hostname, message),
event_type=EVENT_TYPE_MONKEY_NETWORK) event_type=EVENT_TYPE_MONKEY_NETWORK)
else:
event_to_append = Event.create_event(
title="Communicate as new user",
message="Monkey on {} couldn't communicate as new user. Details: {}".format(
current_monkey.hostname, message),
event_type=EVENT_TYPE_MONKEY_NETWORK)
return event_to_append