-
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.
Armis AlertsActivities and Device Data Connector Enhancements
- Loading branch information
shashank-shah1719
committed
Nov 7, 2024
1 parent
a9fff40
commit 053b633
Showing
16 changed files
with
614 additions
and
270 deletions.
There are no files selected for viewing
167 changes: 100 additions & 67 deletions
167
...mis/Data Connectors/ArmisAlertsActivities/ArmisAlertActivitySentinelConnector/__init__.py
Large diffs are not rendered by default.
Oops, something went wrong.
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
91 changes: 91 additions & 0 deletions
91
...ata Connectors/ArmisAlertsActivities/ArmisAlertActivitySentinelConnector/exports_store.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,91 @@ | ||
import logging | ||
|
||
from azure.data.tables import TableClient, UpdateMode | ||
from azure.core.exceptions import ResourceNotFoundError, ResourceExistsError, HttpResponseError | ||
|
||
|
||
class ExportsTableStore: | ||
|
||
def __init__(self, connection_string, table_name): | ||
self.connection_string = connection_string | ||
self.table_name = table_name | ||
|
||
def create(self): | ||
with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: | ||
try: | ||
table_client.create_table() | ||
logging.info("Checkpoint Table created") | ||
except ResourceExistsError: | ||
logging.warning("Checkpoint Table already exists") | ||
|
||
def post(self, pk: str, rk: str, data: dict = None): | ||
with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: | ||
entity_template = { | ||
"PartitionKey": pk, | ||
"RowKey": rk, | ||
} | ||
if data is not None: | ||
entity_template.update(data) | ||
try: | ||
table_client.create_entity(entity_template) | ||
except Exception as e: | ||
logging.warning("could not post entity to table") | ||
logging.warning(e) | ||
raise e | ||
|
||
def get(self, pk: str, rk: str): | ||
with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: | ||
try: | ||
logging.info( | ||
"looking for {} - {} on table {}".format(pk, rk, self.table_name)) | ||
return table_client.get_entity(pk, rk) | ||
except ResourceNotFoundError: | ||
return None | ||
|
||
def upsert(self, pk: str, rk: str, data: dict = None): | ||
with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: | ||
logging.info("upserting {} - {} on table {}".format(pk, rk, self.table_name)) | ||
entity_template = { | ||
"PartitionKey": pk, | ||
"RowKey": rk, | ||
} | ||
if data is not None: | ||
entity_template.update(data) | ||
return table_client.upsert_entity(mode=UpdateMode.REPLACE, entity=entity_template) | ||
|
||
def update_if_found(self, pk: str, rk: str, data: dict = None): | ||
if self.get(pk, rk) is not None: | ||
self.merge(pk, rk, data) | ||
|
||
def query_by_partition_key(self, pk): | ||
table_client = TableClient.from_connection_string( | ||
self.connection_string, self.table_name) | ||
parameters = {u"key": pk} | ||
name_filter = u"PartitionKey eq @key" | ||
try: | ||
return table_client.query_entities(name_filter, parameters=parameters) | ||
except HttpResponseError as e: | ||
print(e.message) | ||
return [] | ||
|
||
def batch(self, operations): | ||
with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: | ||
return table_client.submit_transaction(operations=operations) | ||
|
||
def list_all(self): | ||
table_client = TableClient.from_connection_string( | ||
self.connection_string, self.table_name) | ||
return table_client.list_entities() | ||
|
||
def merge(self, pk: str, rk: str, data: dict = None): | ||
with TableClient.from_connection_string(self.connection_string, self.table_name) as table_client: | ||
logging.info("upserting {} - {} on table {}".format(pk, rk, self.table_name)) | ||
entity_template = { | ||
"PartitionKey": pk, | ||
"RowKey": rk, | ||
} | ||
if data is not None: | ||
entity_template.update(data) | ||
return table_client.upsert_entity(mode=UpdateMode.MERGE, entity=entity_template) | ||
|
||
|
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
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
Binary file modified
BIN
+149 KB
(100%)
Solutions/Armis/Data Connectors/ArmisAlertsActivities/ArmisAlertsActivitiesSentinelConn.zip
Binary file not shown.
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
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
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 |
---|---|---|
|
@@ -4,4 +4,5 @@ | |
|
||
azure-functions | ||
azure-storage-file-share==12.3.0 | ||
requests | ||
requests | ||
azure-data-tables==12.1.0 |
Binary file modified
BIN
+447 KB
(100%)
Solutions/Armis/Data Connectors/ArmisDevice/ArmisDeviceSentinelConn.zip
Binary file not shown.
Oops, something went wrong.