Skip to content

Commit 99d031a

Browse files
committed
add fetch_integration_jobs and fetch_integration_job_events
1 parent acd8868 commit 99d031a

File tree

2 files changed

+115
-4
lines changed

2 files changed

+115
-4
lines changed

jupiterone/client.py

Lines changed: 36 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,13 @@
2828
DELETE_RELATIONSHIP,
2929
CURSOR_QUERY_V1,
3030
CREATE_INSTANCE,
31+
INTEGRATION_JOB_VALUES,
32+
INTEGRATION_INSTANCE_EVENT_VALUES,
3133
ALL_PROPERTIES,
3234
CREATE_SMARTCLASS,
3335
CREATE_SMARTCLASS_QUERY,
3436
EVALUATE_SMARTCLASS,
35-
GET_SMARTCLASS_DETAILS
37+
GET_SMARTCLASS_DETAILS,
3638
)
3739

3840

@@ -240,7 +242,7 @@ def _limit_and_skip_query(
240242

241243
return {"data": results}
242244

243-
def _execute_syncapi_request(self, endpoint: str, payload: Dict):
245+
def _execute_syncapi_request(self, endpoint: str, payload: Dict = None) -> Dict:
244246
"""Executes POST request to SyncAPI endpoints"""
245247

246248
# 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):
266268
"JupiterOne API rate limit exceeded"
267269
)
268270
raise JupiterOneApiError(content.get("errors"))
269-
270271
return response.json()
271272

272273
elif response.status_code == 401:
@@ -518,14 +519,45 @@ def finalize_sync_job(self, instance_job_id: str = None):
518519

519520
return response
520521

522+
def fetch_integration_jobs(self, instance_id: str = None):
523+
"""Fetch Integration Job details from defined integration instance.
524+
525+
args:
526+
instance_id (str): The "integrationInstanceId" of the integration to fetch jobs from.
527+
"""
528+
variables = {
529+
"integrationInstanceId": instance_id,
530+
"size": 100
531+
}
532+
533+
response = self._execute_query(INTEGRATION_JOB_VALUES, variables=variables)
534+
535+
return response['data']['integrationJobs']
536+
537+
def fetch_integration_job_events(self, instance_id: str = None, instance_job_id: str = None):
538+
"""Fetch events within an integration job run.
539+
540+
args:
541+
instance_id (str): The integration Instance Id of the integration to fetch job events from.
542+
instance_job_id (str): The integration Job ID of the integration to fetch job events from.
543+
"""
544+
variables = {
545+
"integrationInstanceId": instance_id,
546+
"jobId": instance_job_id,
547+
"size": 1000
548+
}
549+
550+
response = self._execute_query(INTEGRATION_INSTANCE_EVENT_VALUES, variables=variables)
551+
552+
return response['data']['integrationEvents']
553+
521554
def create_smartclass(self, smartclass_name: str = None, smartclass_description: str = None):
522555
"""Creates a new Smart Class within Assets.
523556
524557
args:
525558
smartclass_name (str): The "Smart class name" for Smart Class to be created.
526559
smartclass_description (str): The "Description" for Smart Class to be created.
527560
"""
528-
529561
variables = {
530562
"input": {
531563
"tagName": smartclass_name,

jupiterone/constants.py

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,3 +222,82 @@
222222
}
223223
}
224224
"""
225+
226+
INTEGRATION_JOB_VALUES = """
227+
query IntegrationJobs(
228+
$status: IntegrationJobStatus
229+
$integrationInstanceId: String
230+
$integrationDefinitionId: String
231+
$integrationInstanceIds: [String]
232+
$cursor: String
233+
$size: Int
234+
) {
235+
integrationJobs(
236+
status: $status
237+
integrationInstanceId: $integrationInstanceId
238+
integrationDefinitionId: $integrationDefinitionId
239+
integrationInstanceIds: $integrationInstanceIds
240+
cursor: $cursor
241+
size: $size
242+
) {
243+
jobs {
244+
id
245+
status
246+
integrationInstanceId
247+
createDate
248+
endDate
249+
hasSkippedSteps
250+
integrationInstance {
251+
id
252+
name
253+
__typename
254+
}
255+
integrationDefinition {
256+
id
257+
title
258+
integrationType
259+
__typename
260+
}
261+
__typename
262+
}
263+
pageInfo {
264+
endCursor
265+
__typename
266+
}
267+
__typename
268+
}
269+
}
270+
"""
271+
272+
INTEGRATION_INSTANCE_EVENT_VALUES = """
273+
query ListEvents(
274+
$jobId: String!
275+
$integrationInstanceId: String!
276+
$cursor: String
277+
$size: Int
278+
) {
279+
integrationEvents(
280+
size: $size
281+
cursor: $cursor
282+
jobId: $jobId
283+
integrationInstanceId: $integrationInstanceId
284+
) {
285+
events {
286+
id
287+
name
288+
description
289+
createDate
290+
jobId
291+
level
292+
eventCode
293+
__typename
294+
}
295+
pageInfo {
296+
endCursor
297+
hasNextPage
298+
__typename
299+
}
300+
__typename
301+
}
302+
}
303+
"""

0 commit comments

Comments
 (0)