Skip to content

Commit

Permalink
Validators
Browse files Browse the repository at this point in the history
  • Loading branch information
ablakley-r7 committed Jan 28, 2025
1 parent bb5a7f4 commit de457aa
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
from insightconnect_plugin_runtime.exceptions import PluginException, ConnectionTestException
from .schema import ConnectionSchema, Input
from icon_mimecast_v2.util.api import API

# Custom imports below


class Connection(insightconnect_plugin_runtime.Connection):

def __init__(self):
super(self.__class__, self).__init__(input=ConnectionSchema())

Expand All @@ -17,8 +17,6 @@ def connect(self, params):
self.api = API(client_id=self.client_id, client_secret=self.client_secret, logger=self.logger)
self.api.authenticate()



def test(self):
try:
self.api.health_check()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ def __init__(self):
state=MonitorSiemLogsState(),
)

def run(self, params={}, state={}, custom_config={}):
def run(self, params={}, state={}, custom_config={}): # pylint: disable=unused-argument
self.logger.info(f"TASK: Received State: {state}")
existing_state = state.copy()
try:
run_condition = self.detect_run_condition(state)
self.logger.info(f"TASK: Current run state is {run_condition}")
now = datetime.now(tz=timezone.utc)
now_date = now.date()
max_api_lookback_date, max_run_lookback_date = self.get_max_lookback_date(
now, run_condition, bool(custom_config)
)
max_run_lookback_date = self.get_max_lookback_date(now, run_condition, bool(custom_config))
if not state:
state = INITIAL_STATE
self.apply_custom_config(state, custom_config)
Expand All @@ -47,17 +45,14 @@ def run(self, params={}, state={}, custom_config={}):
exit_state, has_more_pages = self.prepare_exit_state(query_config, now_date)
return logs, exit_state, has_more_pages, 200, None
except APIException as error:
raise error
self.logger.info(
f"Error: An API exception has occurred. Status code: {error.status_code} returned. Cause: {error.cause}. Error data: {error.data}."
)
return [], existing_state, False, error.status_code, error
except PluginException as error:
raise error
self.logger.info(f"Error: A Plugin exception has occurred. Cause: {error.cause} Error data: {error.data}.")
return [], existing_state, False, error.status_code, error
except Exception as error:
raise error
self.logger.info(f"Error: Unknown exception has occurred. No results returned. Error Data: {error}")
return [], existing_state, False, 500, PluginException(preset=PluginException.Preset.UNKNOWN, data=error)

Expand All @@ -78,20 +73,18 @@ def get_max_lookback_date(
self, now: datetime, run_condition: str, custom_config: bool
) -> Tuple[datetime, datetime]:
"""
Get max API lookback date and max lookback date for run condition
Get max lookback date for run condition
:param now:
:param run_condition:
:param custom_config:
:return: max_api_lookback_date, max_run_lookback_date
:return: max_run_lookback_date
"""
max_api_lookback_days = MAX_LOOKBACK_DAYS
max_run_lookback_days = max_api_lookback_days
max_run_lookback_days = MAX_LOOKBACK_DAYS
if run_condition in [INITIAL_RUN] and not custom_config:
max_run_lookback_days = INITIAL_MAX_LOOKBACK_DAYS

max_api_lookback_date = (now - timedelta(days=max_api_lookback_days)).date()
max_run_lookback_date = (now - timedelta(days=max_run_lookback_days)).date()
return max_api_lookback_date, max_run_lookback_date
return max_run_lookback_date

def apply_custom_config(self, current_query_config: Dict, custom_config: Dict) -> None:
"""
Expand Down Expand Up @@ -172,7 +165,7 @@ def prepare_exit_state(self, state: dict, now_date: datetime) -> Tuple[Dict, boo
:return: state, has_more_pages
"""
has_more_pages = False
for log_type, log_type_config in state.items():
for log_type_config in state.values():
query_date = log_type_config.get("query_date")
if log_type_config.get("caught_up") is True:
has_more_pages = True
Expand Down
2 changes: 1 addition & 1 deletion plugins/mimecast_v2/icon_mimecast_v2/util/endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@

class Endpoints:
AUTH = f"{BASE_URL}oauth/token"
GET_SIEM_LOGS_BATCH = f"{BASE_URL}siem/v1/batch/events/cg"
GET_SIEM_LOGS_BATCH = f"{BASE_URL}siem/v1/batch/events/cg"

0 comments on commit de457aa

Please sign in to comment.