This commit is contained in:
A Smith 2017-04-06 18:35:50 -05:00 коммит произвёл Brandon Myers
Родитель c2a4ac5aa9
Коммит f4e442b679
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 8AA79AD83045BBC7
2 изменённых файлов: 28 добавлений и 54 удалений

Просмотреть файл

@ -2,7 +2,7 @@
"mozdef": {
"url": "http://localhost:8080/events"
},
//Generate on https://manage{-dev}.{mozilla.}auth0.com/#/apis (Management API)
//Generate on https://auth0.com/docs/api/management/v2 (top left TOKEN GENERATOR)
"auth0": {
"reqnr": 100,
"token": "<add_token>",

Просмотреть файл

@ -19,7 +19,6 @@ except ImportError:
#Well hello there python2 user!
import urllib
quote_url = urllib.quote
import traceback
class DotDict(dict):
'''dict.item notation for dict()'s'''
@ -214,15 +213,7 @@ log_types=DotDict({
'fd': {
"event": 'Failed delegation',
"level": 3 # error
},
'seccft': {
"event": "Success Exchange (Client Credentials for Access Token)",
"level": 1
},
'feccft': {
"event": "Failed Exchange (Client Credentials for Access Token)",
"level": 1
}
}
})
def process_msg(mozmsg, msg):
@ -241,13 +232,7 @@ def process_msg(mozmsg, msg):
except KeyError:
pass
try:
details['type'] = log_types[msg.type].event
except KeyError:
#New message type, check https://manage-dev.mozilla.auth0.com/docs/api/management/v2#!/Logs/get_logs for ex.
debug('New auth0 message type, please add support: {}'.format(msg.type))
details['type'] = msg.type
details['type'] = log_types[msg.type].event
if log_types[msg.type].level == 3:
mozmsg.set_severity(mozdef.MozDefEvent.SEVERITY_ERROR)
elif log_types[msg.type].level > 3:
@ -267,18 +252,10 @@ def process_msg(mozmsg, msg):
except KeyError:
pass
try:
details['connection'] = msg.connection
except KeyError:
pass
details['auth0_client_id'] = msg.client_id
try:
details['auth0_client_id'] = msg.client_id
except KeyError:
pass
try:
details['username'] = msg.details.request.auth.user.name
details['username'] = msg.details.request.auth.user
details['action'] = msg.details.response.body.name
except KeyError:
try:
@ -288,19 +265,31 @@ def process_msg(mozmsg, msg):
pass
except AttributeError:
pass
try:
details['username'] = msg.user_name
except KeyError:
pass
details['username'] = msg.user_name
mozmsg.summary = "{mtype} {desc}".format(
mtype=details.type,
desc=details.description
try:
auth0details = msg.details.details
except KeyError:
auth0details = ""
if type(details.type) == unicode:
details.type = details.type.encode('utf8')
if type(details.description) == unicode:
details.description = details.description.encode('utf8')
if type(auth0details) == unicode:
auth0details = auth0details.encode('utf8')
mozmsg.summary = "{type} {desc} {auth0details}".format(
type=details.type,
desc=details.description,
auth0details=auth0details
)
mozmsg.details = details
mozmsg.details['auth0_raw'] = msg
#that's just too much data, IMO
#mozmsg.details['auth0_raw'] = msg
return mozmsg
def load_state(fpath):
@ -323,18 +312,6 @@ def save_state(fpath, state):
with open(fpath, mode='w') as fd:
fd.write(str(state)+'\n')
def byteify(input):
"""Convert input to ascii"""
if isinstance(input, dict):
return {byteify(key): byteify(value)
for key, value in input.iteritems()}
elif isinstance(input, list):
return [byteify(element) for element in input]
elif isinstance(input, unicode):
return input.encode('utf-8')
else:
return input
def fetch_auth0_logs(config, headers, fromid):
lastid = fromid
@ -362,9 +339,8 @@ def fetch_auth0_logs(config, headers, fromid):
mozmsg = mozdef.MozDefEvent(config.mozdef.url)
if config.DEBUG == 'True':
mozmsg.set_send_to_syslog(True, only_syslog=True)
mozmsg.hostname = config.auth0.url
mozmsg.source = config.auth0.url
mozmsg.tags = ['auth0']
msg = byteify(msg)
msg = DotDict(msg)
lastid = msg._id
@ -376,8 +352,6 @@ def fetch_auth0_logs(config, headers, fromid):
mozmsg.details['error'] = 'true'
mozmsg.details['errormsg'] = '"'+str(e)+'"'
mozmsg.summary = 'Failed to parse auth0 message'
if config.DEBUG == 'True':
traceback.print_exc()
mozmsg.send()
if have_totals:
@ -414,4 +388,4 @@ def main():
save_state(config.state_file, lastid)
if __name__ == "__main__":
main()
main()