From 99d031a5d9f1176000b95df51e16200a426fbe6f Mon Sep 17 00:00:00 2001 From: SeaBlooms Date: Wed, 28 Aug 2024 20:51:50 -0600 Subject: [PATCH] add fetch_integration_jobs and fetch_integration_job_events --- jupiterone/client.py | 40 ++++++++++++++++++--- jupiterone/constants.py | 79 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 4 deletions(-) diff --git a/jupiterone/client.py b/jupiterone/client.py index a25ef46..9f42fd8 100644 --- a/jupiterone/client.py +++ b/jupiterone/client.py @@ -28,11 +28,13 @@ DELETE_RELATIONSHIP, CURSOR_QUERY_V1, CREATE_INSTANCE, + INTEGRATION_JOB_VALUES, + INTEGRATION_INSTANCE_EVENT_VALUES, ALL_PROPERTIES, CREATE_SMARTCLASS, CREATE_SMARTCLASS_QUERY, EVALUATE_SMARTCLASS, - GET_SMARTCLASS_DETAILS + GET_SMARTCLASS_DETAILS, ) @@ -240,7 +242,7 @@ def _limit_and_skip_query( return {"data": results} - def _execute_syncapi_request(self, endpoint: str, payload: Dict): + def _execute_syncapi_request(self, endpoint: str, payload: Dict = None) -> Dict: """Executes POST request to SyncAPI endpoints""" # initiate requests session and implement retry logic of 5 request retries with 1 second between @@ -266,7 +268,6 @@ def _execute_syncapi_request(self, endpoint: str, payload: Dict): "JupiterOne API rate limit exceeded" ) raise JupiterOneApiError(content.get("errors")) - return response.json() elif response.status_code == 401: @@ -518,6 +519,38 @@ def finalize_sync_job(self, instance_job_id: str = None): return response + def fetch_integration_jobs(self, instance_id: str = None): + """Fetch Integration Job details from defined integration instance. + + args: + instance_id (str): The "integrationInstanceId" of the integration to fetch jobs from. + """ + variables = { + "integrationInstanceId": instance_id, + "size": 100 + } + + response = self._execute_query(INTEGRATION_JOB_VALUES, variables=variables) + + return response['data']['integrationJobs'] + + def fetch_integration_job_events(self, instance_id: str = None, instance_job_id: str = None): + """Fetch events within an integration job run. + + args: + instance_id (str): The integration Instance Id of the integration to fetch job events from. + instance_job_id (str): The integration Job ID of the integration to fetch job events from. + """ + variables = { + "integrationInstanceId": instance_id, + "jobId": instance_job_id, + "size": 1000 + } + + response = self._execute_query(INTEGRATION_INSTANCE_EVENT_VALUES, variables=variables) + + return response['data']['integrationEvents'] + def create_smartclass(self, smartclass_name: str = None, smartclass_description: str = None): """Creates a new Smart Class within Assets. @@ -525,7 +558,6 @@ def create_smartclass(self, smartclass_name: str = None, smartclass_description: smartclass_name (str): The "Smart class name" for Smart Class to be created. smartclass_description (str): The "Description" for Smart Class to be created. """ - variables = { "input": { "tagName": smartclass_name, diff --git a/jupiterone/constants.py b/jupiterone/constants.py index d242d6f..6874f1d 100644 --- a/jupiterone/constants.py +++ b/jupiterone/constants.py @@ -222,3 +222,82 @@ } } """ + +INTEGRATION_JOB_VALUES = """ + query IntegrationJobs( + $status: IntegrationJobStatus + $integrationInstanceId: String + $integrationDefinitionId: String + $integrationInstanceIds: [String] + $cursor: String + $size: Int + ) { + integrationJobs( + status: $status + integrationInstanceId: $integrationInstanceId + integrationDefinitionId: $integrationDefinitionId + integrationInstanceIds: $integrationInstanceIds + cursor: $cursor + size: $size + ) { + jobs { + id + status + integrationInstanceId + createDate + endDate + hasSkippedSteps + integrationInstance { + id + name + __typename + } + integrationDefinition { + id + title + integrationType + __typename + } + __typename + } + pageInfo { + endCursor + __typename + } + __typename + } + } +""" + +INTEGRATION_INSTANCE_EVENT_VALUES = """ + query ListEvents( + $jobId: String! + $integrationInstanceId: String! + $cursor: String + $size: Int + ) { + integrationEvents( + size: $size + cursor: $cursor + jobId: $jobId + integrationInstanceId: $integrationInstanceId + ) { + events { + id + name + description + createDate + jobId + level + eventCode + __typename + } + pageInfo { + endCursor + hasNextPage + __typename + } + __typename + } + } +""" \ No newline at end of file