Skip to content
Snippets Groups Projects
Commit 965ce873 authored by Sven Mäder's avatar Sven Mäder :speech_balloon:
Browse files

Move parts to library

parent 193f7be3
No related branches found
No related tags found
No related merge requests found
......@@ -17,7 +17,7 @@ import dphysldap
# security warning: using DEBUG may log sensitive data
# log levels: CRITICAL | ERROR | WARNING | INFO | DEBUG | NOTSET
# default: WARNING
log_level = logging.DEBUG
log_level = logging.INFO
script_name = 'deltalogparse'
deltalog_name = 'delta'
......@@ -55,7 +55,7 @@ re_redacted = (r'^('
r'userPassword'
r'):')
re_attribute = r'^(?P<key>[^:]+?)(?P<delim>:[-+=#] ?(; )?)(?P<value>.*)'
re_attribute = r'^(?P<key>[^:]+?)(?P<delim>:[-+=#] ?)(?P<value>.*)'
rgx_skip = re.compile(re_skip.encode('utf-8'))
rgx_filter = re.compile(re_filter.encode('utf-8'))
......@@ -134,7 +134,7 @@ def split_attribute(attribute):
return key, delim, value
def filtered(req_mods):
def filtered_req_mod(req_mods):
"""
Filter and decode reqMod attributes:
- not of interest: remove
......@@ -192,7 +192,7 @@ def write(entry):
entry['attributes'] = dict(entry['attributes'])
if 'reqMod' in entry['attributes']:
entry['attributes']['reqMod'] = filtered(entry['raw_attributes']['reqMod'])
entry['attributes']['reqMod'] = filtered_req_mod(entry['raw_attributes']['reqMod'])
del entry['raw_dn']
del entry['raw_attributes']
......@@ -223,33 +223,20 @@ def connect(slapd):
slapd.connect()
except:
log.exception('error: failed to connect! trying to reconnect...')
if slapd.reconnect():
log.error('connected to slapd')
slapd.connect_retry()
log.error('connected to slapd')
def get_byte_attrs():
"""Read the schema from slapd and extract byte attributes"""
def get_byte_attributes():
"""Get all byte type attributes"""
global rgx_byte
byte_attrs = list()
byte_syntaxes = set()
byte_syntaxes.add('1.3.6.1.4.1.1466.115.121.1.40')
log.info('connecting to slapd to get the schema...')
log.info('connecting to slapd to retrieve schema...')
slapd = dphysldap.Slapd(get_info='SCHEMA')
connect(slapd)
log.info('searching schema for octet string attribute types...')
if slapd.server.schema:
for key, value in slapd.server.schema.ldap_syntaxes.items():
if value.extensions:
for extension in value.extensions:
if extension[0] == 'X-NOT-HUMAN-READABLE' and extension[1][0] == 'TRUE':
byte_syntaxes.add(key)
for key, value in slapd.server.schema.attribute_types.items():
if value.syntax in byte_syntaxes:
byte_attrs.append(key)
byte_syntaxes = slapd.get_byte_syntaxes()
byte_attrs = slapd.get_byte_attributes(byte_syntaxes=byte_syntaxes)
for item in byte_syntaxes:
log.debug('byte syntax: {}'.format(item))
......@@ -266,7 +253,7 @@ def get_byte_attrs():
def get_req_start():
"""Get the timestamp of the last logged entry"""
"""Get the timestamp of the last logged entry or now"""
try:
log.info('trying to read last req from {}'.format(log_file_deltalog))
last_line = get_last_line(log_file_deltalog).decode('utf-8')
......@@ -288,7 +275,7 @@ def main():
init_log()
get_byte_attrs()
get_byte_attributes()
req_start = get_req_start()
log.info('connecting to slapd...')
......@@ -304,9 +291,9 @@ def main():
response = slapd.search(search_base, search_filter)
except:
log.exception('error: reading socket! trying to reconnect...')
if slapd.reconnect():
log.error('socket reconnected.')
continue
slapd.connect_retry()
log.error('socket reconnected.')
continue
if response:
for entry in slapd.response():
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment