Last active
November 16, 2021 07:27
-
-
Save yujiterada/a9f0ec36a8f72574727dd2ba14dd7849 to your computer and use it in GitHub Desktop.
Send a sample log to Datadog
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import json | |
| from dateutil.parser import parse as dateutil_parser | |
| from datadog_api_client.v2 import ApiClient, ApiException, Configuration | |
| from datadog_api_client.v2.api import logs_api | |
| from datadog_api_client.v2.models import * | |
| from pprint import pprint | |
| # See configuration.py for a list of all supported configuration parameters. | |
| configuration = Configuration() | |
| # Enter a context with an instance of the API client | |
| with ApiClient(configuration) as api_client: | |
| # Create an instance of the API class | |
| api_instance = logs_api.LogsApi(api_client) | |
| test = { | |
| "occurredAt": "2021-11-15T02:19:29.718001Z", | |
| "networkId": "L_7262054399134XXXXX", | |
| "type": "dhcp_lease", | |
| "description": "DHCP lease", | |
| "clientId": "kde4xxx", | |
| "clientDescription": "Apple TV 4K", | |
| "deviceSerial": "Q2QN-AUDP-XXXX", | |
| "deviceName": "MX65", | |
| "eventData": { | |
| "vap": "0", | |
| "vlan": "9", | |
| "ip": "192.168.9.100", | |
| "router": "192.168.9.254", | |
| "subnet": "255.255.255.0", | |
| "dns": "208.67.222.222 208.67.220.220", | |
| "duration": "86400", | |
| "server_ip": "192.168.9.254", | |
| "mx_mac": "e0:cb:bc:xx:xx:xx" | |
| }, | |
| "productType": "appliance" | |
| } | |
| body = HTTPLog([ | |
| HTTPLogItem( | |
| ddsource="meraki", | |
| message=json.dumps(test), | |
| service="event", | |
| ), | |
| ]) # HTTPLog | Log to send (JSON format). | |
| content_encoding = ContentEncoding("gzip") # ContentEncoding | HTTP header used to compress the media-type. (optional) | |
| # example passing only required values which don't have defaults set | |
| # and optional values | |
| try: | |
| # Send logs | |
| api_response = api_instance.submit_log(body, content_encoding=content_encoding) | |
| pprint(api_response) | |
| except ApiException as e: | |
| print("Exception when calling LogsApi->submit_log: %s\n" % e) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment