Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
P
perun-proxy-utils
Manage
Activity
Members
Labels
Plan
Jira
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Analyze
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
Perun
Perun ProxyIdP
perun-proxy-utils
Commits
ac5eebd9
Commit
ac5eebd9
authored
2 years ago
by
Johana Supíková
Browse files
Options
Downloads
Patches
Plain Diff
feat: check LDAP availability
parent
d8f3b8cc
No related branches found
No related tags found
1 merge request
!28
feat: check LDAP availability
Pipeline
#278473
passed
2 years ago
Stage: test
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
perun/proxy/utils/nagios/check_ldap.py
+99
-0
99 additions, 0 deletions
perun/proxy/utils/nagios/check_ldap.py
setup.py
+1
-0
1 addition, 0 deletions
setup.py
with
100 additions
and
0 deletions
perun/proxy/utils/nagios/check_ldap.py
0 → 100644
+
99
−
0
View file @
ac5eebd9
#!/usr/bin/env python3
import
argparse
import
sys
import
time
from
ldap3
import
Server
,
Connection
,
SUBTREE
"""
check LDAP is available
"""
def
get_args
():
"""
Supports the command-line arguments listed below.
"""
parser
=
argparse
.
ArgumentParser
(
description
=
"
Check LDAP status
"
)
parser
.
add_argument
(
"
-u
"
,
"
--user
"
,
help
=
"
LDAP username
"
,
)
parser
.
add_argument
(
"
-p
"
,
"
--password
"
,
help
=
"
LDAP password, required when username is set
"
,
)
parser
.
add_argument
(
"
-b
"
,
"
--base
"
,
help
=
"
base dn of LDAP tree
"
,
required
=
True
,
)
parser
.
add_argument
(
"
-i
"
,
"
--identity
"
,
default
=
""
,
help
=
"
eduPersonPrincipalName which the script will look for
"
,
)
parser
.
add_argument
(
"
-q
"
,
"
--query
"
,
help
=
"
custom query to test LDAP connection
"
,
)
parser
.
add_argument
(
"
-t
"
,
"
--host
"
,
help
=
"
LDAP hostname,
'
ldaps://
'
will be prepended
"
,
required
=
True
,
)
return
parser
.
parse_args
()
def
call_ldap
(
username
,
password
,
base_dn
,
query
,
hostname
):
start_time
=
time
.
time
()
ldap_result
=
None
ldap_connection
=
None
try
:
ldap_server
=
Server
(
hostname
,
use_ssl
=
True
)
ldap_connection
=
Connection
(
ldap_server
,
user
=
username
,
password
=
password
)
ldap_connection
.
bind
()
ldap_connection
.
search
(
base_dn
,
query
,
SUBTREE
)
ldap_result
=
ldap_connection
.
entries
except
Exception
as
e
:
error_message
=
"
Failed to connect to LDAP:
"
+
str
(
e
)
finally
:
if
ldap_connection
is
not
None
:
ldap_connection
.
unbind
()
end_time
=
time
.
time
()
total_time
=
end_time
-
start_time
if
ldap_result
is
not
None
and
len
(
ldap_result
)
>
0
:
print
(
f
"
0 check_ldap - total_time=
{
total_time
:
.
4
f
}
OK
"
)
return
0
if
ldap_result
is
not
None
:
error_message
=
"
No result was returned from LDAP
"
print
(
f
"
2 check_ldap - total_time=
{
total_time
:
.
4
f
}
{
error_message
}
"
)
return
2
def
main
():
args
=
get_args
()
hostname
=
"
ldaps://
"
+
args
.
host
query
=
(
args
.
query
if
args
.
query
is
not
None
else
"
eduPersonPrincipalNames=
"
+
args
.
identity
)
query
=
f
"
(
{
query
}
)
"
return
call_ldap
(
args
.
user
,
args
.
password
,
args
.
base
,
query
,
hostname
)
if
__name__
==
"
__main__
"
:
sys
.
exit
(
main
())
This diff is collapsed.
Click to expand it.
setup.py
+
1
−
0
View file @
ac5eebd9
...
...
@@ -14,5 +14,6 @@ setuptools.setup(
"
docker~=6.0
"
,
"
beautifulsoup4~=4.12
"
,
"
requests~=2.31
"
,
"
ldap3~=2.9.1
"
,
],
)
This diff is collapsed.
Click to expand it.
Jednotné přihlášení test
@9008807
mentioned in commit
b17d9029
·
2 years ago
mentioned in commit
b17d9029
mentioned in commit b17d90293e7d17ebfb8bffe40289576652f4714e
Toggle commit list
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