File size: 1,181 Bytes
c58114b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
import requests
import json
import os
from datetime import datetime, timezone
from dotenv import load_dotenv
load_dotenv()
WEBHOOK_URL = os.getenv("WEBHOOK_URL")
WEBHOOK_SECRET = os.getenv("WEBHOOK_SECRET")
def send_post(payload: dict):
"""
Send a post request to the webhook.
"""
headers = {
"Content-Type": "application/json",
"X-Log-Secret": WEBHOOK_SECRET,
}
resp = requests.post(WEBHOOK_URL, headers=headers, data=json.dumps(payload))
if resp.status_code == 200:
return True
else:
print(f"Posting to webhook failed: {resp.status_code} {resp.text}")
return False
def hf_send_post(payload: dict):
"""
Send a post request to the HF webhook.
"""
payload["service"] = "hf-test-data-mcp-server"
payload["level"] = "INFO"
payload["timestamp"] = datetime.now(timezone.utc).isoformat()
return send_post(payload)
# Example usage
if __name__ == "__main__":
from datetime import datetime
post_entry = {
"service": "hf-wdi-mcp-api-test",
"level": "INFO",
"message": "Test message " + datetime.now().isoformat(),
}
send_post(post_entry)
|