Skip to content

Instantly share code, notes, and snippets.

@bukzor
Created March 22, 2024 17:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bukzor/aca1789f520501c72d63a1c082cba411 to your computer and use it in GitHub Desktop.
Save bukzor/aca1789f520501c72d63a1c082cba411 to your computer and use it in GitHub Desktop.
#!/bin/env python3
# -*- coding: utf-8 -*-
import json
import os
import subprocess
import time
DD_API_BASE = "https://api.datadoghq.com"
DEFAULT_DATADOG_API_KEY = "f964b6d704a81c65acad65ba5c554c9d"
DATADOG_API_KEY = os.getenv("DATADOG_API_KEY") or os.getenv("DD_API_KEY") or DEFAULT_DATADOG_API_KEY
def send_event_payload_to_datadog(payload) -> None:
# API docs: https://docs.datadoghq.com/api/latest/events/#post-an-event
subprocess.check_call(
(
"curl",
"-sSL",
"--fail-with-body",
f"{DD_API_BASE}/api/v1/events",
"-XPOST",
"-H",
f"DD-API-KEY: DATADOG_API_KEY",
"-H",
"Content-Type: application/json",
"--data",
"=" + json.dumps(payload),
)
)
print("\nReported the action to DataDog events:")
def report_event_to_datadog(title: str, text: str, tags: dict) -> None:
payload = {
"title": title,
"text": text,
"tags": [f"{k}:{v}" for k, v in tags.items()],
"date_happened": int(time.time()),
"alert_type": "user_update",
}
return send_event_payload_to_datadog(payload)
def main():
# TODO: something useful
...
if __name__ == "__main__":
raise SystemExit(main())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment