Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
python
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
isgphys
python
Commits
965ce873
Commit
965ce873
authored
7 years ago
by
Sven Mäder
Browse files
Options
Downloads
Patches
Plain Diff
Move parts to library
parent
193f7be3
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/deltalogparse.py
+16
-29
16 additions, 29 deletions
bin/deltalogparse.py
with
16 additions
and
29 deletions
bin/deltalogparse.py
+
16
−
29
View file @
965ce873
...
...
@@ -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
.
re
connect
()
:
log
.
error
(
'
connected to slapd
'
)
slapd
.
connect
_retry
()
log
.
error
(
'
connected to slapd
'
)
def
get_byte_attrs
():
"""
Read the schema from slapd and extract byt
e attributes
"""
def
get_byte_attr
ibute
s
():
"""
Get all byte typ
e 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
g
et
th
e schema...
'
)
log
.
info
(
'
connecting to slapd to
r
et
riev
e 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_attr
ibute
s
()
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
.
re
connect
()
:
log
.
error
(
'
socket reconnected.
'
)
continue
slapd
.
connect
_retry
()
log
.
error
(
'
socket reconnected.
'
)
continue
if
response
:
for
entry
in
slapd
.
response
():
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment