Skip to content

Commit 70ab400

Browse files
committed
fix bugs
1 parent aef8c4d commit 70ab400

6 files changed

Lines changed: 50 additions & 58 deletions

examples/01_client_setup_and_queries.py

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""
1111

1212
import os
13-
import time
1413
from jupiterone import JupiterOneClient
1514

1615
def setup_client():
@@ -57,8 +56,8 @@ def basic_query_examples(j1):
5756
print(f"Found {len(hosts_with_apps)} host-application relationships\n")
5857

5958
# 4. Tree query
60-
print("4. Tree query for host hierarchy:")
61-
tree_result = j1.query_v1(query='FIND Host RETURN TREE LIMIT 5')
59+
print("4. Tree query for host relationships:")
60+
j1.query_v1(query='FIND Host with displayName = "server-001" THAT RELATES TO *RETURN TREE')
6261
print(f"Tree query completed\n")
6362

6463
# 5. Query with deleted entities
@@ -81,7 +80,7 @@ def pagination_examples(j1):
8180

8281
# 2. Limit and skip pagination
8382
print("2. Limit and skip pagination:")
84-
limit_skip_result = j1._limit_and_skip_query(
83+
j1._limit_and_skip_query(
8584
query="FIND User",
8685
skip=0,
8786
limit=100
@@ -91,9 +90,7 @@ def pagination_examples(j1):
9190
# 3. Deferred response for very large datasets
9291
print("3. Deferred response for large datasets:")
9392
deferred_result = j1.query_with_deferred_response(
94-
query="FIND UnifiedDevice",
95-
polling_interval=30, # seconds
96-
max_retries=10
93+
query="FIND UnifiedDevice"
9794
)
9895
print(f"Deferred response query completed with {len(deferred_result)} results\n")
9996

@@ -123,7 +120,7 @@ def complex_query_examples(j1):
123120
ORDER BY count(h) DESC
124121
LIMIT 10
125122
"""
126-
agg_result = j1.query_v1(query=agg_query)
123+
j1.query_v1(query=agg_query)
127124
print(f"Aggregation query completed\n")
128125

129126
# 3. Time-based query

examples/02_entity_management.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def update_entity_examples(j1, entity_id):
106106

107107
# 2. Update with tags
108108
print("2. Updating entity tags:")
109-
tag_update = j1.update_entity(
109+
j1.update_entity(
110110
entity_id=entity_id,
111111
properties={
112112
'tag.Status': 'maintenance',
@@ -118,7 +118,7 @@ def update_entity_examples(j1, entity_id):
118118

119119
# 3. Update with complex properties
120120
print("3. Updating with complex properties:")
121-
complex_update = j1.update_entity(
121+
j1.update_entity(
122122
entity_id=entity_id,
123123
properties={
124124
'isActive': False,
@@ -148,7 +148,7 @@ def delete_entity_examples(j1, entity_id):
148148

149149
# 2. Deletion with timestamp
150150
print("2. Deleting with specific timestamp:")
151-
timestamp_delete = j1.delete_entity(
151+
j1.delete_entity(
152152
entity_id=entity_id,
153153
timestamp=int(time.time()) * 1000
154154
)
@@ -316,7 +316,8 @@ def main():
316316
try:
317317
j1.delete_entity(entity_id=entity['entity']['_id'])
318318
print(f"Cleaned up: {entity['entity']['_id']}")
319-
except:
319+
except Exception:
320+
# Entity may already be deleted or not exist
320321
pass
321322

322323
print("\n✓ All entity management examples completed successfully!")

examples/03_relationship_management.py

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def update_relationship_examples(j1, relationship_id):
131131

132132
# 2. Update with complex properties
133133
print("2. Updating with complex properties:")
134-
complex_update = j1.update_relationship(
134+
j1.update_relationship(
135135
relationship_id=relationship_id,
136136
properties={
137137
'accessLevel': 'admin',
@@ -149,7 +149,7 @@ def update_relationship_examples(j1, relationship_id):
149149

150150
# 3. Update with tags
151151
print("3. Updating relationship tags:")
152-
tag_update = j1.update_relationship(
152+
j1.update_relationship(
153153
relationship_id=relationship_id,
154154
properties={
155155
'tag.Status': 'active',
@@ -172,7 +172,7 @@ def delete_relationship_examples(j1, relationship_id):
172172

173173
# 2. Deletion with timestamp
174174
print("2. Deleting with specific timestamp:")
175-
timestamp_delete = j1.delete_relationship(
175+
j1.delete_relationship(
176176
relationship_id=relationship_id,
177177
timestamp=int(time.time()) * 1000
178178
)
@@ -384,15 +384,17 @@ def main():
384384
try:
385385
j1.delete_relationship(relationship_id=rel['relationship']['_id'])
386386
print(f"Cleaned up relationship: {rel['relationship']['_id']}")
387-
except:
387+
except Exception:
388+
# Relationship may already be deleted or not exist
388389
pass
389390

390391
# Clean up entities
391392
try:
392393
j1.delete_entity(entity_id=from_entity_id)
393394
j1.delete_entity(entity_id=to_entity_id)
394395
print(f"Cleaned up entities")
395-
except:
396+
except Exception:
397+
# Entities may already be deleted or not exist
396398
pass
397399

398400
print("\n✓ All relationship management examples completed successfully!")

examples/04_integration_management.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
"""
1212

1313
import os
14-
import time
1514
from jupiterone import JupiterOneClient
1615

1716
def setup_client():
@@ -251,7 +250,7 @@ def batch_upload_examples(j1, job_id):
251250
]
252251

253252
try:
254-
entities_result = j1.upload_entities_batch_json(
253+
j1.upload_entities_batch_json(
255254
instance_job_id=job_id,
256255
entities_list=entities_payload
257256
)
@@ -286,7 +285,7 @@ def batch_upload_examples(j1, job_id):
286285
]
287286

288287
try:
289-
relationships_result = j1.upload_relationships_batch_json(
288+
j1.upload_relationships_batch_json(
290289
instance_job_id=job_id,
291290
relationships_list=relationships_payload
292291
)
@@ -340,7 +339,7 @@ def batch_upload_examples(j1, job_id):
340339
}
341340

342341
try:
343-
combined_result = j1.upload_combined_batch_json(
342+
j1.upload_combined_batch_json(
344343
instance_job_id=job_id,
345344
combined_payload=combined_payload
346345
)
@@ -379,7 +378,7 @@ def bulk_delete_example(j1, job_id):
379378
print("Uploaded entities for deletion test")
380379

381380
# Then bulk delete them
382-
delete_result = j1.bulk_delete_entities(
381+
j1.bulk_delete_entities(
383382
instance_job_id=job_id,
384383
entities_list=entities_to_delete
385384
)
@@ -417,9 +416,6 @@ def main():
417416
print("Note: These examples require a valid sync job ID to run")
418417
print("The structure is shown for reference\n")
419418

420-
# Example job ID (replace with actual job ID when testing)
421-
example_job_id = "example-job-id"
422-
423419
# Show batch upload structure
424420
print("Batch upload structure would include:")
425421
print("- Upload entities batch")

examples/05_alert_rules_and_smartclasses.py

Lines changed: 27 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010
"""
1111

1212
import os
13-
import time
1413
from jupiterone import JupiterOneClient
1514

1615
def setup_client():
@@ -97,33 +96,33 @@ def alert_rule_with_actions_examples(j1):
9796
]
9897
}
9998

100-
# 3. Jira ticket creation action configuration
101-
jira_action_config = {
102-
"integrationInstanceId": "your-jira-integration-id", # Replace with actual ID
103-
"type": "CREATE_JIRA_TICKET",
104-
"entityClass": "Record",
105-
"summary": "Security Violation Detected",
106-
"issueType": "Bug",
107-
"project": "SEC",
108-
"additionalFields": {
109-
"description": {
110-
"type": "doc",
111-
"version": 1,
112-
"content": [
113-
{
114-
"type": "paragraph",
115-
"content": [
116-
{
117-
"type": "text",
118-
"text": "{{alertWebLink}}\n\n**Affected Items:**\n\n* {{queries.query0.data|mapProperty('displayName')|join('\n* ')}}"
119-
}
120-
]
121-
}
122-
]
123-
},
124-
"labels": ["security", "automated", "jupiterone"]
125-
}
126-
}
99+
# 3. Jira ticket creation action configuration (commented out as it requires specific integration ID)
100+
# jira_action_config = {
101+
# "integrationInstanceId": "your-jira-integration-id", # Replace with actual ID
102+
# "type": "CREATE_JIRA_TICKET",
103+
# "entityClass": "Record",
104+
# "summary": "Security Violation Detected",
105+
# "issueType": "Bug",
106+
# "project": "SEC",
107+
# "additionalFields": {
108+
# "description": {
109+
# "type": "doc",
110+
# "version": 1,
111+
# "content": [
112+
# {
113+
# "type": "paragraph",
114+
# "content": [
115+
# {
116+
# "type": "text",
117+
# "text": "{{alertWebLink}}\n\n**Affected Items:**\n\n* {{queries.query0.data|mapProperty('displayName')|join('\n* ')}}"
118+
# }
119+
# ]
120+
# }
121+
# ]
122+
# },
123+
# "labels": ["security", "automated", "jupiterone"]
124+
# }
125+
# }
127126

128127
# Create alert rule with webhook action
129128
print("1. Creating alert rule with webhook action:")

examples/06_advanced_operations.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -310,13 +310,10 @@ def pagination_techniques_examples(j1):
310310
print()
311311

312312
# 3. Deferred response with custom polling
313-
print("3. Deferred response with custom polling:")
313+
print("3. Deferred response for large datasets:")
314314
try:
315315
deferred_results = j1.query_with_deferred_response(
316-
query="FIND UnifiedDevice",
317-
polling_interval=60, # Poll every 60 seconds
318-
max_retries=5, # Maximum 5 retries
319-
timeout=300 # 5 minute timeout
316+
query="FIND UnifiedDevice"
320317
)
321318
print(f"Deferred response query completed with {len(deferred_results)} results")
322319
except Exception as e:

0 commit comments

Comments
 (0)