Skip to content

Commit

Permalink
Format fixes + add tags
Browse files Browse the repository at this point in the history
  • Loading branch information
dtru-ddog committed Oct 25, 2023
1 parent 64ee5a5 commit 8f020da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
29 changes: 21 additions & 8 deletions Object Store/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def handler(ctx, data: io.BytesIO = None):
if not namespace:
logging.getLogger().error("No namespace provided")
return

bucket = additional_details.get("bucketName")
if not bucket:
logging.getLogger().error("No bucket provided")
Expand All @@ -41,22 +41,35 @@ def handler(ctx, data: io.BytesIO = None):
datafile = request_one_object(namespace, bucket, resource_name)
data = str(datafile, 'utf-8')

dd_host = os.environ['DATADOG_HOST']
dd_token = os.environ['DATADOG_TOKEN']
# Datadog endpoint URL and token to call the REST interface.
# These are defined in the func.yaml file.
try:
dd_host = os.environ['DATADOG_HOST']
dd_token = os.environ['DATADOG_TOKEN']
dd_tags = os.environ.get('DATADOG_TAGS', '')
except KeyError:
err_msg = "Could not find environment variables, \
please ensure DATADOG_HOST and DATADOG_TOKEN \
are set as environment variables."
logging.getLogger().error(err_msg)

for lines in data.splitlines():
logging.getLogger().info("lines %s", lines)
payload = {}
payload.update({"ddsource": source})
payload.update({"ddtags": dd_tags})
payload.update({"host": resource_name})
payload.update({"time": event_time})

payload.update({"ddsource": source})
payload.update({"service": service})

payload.update({"event": lines})

headers = {'Content-type': 'application/json', 'DD-API-KEY': dd_token}
req = requests.post(dd_host, data=json.dumps(payload), headers=headers)
try:
headers = {'Content-type': 'application/json', 'DD-API-KEY': dd_token}
req = requests.post(dd_host, data=json.dumps(payload), headers=headers)
except (Exception, ValueError) as ex:
logging.getLogger().info(str(ex))
return

logging.getLogger().info(req.text)


Expand Down
5 changes: 3 additions & 2 deletions Object Store/func.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ entrypoint: /python/bin/fdk /function/func.py handler
memory: 1024
timeout: 120
config:
DATADOG_HOST: https://http-intake.logs.datadoghq.com/v1/input
DATADOG_TOKEN: <DATADOG_API_TOKEN>
DATADOG_HOST: https://http-intake.logs.datadoghq.com/v1/input # DD Log Intake Host
DATADOG_TOKEN: <DATADOG_API_TOKEN> # DD API Token
# DATADOG_TAGS: prod # Tags associated with logs
3 changes: 3 additions & 0 deletions Service Connector Hub/func.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,14 @@ def process(body: dict):
try:
dd_host = os.environ['DATADOG_HOST']
dd_token = os.environ['DATADOG_TOKEN']
dd_tags = os.environ.get('DATADOG_TAGS', '')
except KeyError:
err_msg = "Could not find environment variables, \
please ensure DATADOG_HOST and DATADOG_TOKEN \
are set as environment variables."
logging.getLogger().error(err_msg)
if dd_tags:
payload.update({'ddtags': dd_tags})

# Invoke Datadog API with the payload.
# If the payload contains more than one log
Expand Down

0 comments on commit 8f020da

Please sign in to comment.