Skip to content

Commit

Permalink
add logging option
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromeleonard committed Aug 29, 2017
1 parent eb4b47e commit 597bcab
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions ds2th.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


import os
import sys
import getopt
import getpass
import datetime
from io import BytesIO
import base64
import logging


from DigitalShadows.api import DigitalShadowsApi
from thehive4py.api import TheHiveApi
Expand Down Expand Up @@ -143,6 +145,7 @@ def get_incidents(dsapi, thapi, since):


for i in response.get('content'):
logging.debug('Incident number: {}'.format(i.get('id')))
alert = build_alert(i, {}, {"thumbnail":""})
thapi.create_alert(alert)

Expand All @@ -160,6 +163,7 @@ def get_intel_incidents(dsapi, thapi, since):
response = DigitalShadowsApi.find_intel_incident(dsapi, s).json()

for i in response.get('content'):
logging.debug('Intel-incident number: {}'.format(i.get('id')))
iocs = DigitalShadowsApi.get_intel_incident_iocs(dsapi, i.get('id')).json()

if i.get('entitySummary') and i.get('entitySummary').get('screenshotThumbnailId'):
Expand Down Expand Up @@ -200,18 +204,25 @@ def run(argv):

# get options
try:
opts, args = getopt.getopt(argv, 'ht:',["time="])
opts, args = getopt.getopt(argv, 'lht:',["log=","time="])
except getopt.GetoptError:
print(__file__ + " -t <time>")
sys.exit(2)

for opt, arg in opts:
if opt in ('-l', '--log'):
logging.basicConfig(filename='{}/ds2th.log'.format(os.path.dirname(os.path.realpath(__file__))),
level=arg, format='%(asctime)s %(levelname)s %(message)s')
logging.debug('logging enabled')

for opt,arg in opts:
if opt == '-h':
print(__file__ + " -t <time in minutes>")
sys.exit()
elif opt in ('-t','--time'):
time = arg


logging.info('ds2th.py started')
# get username and password for TheHive
if not TheHive['username'] and not TheHive['password']:
TheHive['username'] = input("TheHive Username [%s]: " % getpass.getuser())
Expand Down

0 comments on commit 597bcab

Please sign in to comment.