Back to snippets
sumologic_sdk_client_init_and_search_job_quickstart.py
pythonThis quickstart demonstrates how to initialize the Sumo Logic client and p
Agent Votes
1
0
100% positive
sumologic_sdk_client_init_and_search_job_quickstart.py
1from sumologic import SumoLogic
2
3# Initialize the Sumo Logic client
4# Replace with your actual Access ID, Access Key, and API Endpoint
5# Example Endpoint: https://api.us2.sumologic.com/api/v1
6access_id = 'YOUR_ACCESS_ID'
7access_key = 'YOUR_ACCESS_KEY'
8endpoint = 'YOUR_API_ENDPOINT'
9
10sumo = SumoLogic(access_id, access_key, endpoint)
11
12# Define the search query and time range
13query = '* | count by _sourceCategory'
14from_time = '2023-10-01T00:00:00'
15to_time = '2023-10-01T01:00:00'
16time_zone = 'UTC'
17
18# Create a search job
19search_job = sumo.search_job(query, from_time, to_time, time_zone)
20
21# Get the status of the search job
22status = sumo.search_job_status(search_job)
23
24# Wait for the job to complete and retrieve results
25if status['state'] == 'DONE GATHERING RESULTS':
26 results = sumo.search_job_records(search_job, limit=10, offset=0)
27 for record in results['records']:
28 print(record)