Skip to content

Commit 85a50f2

Browse files
ablakley-r7rbowden-r7
authored andcommitted
Mimecast V2 - Fix connection test | Fix custom config (#3071)
* Fix connection test | Fix custom config * Fix type hint
1 parent c49bdcc commit 85a50f2

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

plugins/mimecast_v2/icon_mimecast_v2/connection/connection.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ def connect(self, params):
2020

2121
def test(self):
2222
try:
23-
self.api.health_check()
23+
now_date = datetime.now(tz=timezone.utc).date()
24+
self.api.get_siem_logs(log_type="receipt", query_date=now_date, page_size=1, max_threads=1, next_page=None)
2425
return {"success": True}
2526
except PluginException as error:
2627
raise ConnectionTestException(cause=error.cause, assistance=error.assistance, data=error.data)

plugins/mimecast_v2/icon_mimecast_v2/tasks/monitor_siem_logs/task.py

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ def run(self, params={}, state={}, custom_config={}): # pylint: disable=unused-
4747
run_condition = self.detect_run_condition(state.get(QUERY_CONFIG, {}), now_date)
4848
self.logger.info(f"TASK: Run state is {run_condition}")
4949
state = self.update_state(state)
50-
page_size, thead_count = self.apply_custom_config(state, custom_config)
50+
page_size, thead_count = self.apply_custom_config(state, run_condition, custom_config)
5151
max_run_lookback_date = self.get_max_lookback_date(now_date, run_condition, bool(custom_config))
5252
query_config = self.prepare_query_params(state.get(QUERY_CONFIG, {}), max_run_lookback_date, now_date)
5353
logs, query_config = self.get_all_logs(run_condition, query_config, page_size, thead_count)
@@ -114,20 +114,24 @@ def get_max_lookback_date(self, now_date: datetime, run_condition: str, custom_c
114114
max_run_lookback_date = now_date - timedelta(days=max_run_lookback_days)
115115
return max_run_lookback_date
116116

117-
def apply_custom_config(self, state: Dict, custom_config: Dict = {}) -> Tuple[int, int]:
117+
def apply_custom_config(self, state: Dict, run_type: str, custom_config: Dict = {}) -> Tuple[int, int]:
118118
"""
119119
Apply custom configuration for lookback, query date applies to start and end time of query
120120
:param current_query_config:
121+
:param run_type:
121122
:param custom_config:
122-
:return:
123+
:return: Page size and thread count
123124
"""
125+
custom_query_config = {}
124126
if custom_config:
125127
self.logger.info("TASK: Custom config detected")
126-
if not state:
128+
custom_query_config = custom_config.get("query_config", {})
129+
if run_type == INITIAL_RUN:
127130
current_query_config = state.get(QUERY_CONFIG)
128-
for log_type, query_date_string in custom_config.items():
129-
self.logger.info(f"TASK: Supplied lookback date of {query_date_string} for log type {log_type}")
130-
current_query_config[log_type] = {QUERY_DATE: query_date_string}
131+
for log_type, log_query_config in custom_query_config.items():
132+
log_query_date = log_query_config.get("query_date", None)
133+
self.logger.info(f"TASK: Supplied lookback date of {log_query_date} for log type {log_type}")
134+
current_query_config[log_type] = {QUERY_DATE: log_query_date}
131135
page_size = max(1, min(custom_config.get(PAGE_SIZE, DEFAULT_PAGE_SIZE), DEFAULT_PAGE_SIZE))
132136
thread_count = max(1, custom_config.get(THREAD_COUNT, DEFAULT_THREAD_COUNT))
133137
return page_size, thread_count

0 commit comments

Comments
 (0)