Skip to content

Commit 149df57

Browse files
committed
fix typo
1 parent e252117 commit 149df57

2 files changed

Lines changed: 370 additions & 1 deletion

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ j1.update_entity(
9999
#### Delete an entity:
100100

101101
```python
102-
j1.delete_entity(entit_id='<id-of-entity-to-delete>')
102+
j1.delete_entity(entity_id='<id-of-entity-to-delete>')
103103
```
104104

105105
##### Create a relationship

examples/examples copy.py

Lines changed: 369 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,369 @@
1+
from jupiterone.client import JupiterOneClient
2+
import random
3+
import time
4+
import os
5+
from datetime import datetime
6+
import json
7+
8+
account = os.environ.get("JUPITERONE_ACCOUNT")
9+
token = os.environ.get("JUPITERONE_TOKEN")
10+
url = "https://graphql.us.jupiterone.io"
11+
12+
j1 = JupiterOneClient(account=account, token=token, url=url)
13+
14+
# # query_v1
15+
# q = 'FIND User WITH _type = "jupiterone_user" as i return i.*'
16+
# query_r = j1.query_v1(q)
17+
# print("query_v1()")
18+
# print(query_r)
19+
#
20+
# # create_entity
21+
# num1 = random.randrange(1, 999, 1)
22+
#
23+
# # create_entity
24+
# properties = {
25+
# 'displayName': 'test{}'.format(num1),
26+
# 'customProperty': 'customVal',
27+
# 'tag.Production': 'false',
28+
# 'owner': 'user.name@jupiterone.com'
29+
# }
30+
#
31+
# create_r = j1.create_entity(
32+
# entity_key='jupiterone-api-client-python:{}'.format(num1),
33+
# entity_type='python_client_create_entity',
34+
# entity_class='Record',
35+
# properties=properties,
36+
# timestamp=int(time.time()) * 1000 # Optional, defaults to current datetime
37+
# )
38+
# print("create_entity()")
39+
# print(create_r)
40+
#
41+
# properties = {
42+
# 'customProperty': 'customValUpdated'
43+
# }
44+
#
45+
# # update_entity
46+
# update_r = j1.update_entity(
47+
# entity_id='{}'.format(create_r['entity']['_id']),
48+
# properties=properties
49+
# )
50+
# print("update_entity()")
51+
# print(update_r)
52+
#
53+
# # create_entity_2
54+
# num2 = random.randrange(1, 999, 1)
55+
#
56+
# properties = {
57+
# 'displayName': 'test{}'.format(num2),
58+
# 'customProperty': 'customVal',
59+
# 'tag.Production': 'false',
60+
# 'owner': 'user.name@jupiterone.com'
61+
# }
62+
#
63+
# create_r_2 = j1.create_entity(
64+
# entity_key='jupiterone-api-client-python:{}'.format(num2),
65+
# entity_type='python_client_create_entity',
66+
# entity_class='Record',
67+
# properties=properties,
68+
# timestamp=int(time.time()) * 1000 # Optional, defaults to current datetime
69+
# )
70+
# print("create_entity()")
71+
# print(create_r_2)
72+
#
73+
# # create_relationship
74+
# create_relationship_r = j1.create_relationship(
75+
# relationship_key='{}:{}'.format(create_r['entity']['_id'], create_r_2['entity']['_id']),
76+
# relationship_type='jupiterone-api-client-python:create_relationship',
77+
# relationship_class='HAS',
78+
# from_entity_id=create_r['entity']['_id'],
79+
# to_entity_id=create_r_2['entity']['_id'],
80+
# )
81+
# print("create_relationship()")
82+
# print(create_relationship_r)
83+
#
84+
# # delete_relationship
85+
# delete_relationship_r = j1.delete_relationship(relationship_id=create_relationship_r['relationship']['_id'])
86+
# print("delete_relationship()")
87+
# print(delete_relationship_r)
88+
#
89+
# # delete_entity
90+
# delete_entity_r1 = j1.delete_entity(entity_id=create_r['entity']['_id'])
91+
# print("delete_entity()")
92+
# print(delete_entity_r1)
93+
#
94+
# delete_entity_r2 = j1.delete_entity(entity_id=create_r_2['entity']['_id'])
95+
# print("delete_entity()")
96+
# print(delete_entity_r2)
97+
#
98+
# # cursor_query
99+
# q = "FIND Person"
100+
# cursor_query_r = j1._cursor_query(q)
101+
# print("cursor_query()")
102+
# print(cursor_query_r)
103+
#
104+
# # fetch_all_entity_properties
105+
# fetch_all_entity_properties_r = j1.fetch_all_entity_properties()
106+
# print("fetch_all_entity_properties()")
107+
# print(fetch_all_entity_properties_r)
108+
#
109+
# # fetch_all_entity_tags
110+
# fetch_all_entity_tags_r = j1.fetch_all_entity_tags()
111+
# print("fetch_all_entity_tags()")
112+
# print(fetch_all_entity_tags_r)
113+
#
114+
# # create_integration_instance
115+
# create_integration_instance_r = j1.create_integration_instance(instance_name="pythonclient-customintegration",
116+
# instance_description="dev-testing")
117+
# print("create_integration_instance()")
118+
# print(create_integration_instance_r)
119+
#
120+
# integration_instance_id = "<ID>"
121+
# #
122+
# # start_sync_job
123+
# start_sync_job_r = j1.start_sync_job(instance_id=integration_instance_id,
124+
# sync_mode='PATCH',
125+
# source='integration-external')
126+
# print("start_sync_job()")
127+
# print(start_sync_job_r)
128+
#
129+
# # upload_entities_batch_json
130+
# rand_score_range = [x / 10.0 for x in range(0, 100)]
131+
# rand_score = random.choice(rand_score_range)
132+
#
133+
# now_dt = datetime.now()
134+
# epoch_now = round(datetime.strptime(str(now_dt), "%Y-%m-%d %H:%M:%S.%f").timestamp())
135+
#
136+
# entity_payload = [
137+
# {
138+
# "_key": "jupiterone_user:0014433b-e14e-49f8-967f-86b54a27b90d",
139+
# "enrichVal": rand_score,
140+
# "lastEnrichedOn": epoch_now
141+
# },
142+
# {
143+
# "_key": "jupiterone_user:28a5ab70-6ec3-49fc-bf37-df04c36bc6e1",
144+
# "enrichVal": rand_score,
145+
# "lastEnrichedOn": epoch_now
146+
# }
147+
# ]
148+
#
149+
# # update_entities_batch_json
150+
# upload_entities_batch_json_r = j1.upload_entities_batch_json(instance_job_id=start_sync_job_r['job']['id'],
151+
# entities_list=entity_payload)
152+
# print("upload_entities_batch_json()")
153+
# print(upload_entities_batch_json_r)
154+
#
155+
# # upload_relationships_batch_json
156+
# relationships_payload = [
157+
# {
158+
# "_key": "1:2",
159+
# "_class": "EXTENDS",
160+
# "_type": "pythonclient_extends_pythonclient",
161+
# "_fromEntityKey": "1",
162+
# "_toEntityKey": "2",
163+
# "relationshipProperty": "value"
164+
# },
165+
# {
166+
# "_key": "2:3",
167+
# "_class": "EXTENDS",
168+
# "_type": "pythonclient_extends_pythonclient",
169+
# "_fromEntityKey": "2",
170+
# "_toEntityKey": "3",
171+
# "relationshipProperty": "value"
172+
# }
173+
# ]
174+
#
175+
# # update_relationships_batch_json
176+
# upload_relationships_batch_json_r = j1.upload_relationships_batch_json(instance_job_id=start_sync_job_r['job']['id'],
177+
# relationships_list=relationships_payload)
178+
# print("upload_relationships_batch_json()")
179+
# print(upload_relationships_batch_json_r)
180+
#
181+
# # upload_entities_batch_json
182+
# combined_payload = {
183+
# "entities": [
184+
# {
185+
# "_key": "4",
186+
# "_type": "pythonclient",
187+
# "_class": "API",
188+
# "displayName": "pythonclient4",
189+
# "enrichProp": "value1"
190+
# },
191+
# {
192+
# "_key": "5",
193+
# "_type": "pythonclient",
194+
# "_class": "API",
195+
# "displayName": "pythonclient5",
196+
# "enrichProp": "value2"
197+
# },
198+
# {
199+
# "_key": "6",
200+
# "_type": "pythonclient",
201+
# "_class": "API",
202+
# "displayName": "pythonclient6",
203+
# "enrichProp": "value3"
204+
# }
205+
# ],
206+
# "relationships": [
207+
# {
208+
# "_key": "4:5",
209+
# "_class": "EXTENDS",
210+
# "_type": "pythonclient_extends_pythonclient",
211+
# "_fromEntityKey": "4",
212+
# "_toEntityKey": "5",
213+
# "relationshipProperty": "value"
214+
# },
215+
# {
216+
# "_key": "5:6",
217+
# "_class": "EXTENDS",
218+
# "_type": "pythonclient_extends_pythonclient",
219+
# "_fromEntityKey": "5",
220+
# "_toEntityKey": "6",
221+
# "relationshipProperty": "value"
222+
# }
223+
# ]
224+
# }
225+
#
226+
# # upload_combined_batch_json
227+
# upload_combined_batch_json_r = j1.upload_combined_batch_json(instance_job_id=start_sync_job_r['job']['id'],
228+
# combined_payload=combined_payload)
229+
# print("upload_combined_batch_json()")
230+
# print(upload_combined_batch_json_r)
231+
#
232+
# # finalize_sync_job
233+
# finalize_sync_job_r = j1.finalize_sync_job(instance_job_id=start_sync_job_r['job']['id'])
234+
# print("finalize_sync_job()")
235+
# print(finalize_sync_job_r)
236+
#
237+
# # fetch_integration_jobs
238+
# fetch_integration_jobs_r = j1.fetch_integration_jobs(instance_id=integration_instance_id)
239+
# print("fetch_integration_jobs()")
240+
# print(fetch_integration_jobs_r)
241+
#
242+
# while j1.fetch_integration_jobs(instance_id=integration_instance_id)['jobs'][0]['status'] == "IN_PROGRESS":
243+
#
244+
# fetch_integration_jobs_r = j1.fetch_integration_jobs(instance_id=integration_instance_id)
245+
#
246+
# print("fetch_integration_jobs()")
247+
# print(fetch_integration_jobs_r)
248+
# #
249+
# # query_v1
250+
# q = 'FIND User WITH _type = "jupiterone_user" as i return i.*'
251+
# query_r = j1.query_v1(q)
252+
# print("query_v1()")
253+
# print(query_r)
254+
# print(len(query_r['data']))
255+
#
256+
#
257+
# # fetch_integration_job_events
258+
# fetch_integration_job_events_r = j1.fetch_integration_job_events(instance_id=integration_instance_id,
259+
# instance_job_id=fetch_integration_jobs_r['jobs'][0]['id'])
260+
# print("fetch_integration_job_events()")
261+
# print(fetch_integration_job_events_r)
262+
#
263+
# # create_smartclass
264+
# create_smartclass_r = j1.create_smartclass(smartclass_name="SmartClass1",
265+
# smartclass_description="Created via create_smartclass() method")
266+
# print("create_smartclass()")
267+
# print(create_smartclass_r)
268+
#
269+
# # create_smartclass_query
270+
# create_smartclass_query_r = j1.create_smartclass_query(smartclass_id=create_smartclass_r['id'],
271+
# query="FIND (Device|Host) with osType ~= \'Windows\'",
272+
# query_description="all windows devices and hosts")
273+
# print("create_smartclass_query()")
274+
# print(create_smartclass_query_r)
275+
#
276+
# # evaluate_smartclass
277+
# evaluate_smartclass_r = j1.evaluate_smartclass(smartclass_id=create_smartclass_query_r['smartClassId'])
278+
# print("evaluate_smartclass()")
279+
# print(evaluate_smartclass_r)
280+
#
281+
# # get_smartclass_details
282+
# get_smartclass_details_r = j1.get_smartclass_details(smartclass_id=create_smartclass_query_r['smartClassId'])
283+
# print("get_smartclass_details()")
284+
# print(get_smartclass_details_r)
285+
#
286+
# # generate_j1ql
287+
# generate_j1ql_r = j1.generate_j1ql(natural_language_prompt="show me all Users containing 'jupiterone' in their email address")
288+
# print("generate_j1ql()")
289+
# print(generate_j1ql_r)
290+
291+
# # list_alert_rules
292+
# list_configured_alert_rules_r = j1.list_alert_rules()
293+
# # print("list_configured_alert_rules()")
294+
# print(json.dumps(list_configured_alert_rules_r, indent=1))
295+
# print(len(list_configured_alert_rules_r))
296+
297+
# update_alert_rule
298+
# update_alert_rule_r = j1.update_alert_rule(rule_id="36f2a661-b47d-4c1a-97a6-7c2905a45c80",
299+
# j1ql="Find DataStore LIMIT 123",
300+
# polling_interval="DISABLED",
301+
# tags=['newnewnew', 'naananana'],
302+
# tag_op="OVERWRITE")
303+
304+
# update_alert_rule_r = j1.update_alert_rule(rule_id="35091853-9e3a-4cef-86db-58a0f40343cb",
305+
# tags=['newTag1', 'newTag1'],
306+
# tag_op="OVERWRITE")
307+
308+
# update_alert_rule_r = j1.update_alert_rule(rule_id="36f2a661-b47d-4c1a-97a6-7c2905a45c80",
309+
# tags=['additionalTag1', 'additionalTag2'],
310+
# tag_op="APPEND")
311+
312+
# update_alert_rule_r = j1.update_alert_rule(rule_id="36f2a661-b47d-4c1a-97a6-7c2905a45c80",
313+
# j1ql="Find Internet")
314+
315+
# print("update_alert_rule()")
316+
# print(json.dumps(update_alert_rule_r, indent=1))
317+
318+
evaluate_alert_rule_r = j1.evaluate_alert_rule(rule_id="36f2a661-b47d-4c1a-97a6-7c2905a45c80")
319+
print("evaluate_alert_rule()")
320+
print(json.dumps(evaluate_alert_rule_r, indent=1))
321+
322+
323+
# for i in list_configured_alert_rules_r:
324+
# print(i['id'])
325+
326+
# # create_alert_rule
327+
# webhook_token = "<SECRET>"
328+
#
329+
# webhook_action_config = {
330+
# "type": "WEBHOOK",
331+
# "endpoint": "https://webhook.receiver.endpoint",
332+
# "headers": {
333+
# "Authorization": "Bearer {}".format(webhook_token),
334+
# },
335+
# "method": "POST",
336+
# "body": {
337+
# "queryData": "{{queries.query0.data}}"
338+
# }
339+
# }
340+
#
341+
# tag_entities_action_config = {
342+
# "type": "TAG_ENTITIES",
343+
# "entities": "{{queries.query0.data}}",
344+
# "tags": [
345+
# {
346+
# "name": "tagKey",
347+
# "value": "tagValue"
348+
# }
349+
# ]
350+
# }
351+
#
352+
353+
# for i in range(250):
354+
#
355+
# print(i)
356+
# i = str(i) + "-batch2"
357+
#
358+
# create_alert_rule_r = j1.create_alert_rule(name=f"{i}-10-22-24-name",
359+
# description=f"{i}-10-22-24-description",
360+
# tags=['tag1', 'tag2'],
361+
# polling_interval="DISABLED",
362+
# severity="INFO",
363+
# j1ql=f"find jupiterone_user")
364+
# print("create_alert_rule()")
365+
# print(create_alert_rule_r)
366+
#
367+
# delete_alert_rule_r = j1.delete_alert_rule(rule_id="78fa4bd1-b413-46d7-bffe-336051c2055d")
368+
# print("delete_alert_rule()")
369+
# print(delete_alert_rule_r)

0 commit comments

Comments
 (0)