-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated the DataConnector code by implementing Durable Function App.
- Loading branch information
Jayesh Prajapati
authored and
Jayesh Prajapati
committed
Oct 24, 2023
1 parent
0c533c8
commit 6ded2d6
Showing
34 changed files
with
530 additions
and
443 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
45 changes: 45 additions & 0 deletions
45
Solutions/RubrikSecurityCloud/Data Connectors/RubrikActivity/__init__.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
"""This __init__ file will be called by Orchastrator function to ingest data in Sentinel.""" | ||
import inspect | ||
import time | ||
from shared_code.logger import applogger | ||
from shared_code.consts import LOGS_STARTS_WITH | ||
from shared_code.rubrik_exception import RubrikException | ||
from .rubrik import Rubrik | ||
|
||
|
||
def main(name) -> str: | ||
"""Start Execution of Activity Function. | ||
Args: | ||
name (dict): data received via Rubrik Webhook. | ||
Returns: | ||
str: status message of activity function. | ||
""" | ||
__method_name = inspect.currentframe().f_code.co_name | ||
try: | ||
applogger.info( | ||
"{}(method={}) Activity function called!".format( | ||
LOGS_STARTS_WITH, __method_name | ||
) | ||
) | ||
start = time.time() | ||
rubrik_obj = Rubrik() | ||
rubrik_obj.post_data_to_sentinel(name) | ||
end = time.time() | ||
applogger.info( | ||
"{}(method={}) time taken for data ingestion is {} sec".format( | ||
LOGS_STARTS_WITH, __method_name, int(end - start) | ||
) | ||
) | ||
applogger.info( | ||
"{}(method={}) Activity function Completed!".format( | ||
LOGS_STARTS_WITH, __method_name | ||
) | ||
) | ||
except RubrikException as err: | ||
return err | ||
except Exception as err: | ||
applogger.error("{}(method={}) {}".format(LOGS_STARTS_WITH, __method_name, err)) | ||
return err | ||
return "Data Posted successfully to {}".format(name.get("log_type")) |
10 changes: 10 additions & 0 deletions
10
Solutions/RubrikSecurityCloud/Data Connectors/RubrikActivity/function.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
{ | ||
"scriptFile": "__init__.py", | ||
"bindings": [ | ||
{ | ||
"name": "name", | ||
"type": "activityTrigger", | ||
"direction": "in" | ||
} | ||
] | ||
} |
88 changes: 88 additions & 0 deletions
88
Solutions/RubrikSecurityCloud/Data Connectors/RubrikActivity/rubrik.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
"""This file contains implementation to ingest Dataminr RTAP alert data into sentinel.""" | ||
import inspect | ||
from .sentinel import MicrosoftSentinel | ||
from shared_code.consts import ( | ||
LOGS_STARTS_WITH, | ||
ANOMALY_LOG_TYPE, | ||
RANSOMWARE_LOG_TYPE, | ||
THREATHUNT_LOG_TYPE, | ||
) | ||
from shared_code.rubrik_exception import RubrikException | ||
from shared_code.logger import applogger | ||
|
||
|
||
class Rubrik: | ||
"""This class contains methods to get data from request body pushed via Rubrik Webhook and ingest into Sentinel.""" | ||
|
||
def __init__(self) -> None: | ||
"""Initialize instance variables for class.""" | ||
self.logs_starts_with = LOGS_STARTS_WITH | ||
self.microsoftsentinel = MicrosoftSentinel() | ||
self.error_logs = "{}(method={}) {}" | ||
self.check_environment_var_existance() | ||
|
||
def check_environment_var_existance(self): | ||
"""To verify that all required environment variables exist. | ||
Raises: | ||
RubrikException: raise exception if any of the required environment variable is not set. | ||
""" | ||
__method_name = inspect.currentframe().f_code.co_name | ||
env_var = [ | ||
{"Anomalies_table_name": ANOMALY_LOG_TYPE}, | ||
{"RansomwareAnalysis_table_name": RANSOMWARE_LOG_TYPE}, | ||
{"ThreatHunts_table_name": THREATHUNT_LOG_TYPE}, | ||
] | ||
try: | ||
applogger.debug( | ||
"{}(method={}) Checking environment variables are exist or not.".format( | ||
self.logs_starts_with, __method_name | ||
) | ||
) | ||
for i in env_var: | ||
key, val = next(iter(i.items())) | ||
if val is None: | ||
raise RubrikException( | ||
"{} is not set in the environment please set the environment variable.".format( | ||
key | ||
) | ||
) | ||
applogger.debug( | ||
"{}(method={}) All custom environment variables exist.".format( | ||
self.logs_starts_with, __method_name | ||
) | ||
) | ||
except RubrikException as err: | ||
applogger.error( | ||
"{}".format( | ||
self.error_logs.format(self.logs_starts_with, __method_name, err) | ||
) | ||
) | ||
raise RubrikException(err) | ||
except Exception as err: | ||
applogger.error( | ||
"{}".format( | ||
self.error_logs.format(self.logs_starts_with, __method_name, err) | ||
) | ||
) | ||
raise RubrikException(err) | ||
|
||
def post_data_to_sentinel(self, data): | ||
"""To post data received via Rubrik Webhook into Sentinel. | ||
Args: | ||
data (dict): data received via Rubrik Webhook. | ||
""" | ||
__method_name = inspect.currentframe().f_code.co_name | ||
try: | ||
sentinel_obj = MicrosoftSentinel() | ||
body = data.get("data") | ||
log_type = data.get("log_type") | ||
sentinel_obj.post_data(body, log_type) | ||
except Exception as err: | ||
applogger.error( | ||
"{}".format( | ||
self.error_logs.format(self.logs_starts_with, __method_name, err) | ||
) | ||
) | ||
raise RubrikException(err) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
67 changes: 0 additions & 67 deletions
67
Solutions/RubrikSecurityCloud/Data Connectors/RubrikAnomalyEvent/__init__.py
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.