Skip to content

Commit

Permalink
Alert Activity Data Connector code and zip updated
Browse files Browse the repository at this point in the history
  • Loading branch information
shashank-shah1719 committed Nov 8, 2024
1 parent 053b633 commit f2cd259
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import json
from .sentinel import AzureSentinel
from .exports_store import ExportsTableStore
from Exceptions.ArmisExceptions import ArmisException, ArmisDataNotFoundException, ArmisTimeOutException
from Exceptions.ArmisExceptions import ArmisException, ArmisDataNotFoundException
from .utils import Utils
from . import consts
import inspect
Expand All @@ -16,14 +16,13 @@
class ArmisAlertsActivities(Utils):
"""This class will process the Alert Activity data and post it into the Microsoft sentinel."""

def __init__(self, start_time):
def __init__(self):
"""__init__ method will initialize object of class."""
super().__init__()
self.data_alert_from = 0
self.azuresentinel = AzureSentinel()
self.total_alerts_posted = 0
self.total_activities_posted = 0
self.start = start_time

def get_alert_data(self, parameter):
"""get_alert_data is used to get data using api.
Expand Down Expand Up @@ -248,9 +247,6 @@ def fetch_alert_data(self, alert_parameter, is_checkpoint_not_exist, checkpoint_
alert_parameter["aql"] = aql_data
alert_parameter["length"] = 1000
while self.data_alert_from is not None:
if int(time.time()) >= self.start + consts.FUNCTION_APP_TIMEOUT_SECONDS:
raise ArmisTimeOutException()

alert_parameter.update({"from": self.data_alert_from})
offset_to_post = self.data_alert_from
logging.info(consts.LOG_FORMAT.format(__method_name, "Fetching alerts data with parameters = {}.".format(alert_parameter)))
Expand Down Expand Up @@ -360,15 +356,6 @@ def check_data_exists_or_not_alert(self):
except ArmisException:
raise ArmisException()

except ArmisTimeOutException:
logging.info(
consts.LOG_FORMAT.format(
__method_name,
"9:30 mins executed hence stopping the execution.",
)
)
return

except ArmisDataNotFoundException:
raise ArmisDataNotFoundException()

Expand All @@ -389,14 +376,13 @@ def main(mytimer: func.TimerRequest) -> None:
mytimer (func.TimerRequest): This variable will be used to trigger the function.
"""
start_time = time.time()
__method_name = inspect.currentframe().f_code.co_name
utc_timestamp = datetime.datetime.utcnow().replace(tzinfo=datetime.timezone.utc).isoformat()
logging.info(
consts.LOG_FORMAT.format(__method_name, "Python timer trigger function ran at {}".format(utc_timestamp))
)

armis_obj = ArmisAlertsActivities(start_time)
armis_obj = ArmisAlertsActivities()
try:
armis_obj.check_data_exists_or_not_alert()
except ArmisDataNotFoundException:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,3 @@
LOG_FORMAT = "Armis Alerts Activities Connector: (method = {}) : {}"
REQUEST_TIMEOUT = 300
CHECKPOINT_TABLE_NAME = "ArmisAlertActivityCheckpoint"
FUNCTION_APP_TIMEOUT_SECONDS = 570
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,3 @@ class ArmisDataNotFoundException(Exception):

pass


class ArmisTimeOutException(Exception):
"""ArmisTimeOutException class will inherit Exception class."""

pass

0 comments on commit f2cd259

Please sign in to comment.