Skip to content

Commit

Permalink
soar: fix logger
Browse files Browse the repository at this point in the history
  • Loading branch information
naisanzaa committed Oct 24, 2023
1 parent 33f598e commit 8d25500
Show file tree
Hide file tree
Showing 10 changed files with 57 additions and 45 deletions.
5 changes: 3 additions & 2 deletions automon/integrations/splunk_soar/action_run.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from automon.log import Logging
from automon.log import logger

from .datatypes import AbstractDataType

log = Logging('ActionRun', level=Logging.CRITICAL)
log = logger.logging.getLogger(__name__)
log.setLevel(logger.CRITICAL)


class ActionRun(AbstractDataType):
Expand Down
5 changes: 3 additions & 2 deletions automon/integrations/splunk_soar/artifact.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from automon.log import Logging
from automon.log import logger

from .datatypes import AbstractDataType

log = Logging('Artifact', level=Logging.CRITICAL)
log = logger.logging.getLogger(__name__)
log.setLevel(logger.CRITICAL)


class Artifact(AbstractDataType):
Expand Down
5 changes: 3 additions & 2 deletions automon/integrations/splunk_soar/asset.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from automon.log import Logging
from automon.log import logger

from .datatypes import AbstractDataType

log = Logging(name='Asset', level=Logging.DEBUG)
log = logger.logging.getLogger(__name__)
log.setLevel(logger.DEBUG)


class Asset(AbstractDataType):
Expand Down
56 changes: 29 additions & 27 deletions automon/integrations/splunk_soar/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import Optional

from automon.log import Logging
from automon.log import logger
from automon.integrations.requestsWrapper import Requests

from .action_run import ActionRun
Expand All @@ -28,8 +28,10 @@
VaultResponse
)

log = Logging(name='SplunkSoarClient', level=Logging.DEBUG)
Logging(name='RequestsClient', level=Logging.DEBUG)
log = logger.logging.getLogger(__name__)
log.setLevel(logger.DEBUG)

logger.logging.getLogger('RequestsClient').setLevel(logger.DEBUG)


class SplunkSoarClient:
Expand Down Expand Up @@ -98,7 +100,7 @@ def close_container(self, container_id: int, **kwargs) -> Optional[CloseContaine
log.info(f'container closed: {response}')
return response

log.error(msg=f'close failed. {self.client.to_dict()}', raise_exception=False)
log.error(msg=f'close failed. {self.client.to_dict()}')

@_is_connected
def cancel_playbook_run(
Expand All @@ -115,7 +117,7 @@ def cancel_playbook_run(
log.info(f'cancel playbook run: {response}')
return response

log.error(f'cancel failed: {playbook_run_id} {self.client.to_dict()}', enable_traceback=False)
log.error(f'cancel failed: {playbook_run_id} {self.client.to_dict()}')

@_is_connected
def create_artifact(
Expand Down Expand Up @@ -170,7 +172,7 @@ def create_artifact(
log.info(f'artifact exists. {artifact} {self.client.to_dict()}')
return self.get_artifact(artifact_id=existing_artifact_id)

log.error(f'create artifact. {self.client.to_dict()}', enable_traceback=False)
log.error(f'create artifact. {self.client.to_dict()}')
return False

@_is_connected
Expand Down Expand Up @@ -239,7 +241,7 @@ def create_container(
response = CreateContainerResponse(self.client.to_dict())
log.info(f'container created. {container} {response}')
return response
log.error(f'create container. {self.client.to_dict()}', enable_traceback=False)
log.error(f'create container. {self.client.to_dict()}')
return False

@staticmethod
Expand Down Expand Up @@ -274,7 +276,7 @@ def create_container_attachment(
log.info(f'create attachment: {response}')
return response

log.error(f'create attachment failed.', raise_exception=False)
log.error(f'create attachment failed.')

@_is_connected
def create_vault(
Expand All @@ -299,7 +301,7 @@ def create_vault(
log.info(msg=f'add vault: {response}')
return response

log.error(msg=f'add vault failed.', raise_exception=False)
log.error(msg=f'add vault failed.')

@_is_connected
def delete_container(self, container_id, *args, **kwargs):
Expand All @@ -310,7 +312,7 @@ def delete_container(self, container_id, *args, **kwargs):
if self.client.results.status_code == 200:
log.info(f'container deleted: {container_id}')
return True
log.error(f'delete container: {container_id}. {self.client.to_dict()}', enable_traceback=False)
log.error(f'delete container: {container_id}. {self.client.to_dict()}')
return False

def is_connected(self) -> bool:
Expand Down Expand Up @@ -350,7 +352,7 @@ def generic_delete(self, api: str, **kwargs) -> Optional[GenericResponse]:
log.info(f'generic delete {api}: {response}')
return response

log.error(f'failed generic delete {api}', raise_exception=False)
log.error(f'failed generic delete {api}')

@_is_connected
def generic_get(self, api: str, **kwargs) -> Optional[GenericResponse]:
Expand All @@ -360,7 +362,7 @@ def generic_get(self, api: str, **kwargs) -> Optional[GenericResponse]:
log.info(f'generic get {api}: {response}')
return response

log.error(f'failed generic get {api}', raise_exception=False)
log.error(f'failed generic get {api}')

@_is_connected
def generic_post(self, api: str, data: dict, **kwargs) -> Optional[GenericResponse]:
Expand All @@ -370,7 +372,7 @@ def generic_post(self, api: str, data: dict, **kwargs) -> Optional[GenericRespon
log.info(f'generic post {api}: {response}')
return response

log.error(f'failed generic post {api}', raise_exception=False)
log.error(f'failed generic post {api}')

@_is_connected
def get_action_run(self, action_run_id: int = None, **kwargs) -> ActionRun:
Expand All @@ -380,7 +382,7 @@ def get_action_run(self, action_run_id: int = None, **kwargs) -> ActionRun:
log.info(f'get action run: {action_run}')
return action_run

log.error(f'action run not found: {action_run_id}', enable_traceback=False)
log.error(f'action run not found: {action_run_id}')
return ActionRun()

@_is_connected
Expand All @@ -391,7 +393,7 @@ def get_artifact(self, artifact_id: int = None, **kwargs) -> Artifact:
log.info(f'get artifact: {artifact}')
return artifact

log.error(f'artifact not found: {artifact_id}', enable_traceback=False)
log.error(f'artifact not found: {artifact_id}')
return Artifact()

@_is_connected
Expand All @@ -402,7 +404,7 @@ def get_container(self, container_id: int = None, **kwargs) -> Container:
log.info(f'get container: {container}')
return container

log.error(f'container not found: {container_id}', enable_traceback=False)
log.error(f'container not found: {container_id}')
return Container()

@_is_connected
Expand All @@ -415,10 +417,10 @@ def get_playbook_run(self, playbook_run_id: str, **kwargs) -> Optional[PlaybookR
log.info(f'playbook run: {response}')
return response

log.error(f'playbook run failed: {response.message_to_dict}', enable_traceback=False)
log.error(f'playbook run failed: {response.message_to_dict}')
return response

log.error(f'playbook failed: {self.client.errors}', enable_traceback=False)
log.error(f'playbook failed: {self.client.errors}')

@_is_connected
def get_vault(self, vault_id: int, **kwargs) -> Optional[Vault]:
Expand All @@ -429,7 +431,7 @@ def get_vault(self, vault_id: int, **kwargs) -> Optional[Vault]:
log.info(msg=f'get vault: {response}')
return response

log.error(msg=f'get vault failed: {self.client.to_dict()}', raise_exception=False)
log.error(msg=f'get vault failed: {self.client.to_dict()}')

@_is_connected
def list_artifact(self, **kwargs) -> Response:
Expand Down Expand Up @@ -502,7 +504,7 @@ def list_app_run_generator(
return True

elif response.data is None:
log.error(f'list app runs failed', enable_traceback=True)
log.error(f'list app runs failed')
return False

else:
Expand Down Expand Up @@ -569,7 +571,7 @@ def list_artifact_generator(
return True

elif response.data is None:
log.error(f'list container failed', enable_traceback=True)
log.error(f'list container failed')
return False

else:
Expand Down Expand Up @@ -600,7 +602,7 @@ def list_containers(
response = Response(self._content_dict())
log.info(f'list containers: {len(response.data)}')
return response
log.error(f'no containers', enable_traceback=False)
log.error(f'no containers')
return Response()

@_is_connected
Expand Down Expand Up @@ -642,7 +644,7 @@ def list_containers_generator(
break

elif response.data is None:
log.error(f'list container failed', enable_traceback=True)
log.error(f'list container failed')
break

else:
Expand All @@ -666,7 +668,7 @@ def list_vault(self, **kwargs) -> Optional[VaultResponse]:
log.info(msg=f'list vault: {response}')
return response

log.error(msg=f'list vault failed.', raise_exception=False)
log.error(msg=f'list vault failed.')

@_is_connected
def list_vault_generator(
Expand Down Expand Up @@ -705,7 +707,7 @@ def list_vault_generator(
break

elif response.data is None:
log.error(f'list vault failed', enable_traceback=True)
log.error(f'list vault failed')
break

else:
Expand Down Expand Up @@ -733,7 +735,7 @@ def update_playbook(
log.info(f'update playbook: {data}')
return response

log.error(f'update failed: {self.client.to_dict()}', enable_traceback=False)
log.error(f'update failed: {self.client.to_dict()}')

@_is_connected
def run_playbook(
Expand All @@ -757,4 +759,4 @@ def run_playbook(
log.info(f'run playbook: {data}')
return response

log.error(f'run failed: {self.client.to_dict()}', enable_traceback=False)
log.error(f'run failed: {self.client.to_dict()}')
5 changes: 3 additions & 2 deletions automon/integrations/splunk_soar/config.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
from automon.log import Logging
from automon.log import logger
from automon.helpers.osWrapper import environ

log = Logging(name='SplunkSoarConfig', level=Logging.DEBUG)
log = logger.logging.getLogger(__name__)
log.setLevel(logger.DEBUG)


class SplunkSoarConfig:
Expand Down
5 changes: 3 additions & 2 deletions automon/integrations/splunk_soar/container.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import datetime

from automon.log import Logging
from automon.log import logger

from .datatypes import AbstractDataType

log = Logging('Container', level=Logging.CRITICAL)
log = logger.logging.getLogger(__name__)
log.setLevel(logger.CRITICAL)


class Container(AbstractDataType):
Expand Down
5 changes: 3 additions & 2 deletions automon/integrations/splunk_soar/datatypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@

from dateutil import parser

from automon.log import Logging
from automon.log import logger

log = Logging('AbstractDataType', level=Logging.DEBUG)
log = logger.logging.getLogger(__name__)
log.setLevel(logger.DEBUG)


class AbstractDataType:
Expand Down
5 changes: 3 additions & 2 deletions automon/integrations/splunk_soar/responses.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,13 @@
from dateutil import parser
from typing import Optional

from automon.log import Logging
from automon.log import logger

from .container import Container
from .vault import Vault

log = Logging(name='Responses', level=Logging.DEBUG)
log = logger.logging.getLogger(__name__)
log.setLevel(logger.DEBUG)


class GeneralResponse:
Expand Down
6 changes: 4 additions & 2 deletions automon/integrations/splunk_soar/rest/urls.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
from automon.log import Logging
from automon.log import logger
from ..config import SplunkSoarConfig

config = SplunkSoarConfig()
log = Logging(name='Urls', level=Logging.DEBUG)

log = logger.logging.getLogger(__name__)
log.setLevel(logger.DEBUG)


class Urls:
Expand Down
5 changes: 3 additions & 2 deletions automon/integrations/splunk_soar/vault.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from automon.log import Logging
from automon.log import logger

from .datatypes import AbstractDataType

log = Logging('Vault', level=Logging.CRITICAL)
log = logger.logging.getLogger(__name__)
log.setLevel(logger.CRITICAL)


class Vault(AbstractDataType):
Expand Down

0 comments on commit 8d25500

Please sign in to comment.