Hi @livehybrid , Apologies for the late reply, here's a copy of the code I'm using to generate the result from the API, maybe you can help if there's an issue on my code, thank you! # encoding = utf-8 import requests import json import time from datetime import datetime def validate_input(helper, definition): """Validate input stanza configurations in Splunk Add-on Builder.""" organization_id = definition.parameters.get('organization_id') api_key = definition.parameters.get('api_key') if not organization_id or not api_key: raise ValueError("Both 'organization_id' and 'api_key' are required.") def fetch_data(helper, start, organization_id, api_key): """Fetch data from the API with pagination while handling errors properly.""" url = f"https://xxx/xxx/xx/xxxxx/{organization_id}/xxxxx/availabilities?startingAfter={start}&perPage=1000" headers = {'API-Key-xxx': api_key, 'Content-Type': 'application/json'} try: helper.log_info(f"Fetching data with startingAfter: {start}") response = requests.get(url, headers=headers, timeout=10) # Set timeout for API call response.raise_for_status() data = response.json() helper.log_debug(f"Response Data: {json.dumps(data)[:500]}...") # Log partial data return data except requests.exceptions.Timeout: helper.log_error("Request timed out, stopping further requests to avoid infinite loops.") return None except requests.exceptions.RequestException as e: helper.log_error(f"Error during API request: {e}") return None def collect_events(helper, ew): """Collect events and send to Splunk Cloud while ensuring AppInspect compatibility.""" organization_id = helper.get_arg('organization_id') api_key = helper.get_arg('api_key') last_serial = "0000-0000-0000" results = [] while True: result = fetch_data(helper, last_serial, organization_id, api_key) if result and isinstance(result, list): current_date = datetime.utcnow().strftime('%Y-%m-%d %H:%M:%S') for item in result: item['current_date'] = current_date for item in result: event = helper.new_event( json.dumps(item), time=None, host="xxx", index=helper.get_output_index(), source=helper.get_input_type(), sourcetype="xxxxx" ) ew.write_event(event) if len(result) > 0 and 'serial' in result[-1]: last_serial = result[-1]['serial'] else: helper.log_info("No more data available, stopping collection.") break else: helper.log_warning("Empty response or error encountered, stopping.") break time.sleep(1) # Avoid hitting API rate limits helper.log_info("Data collection completed.")
... View more