Skip to content

Instantly share code, notes, and snippets.

@xen0l
Created May 12, 2022 13:47
Show Gist options
  • Select an option

  • Save xen0l/0b8e42afb0f705803bbf5c668ef2dac2 to your computer and use it in GitHub Desktop.

Select an option

Save xen0l/0b8e42afb0f705803bbf5c668ef2dac2 to your computer and use it in GitHub Desktop.

Revisions

  1. xen0l created this gist May 12, 2022.
    17 changes: 17 additions & 0 deletions sample_forwarder.py
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    def send_log_to_datadog(data, dd_api_token, ingestion_endpoint=LOG_INGESTION_ENDPOINT):
    try:
    req = requests.request(
    "POST",
    "https://{url}/v1/input".format(url=ingestion_endpoint),
    headers={"Content-Type": "application/json", "DD-API-KEY": dd_api_token},
    json=data,
    )
    req.raise_for_status()
    except requests.exceptions.HTTPError as err:
    print("HTTP Error:", err)
    except requests.exceptions.ConnectionError as err:
    print("Error while connecting:", err)
    except requests.exceptions.Timeout as err:
    print("Request timed out:", err)
    except requests.exceptions.RequestException as err:
    print("Error while sending logs:", err)