|
5 | 5 |
|
6 | 6 | account = os.environ.get("JUPITERONE_ACCOUNT")
|
7 | 7 | token = os.environ.get("JUPITERONE_TOKEN")
|
| 8 | +url = "https://graphql.us.jupiterone.io" |
8 | 9 |
|
9 |
| -j1 = JupiterOneClient(account=account, token=token) |
| 10 | +j1 = JupiterOneClient(account=account, token=token, url=url) |
10 | 11 |
|
11 | 12 | # query_v1
|
12 | 13 | q = "FIND jupiterone_user"
|
13 | 14 | query_r = j1.query_v1(q)
|
| 15 | +print("query_v1()") |
14 | 16 | print(query_r)
|
15 | 17 |
|
16 | 18 | # create_entity
|
|
31 | 33 | properties=properties,
|
32 | 34 | timestamp=int(time.time()) * 1000 # Optional, defaults to current datetime
|
33 | 35 | )
|
| 36 | +print("create_entity()") |
34 | 37 | print(create_r)
|
35 | 38 |
|
36 | 39 | properties = {
|
|
42 | 45 | entity_id='{}'.format(create_r['entity']['_id']),
|
43 | 46 | properties=properties
|
44 | 47 | )
|
| 48 | +print("update_entity()") |
45 | 49 | print(update_r)
|
46 | 50 |
|
47 | 51 | # create_entity_2
|
|
61 | 65 | properties=properties,
|
62 | 66 | timestamp=int(time.time()) * 1000 # Optional, defaults to current datetime
|
63 | 67 | )
|
| 68 | +print("create_entity()") |
64 | 69 | print(create_r_2)
|
65 | 70 |
|
66 | 71 | # create_relationship
|
|
71 | 76 | from_entity_id=create_r['entity']['_id'],
|
72 | 77 | to_entity_id=create_r_2['entity']['_id'],
|
73 | 78 | )
|
| 79 | +print("create_relationship()") |
74 | 80 | print(create_relationship_r)
|
75 | 81 |
|
76 | 82 | # delete_relationship
|
77 | 83 | delete_relationship_r = j1.delete_relationship(relationship_id=create_relationship_r['relationship']['_id'])
|
| 84 | +print("delete_relationship()") |
78 | 85 | print(delete_relationship_r)
|
79 | 86 |
|
80 | 87 | # delete_entity
|
81 | 88 | delete_entity_r1 = j1.delete_entity(entity_id=create_r['entity']['_id'])
|
| 89 | +print("delete_entity()") |
82 | 90 | print(delete_entity_r1)
|
83 | 91 |
|
84 | 92 | delete_entity_r2 = j1.delete_entity(entity_id=create_r_2['entity']['_id'])
|
| 93 | +print("delete_entity()") |
85 | 94 | print(delete_entity_r2)
|
86 | 95 |
|
| 96 | +# cursor_query |
87 | 97 | q = "FIND Person"
|
88 | 98 | cursor_query_r = j1._cursor_query(q)
|
| 99 | +print("cursor_query()") |
89 | 100 | print(cursor_query_r)
|
90 |
| -print(len(cursor_query_r['data'])) |
| 101 | + |
| 102 | +# fetch_all_entity_properties |
| 103 | +fetch_all_entity_properties_r = j1.fetch_all_entity_properties() |
| 104 | +print("fetch_all_entity_properties()") |
| 105 | +print(fetch_all_entity_properties_r) |
| 106 | + |
| 107 | +# fetch_all_entity_tags |
| 108 | +fetch_all_entity_tags_r = j1.fetch_all_entity_tags() |
| 109 | +print("fetch_all_entity_tags()") |
| 110 | +print(fetch_all_entity_tags_r) |
| 111 | + |
| 112 | +# create_integration_instance |
| 113 | +create_integration_instance_r = j1.create_integration_instance(instance_name="pythonclient-customintegration", |
| 114 | + instance_description="dev-testing") |
| 115 | +print("create_integration_instance()") |
| 116 | +print(create_integration_instance_r) |
| 117 | + |
| 118 | +integration_instance_id = "<GUID>" |
| 119 | + |
| 120 | +# start_sync_job |
| 121 | +start_sync_job_r = j1.start_sync_job(instance_id=integration_instance_id) |
| 122 | +print("start_sync_job()") |
| 123 | +print(start_sync_job_r) |
| 124 | + |
| 125 | +# upload_entities_batch_json |
| 126 | +entity_payload = [ |
| 127 | + { |
| 128 | + "_key": "1", |
| 129 | + "_type": "pythonclient", |
| 130 | + "_class": "API", |
| 131 | + "displayName": "pythonclient1", |
| 132 | + "propertyName": "value", |
| 133 | + "relationshipProperty": "source", |
| 134 | + }, |
| 135 | + { |
| 136 | + "_key": "2", |
| 137 | + "_type": "pythonclient", |
| 138 | + "_class": "API", |
| 139 | + "displayName": "pythonclient2", |
| 140 | + "propertyName": "value" |
| 141 | + }, |
| 142 | + { |
| 143 | + "_key": "3", |
| 144 | + "_type": "pythonclient", |
| 145 | + "_class": "API", |
| 146 | + "displayName": "pythonclient3", |
| 147 | + "propertyName": "value" |
| 148 | + } |
| 149 | +] |
| 150 | + |
| 151 | +# update_entities_batch_json |
| 152 | +upload_entities_batch_json_r = j1.upload_entities_batch_json(instance_job_id=start_sync_job_r['job']['id'], |
| 153 | + entities_list=entity_payload) |
| 154 | +print("upload_entities_batch_json()") |
| 155 | +print(upload_entities_batch_json_r) |
| 156 | + |
| 157 | +# upload_relationships_batch_json |
| 158 | +relationships_payload = [ |
| 159 | + { |
| 160 | + "_key": "1:2", |
| 161 | + "_class": "EXTENDS", |
| 162 | + "_type": "pythonclient_extends_pythonclient", |
| 163 | + "_fromEntityKey": "1", |
| 164 | + "_toEntityKey": "2", |
| 165 | + "relationshipProperty": "value" |
| 166 | + }, |
| 167 | + { |
| 168 | + "_key": "2:3", |
| 169 | + "_class": "EXTENDS", |
| 170 | + "_type": "pythonclient_extends_pythonclient", |
| 171 | + "_fromEntityKey": "2", |
| 172 | + "_toEntityKey": "3", |
| 173 | + "relationshipProperty": "value" |
| 174 | + } |
| 175 | +] |
| 176 | + |
| 177 | +# update_relationships_batch_json |
| 178 | +upload_relationships_batch_json_r = j1.upload_relationships_batch_json(instance_job_id=start_sync_job_r['job']['id'], |
| 179 | + relationships_list=relationships_payload) |
| 180 | +print("upload_relationships_batch_json()") |
| 181 | +print(upload_relationships_batch_json_r) |
| 182 | + |
| 183 | +# upload_entities_batch_json |
| 184 | +combined_payload = { |
| 185 | + "entities": [ |
| 186 | + { |
| 187 | + "_key": "4", |
| 188 | + "_type": "pythonclient", |
| 189 | + "_class": "API", |
| 190 | + "displayName": "pythonclient4", |
| 191 | + "propertyName": "value", |
| 192 | + "relationshipProperty": "source", |
| 193 | + }, |
| 194 | + { |
| 195 | + "_key": "5", |
| 196 | + "_type": "pythonclient", |
| 197 | + "_class": "API", |
| 198 | + "displayName": "pythonclient5", |
| 199 | + "propertyName": "value" |
| 200 | + }, |
| 201 | + { |
| 202 | + "_key": "6", |
| 203 | + "_type": "pythonclient", |
| 204 | + "_class": "API", |
| 205 | + "displayName": "pythonclient6", |
| 206 | + "propertyName": "value" |
| 207 | + } |
| 208 | +], |
| 209 | + "relationships": [ |
| 210 | + { |
| 211 | + "_key": "4:5", |
| 212 | + "_class": "EXTENDS", |
| 213 | + "_type": "pythonclient_extends_pythonclient", |
| 214 | + "_fromEntityKey": "4", |
| 215 | + "_toEntityKey": "5", |
| 216 | + "relationshipProperty": "value" |
| 217 | + }, |
| 218 | + { |
| 219 | + "_key": "5:6", |
| 220 | + "_class": "EXTENDS", |
| 221 | + "_type": "pythonclient_extends_pythonclient", |
| 222 | + "_fromEntityKey": "5", |
| 223 | + "_toEntityKey": "6", |
| 224 | + "relationshipProperty": "value" |
| 225 | + } |
| 226 | +] |
| 227 | +} |
| 228 | + |
| 229 | +# upload_combined_batch_json |
| 230 | +upload_combined_batch_json_r = j1.upload_combined_batch_json(instance_job_id=start_sync_job_r['job']['id'], |
| 231 | + combined_payload=combined_payload) |
| 232 | +print("upload_combined_batch_json()") |
| 233 | +print(upload_combined_batch_json_r) |
| 234 | + |
| 235 | +# finalize_sync_job |
| 236 | +finalize_sync_job_r = j1.finalize_sync_job(instance_job_id=start_sync_job_r['job']['id']) |
| 237 | +print("finalize_sync_job()") |
| 238 | +print(finalize_sync_job_r) |
| 239 | + |
| 240 | +# fetch_integration_jobs |
| 241 | +fetch_integration_jobs_r = j1.fetch_integration_jobs(instance_id=integration_instance_id) |
| 242 | +print("fetch_integration_jobs()") |
| 243 | +print(fetch_integration_jobs_r) |
| 244 | + |
| 245 | +while j1.fetch_integration_jobs(instance_id=integration_instance_id)['jobs'][0]['status'] == "IN_PROGRESS": |
| 246 | + |
| 247 | + fetch_integration_jobs_r = j1.fetch_integration_jobs(instance_id=integration_instance_id) |
| 248 | + |
| 249 | + print("fetch_integration_jobs()") |
| 250 | + print(fetch_integration_jobs_r) |
| 251 | + |
| 252 | +# fetch_integration_job_events |
| 253 | +fetch_integration_job_events_r = j1.fetch_integration_job_events(instance_id=integration_instance_id, |
| 254 | + instance_job_id=fetch_integration_jobs_r['jobs'][0]['id']) |
| 255 | +print("fetch_integration_job_events()") |
| 256 | +print(fetch_integration_job_events_r) |
| 257 | + |
| 258 | +# create_smartclass |
| 259 | +create_smartclass_r = j1.create_smartclass(smartclass_name="SmartClass1", |
| 260 | + smartclass_description="Created via create_smartclass() method") |
| 261 | +print("create_smartclass()") |
| 262 | +print(create_smartclass_r) |
| 263 | + |
| 264 | +# create_smartclass_query |
| 265 | +create_smartclass_query_r = j1.create_smartclass_query(smartclass_id=create_smartclass_r['id'], |
| 266 | + query="FIND (Device|Host) with osType ~= \'Windows\'", |
| 267 | + query_description="all windows devices and hosts") |
| 268 | +print("create_smartclass_query()") |
| 269 | +print(create_smartclass_query_r) |
| 270 | + |
| 271 | +# evaluate_smartclass |
| 272 | +evaluate_smartclass_r = j1.evaluate_smartclass(smartclass_id=create_smartclass_query_r['smartClassId']) |
| 273 | +print("evaluate_smartclass()") |
| 274 | +print(evaluate_smartclass_r) |
| 275 | + |
| 276 | +# get_smartclass_details |
| 277 | +get_smartclass_details_r = j1.get_smartclass_details(smartclass_id=create_smartclass_query_r['smartClassId']) |
| 278 | +print("get_smartclass_details()") |
| 279 | +print(get_smartclass_details_r) |
| 280 | + |
| 281 | +# list_configured_alert_rules |
| 282 | +list_configured_alert_rules_r = j1.list_configured_alert_rules() |
| 283 | +print("list_configured_alert_rules()") |
| 284 | +print(list_configured_alert_rules_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) |
0 commit comments