Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

more verbose logging #12

Merged
merged 2 commits into from
Feb 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/lambda_function.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ def lambda_handler(event, context):

# Decode the url argument and fix if no protocol
url = urllib.parse.unquote(event['url'])

logging_help.log_msg('Scan requested for URL: {}'.format(url))

# Filter for potentially malicious or invalid URLs
filter(url)

Expand Down Expand Up @@ -81,7 +84,7 @@ def lambda_handler(event, context):
pp.pprint(return_data)

print('[!] Logging Scan')
logging_help.log_scan(db_data)
logging_help.log_msg('Existing data returned for hash {}'.format(url_hash))

return return_data

Expand Down
47 changes: 38 additions & 9 deletions src/logging_help.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,24 @@
import os
import boto3
import json
import time
import base64
import requests
from requests.auth import HTTPBasicAuth
from botocore.exceptions import ClientError

h_data = {"Content-Type": "application/json; charset=UTF-8"}

def get_env():
log_env = "unknown"

if "CI" in os.environ and os.environ.get("CI") == "true":
log_env = "test"
else:
log_env = "production"

return log_env

def get_secret():

secret_name = 'LogDNAIngestionKey' # os.environ['LOGGING_KEY']
Expand Down Expand Up @@ -71,17 +84,35 @@ def get_secret():

return json.loads(secret).get('logdna-ingestion')

def log_scan(db_data):
def log_msg(message):
log_env = get_env()

log_env = "unknown"
logdna = get_secret()

if "CI" in os.environ and os.environ.get("CI") == "true":
log_env = "test"
else:
log_env = "production"
logdata = {
"lines": [
{
"line": message,
"app": "glimpse",
"level": "INFO",
"env": log_env
}
]
}

submission = requests.post('https://logs.logdna.com/logs/ingest?hostname=GLIMPSE&now={}'.format(int(time.time())), json=logdata, headers=h_data, auth=HTTPBasicAuth(logdna, ''))

if submission.status_code != 200: # or submission.json['status'] != "ok":
raise ValueError('Got status {}'.format(submission.status_code))



def log_scan(db_data):
log_env = get_env()

logdna = get_secret()


logdata = {
"lines": [
{
Expand All @@ -101,9 +132,7 @@ def log_scan(db_data):
]
}

h_data = {"Content-Type": "application/json; charset=UTF-8"}

submission = requests.post('https://logs.logdna.com/logs/ingest?hostname=GLIMPSE', json=logdata, headers=h_data, auth=HTTPBasicAuth(logdna, ''))
submission = requests.post('https://logs.logdna.com/logs/ingest?hostname=GLIMPSE&now={}'.format(int(time.time())), json=logdata, headers=h_data, auth=HTTPBasicAuth(logdna, ''))

if submission.status_code != 200: # or submission.json['status'] != "ok":
raise ValueError('Got status {}'.format(submission.status_code))