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
a2da30ac
Commit
a2da30ac
authored
7 years ago
by
Sven Mäder
Browse files
Options
Downloads
Patches
Plain Diff
First skeleton
parent
44edf06b
No related branches found
No related tags found
1 merge request
!12
Deltalogparse
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
bin/deltalogparse.py
+113
-9
113 additions, 9 deletions
bin/deltalogparse.py
with
113 additions
and
9 deletions
bin/deltalogparse.py
+
113
−
9
View file @
a2da30ac
#!/usr/bin/env python3
#!/usr/bin/env python3
import
sys
import
time
import
re
import
pprint
import
lib_path
import
lib_path
import
lib
import
lib
import
ldap3
import
ldap3
s
=
ldap3
.
Server
(
'
ldapi:///var/run/slapd/ldapi
'
,
get_info
=
[
ldap3
.
ALL
,
ldap3
.
OFFLINE_SLAPD_2_4
])
update_every
=
1
c
=
ldap3
.
Connection
(
s
,
authentication
=
ldap3
.
SASL
,
sasl_mechanism
=
ldap3
.
EXTERNAL
,
sasl_credentials
=
''
,
auto_bind
=
'
NONE
'
,
version
=
3
,
client_strategy
=
'
SYNC
'
)
c
.
bind
()
search_base
=
'
cn=deltalog
'
search_base
=
'
cn=deltalog
'
search_filter
=
'
(objectClass=auditModify)
'
search_filter
=
'
(
|(
objectClass=auditModify)
(objectClass=auditAdd)(objectClass=auditDelete))
'
search_scope
=
ldap3
.
SUBTREE
search_scope
=
ldap3
.
SUBTREE
attributes
=
[
ldap3
.
ALL_ATTRIBUTES
,
ldap3
.
ALL_OPERATIONAL_ATTRIBUTES
]
attributes
=
[
ldap3
.
ALL_ATTRIBUTES
,
ldap3
.
ALL_OPERATIONAL_ATTRIBUTES
]
r
=
c
.
search
(
search_base
=
search_base
,
search_filter
=
search_filter
,
search_scope
=
search_scope
,
attributes
=
attributes
)
rgx_filter
=
re
.
compile
(
if
r
==
True
:
r
'
^(
'
for
entry
in
c
.
response
:
r
'
heartbeatTimestamp|
'
print
(
entry
[
'
dn
'
],
entry
[
'
attributes
'
])
r
'
modifyTimestamp|
'
r
'
lastUse.*?|
'
r
'
(context|entry)CSN
'
r
'
):
'
)
def
is_filtered
(
attributes
):
for
attribute
in
attributes
:
if
not
rgx_filter
.
search
(
attribute
):
return
False
else
:
print
(
'
filter match: %s
'
%
attribute
)
return
True
def
backup
(
req_type
,
req_dn
,
entry
=
None
):
if
entry
:
attributes
=
dict
(
entry
[
'
attributes
'
])
entry
[
'
attributes
'
]
=
attributes
del
entry
[
'
raw_attributes
'
]
pprint
.
pprint
(
entry
,
indent
=
4
)
if
req_type
==
'
skip
'
:
print
(
'
skip: %s
'
%
req_dn
)
else
:
print
(
'
backup: %s %s
'
%
(
req_type
,
req_dn
))
def
main
():
"""
Connect to slapd socket and parse accesslog
"""
server
=
ldap3
.
Server
(
'
ldapi:///var/run/slapd/ldapi
'
,
get_info
=
[
ldap3
.
ALL
,
ldap3
.
OFFLINE_SLAPD_2_4
]
)
connection
=
ldap3
.
Connection
(
server
,
authentication
=
ldap3
.
SASL
,
sasl_mechanism
=
ldap3
.
EXTERNAL
,
sasl_credentials
=
''
,
auto_bind
=
'
NONE
'
,
version
=
3
,
client_strategy
=
'
SYNC
'
)
connection
.
bind
()
response
=
connection
.
search
(
search_base
=
search_base
,
search_filter
=
search_filter
,
search_scope
=
search_scope
,
attributes
=
attributes
)
while
True
:
start_time
=
time
.
perf_counter
()
req_start
=
None
if
response
:
#for entry in connection.entries:
# print(entry.entry_dn)
# print(entry['reqStart'])
for
entry
in
connection
.
response
:
req_start
=
entry
[
'
attributes
'
][
'
reqStart
'
][
0
]
req_type
=
entry
[
'
attributes
'
][
'
reqType
'
][
0
]
req_dn
=
entry
[
'
attributes
'
][
'
reqDN
'
][
0
]
print
(
'
'
.
join
([
'
\n
processing:
'
,
req_start
,
entry
[
'
dn
'
]]))
if
req_type
==
'
modify
'
:
req_mods
=
entry
[
'
attributes
'
][
'
reqMod
'
]
if
is_filtered
(
req_mods
):
backup
(
'
skip
'
,
req_dn
,
entry
)
continue
#backup(req_type, req_dn, entry=entry)
backup
(
req_type
,
req_dn
)
current_time
=
time
.
perf_counter
()
elapsed_time
=
current_time
-
start_time
sleep_time
=
update_every
-
elapsed_time
print
(
'
\n
runtime %0.3fs, sleeping %0.3fs
'
%
(
elapsed_time
,
sleep_time
))
if
sleep_time
>
0
:
time
.
sleep
(
sleep_time
)
#else:
# time.sleep(update_every)
response
=
connection
.
search
(
search_base
=
search_base
,
search_filter
=
search_filter
,
search_scope
=
search_scope
,
attributes
=
attributes
)
if
__name__
==
'
__main__
'
:
main
()
sys
.
exit
(
0
)
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