Skip to content

Commit

Permalink
Merge pull request #12 from becksteadn/build
Browse files Browse the repository at this point in the history
more verbose logging
  • Loading branch information
scriptingislife authored Feb 6, 2020
2 parents 1890a70 + c4af4a3 commit e444ee3
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 10 deletions.
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))

0 comments on commit e444ee3

Please sign in to comment.