Skip to content
Snippets Groups Projects
Unverified Commit f1ff0dc1 authored by Pavel Vyskočil's avatar Pavel Vyskočil
Browse files

Rewrited ldap_status.sh

* Using variable names in uppercase
* Add time counter
parent 046121c9
No related branches found
No related tags found
1 merge request!9Rewritten ldap_status.sh
...@@ -82,20 +82,21 @@ This script checks if the LDAP servers are accessible ...@@ -82,20 +82,21 @@ This script checks if the LDAP servers are accessible
* Attributes to be filled: * Attributes to be filled:
<pre> <pre>
# LDAP username # LDAP username
user="" USER=""
# LDAP password # LDAP password
password="" PASSWORD=""
# Base dn of LDAP tree # Base dn of LDAP tree
basedn="" BASEDN=""
# eduPersonPrincipalName which will be searched # eduPersonPrincipalName which the script will look for
searchedIdentity="" IDENTITY=""
# List of LDPA hostnames separated by space # List of LDAP HOSTNAMES separated by whitespace
# Included ldap:// or ldaps:// # Each value must start with ldap:// or ldaps://
hostnames="" # For example: "ldaps://hostname.com ldap://hostname.com"
HOSTNAMES=""
</pre> </pre>
## List of plugins ## List of plugins
......
#!/bin/bash #!/bin/bash
# LDAP username # LDAP username
user="" USER=""
# LDAP password # LDAP password
password="" PASSWORD=""
# Base dn of LDAP tree # Base dn of LDAP tree
basedn="" BASEDN=""
# eduPersonPrincipalName which will be searched # eduPersonPrincipalName which the script will look for
searchedIdentity="" IDENTITY=""
# List of LDPA hostnames separated by space # List of LDAP HOSTNAMES separated by whitespace
# Included ldap:// or ldaps:// # Each value must start with ldap:// or ldaps://
hostnames="" # For example: "ldaps://hostname.com ldap://hostname.com"
HOSTNAMES=""
for hostname in $hostnames for HOSTNAME in $HOSTNAMES
do do
if [[ -z $password ]]; then START_TIME=$(date +%s%N)
ldapresult=$(ldapsearch -x -H $hostname -b $basedn "(eduPersonPrincipalNames=$searchedIdentity)" 2>&1) if [[ -z $PASSWORD ]]; then
LDAP_RESULT=$(timeout 10 ldapsearch -x -H $HOSTNAME -b $BASEDN "(eduPersonPrincipalNames=$IDENTITY)" 2>&1)
else else
ldapresult=$(ldapsearch -x -H $hostname -D $user -w $password -b $basedn "(eduPersonPrincipalNames=$searchedIdentity)" 2>&1) LDAP_RESULT=$(timeout 10 ldapsearch -x -H $HOSTNAME -D $USER -w $PASSWORD -b $BASEDN "(eduPersonPrincipalNames=$IDENTITY)" 2>&1)
fi fi
result=$? RESULT=$?
if [[ $result == 0 ]]; then END_TIME=$(date +%s%N)
echo "0 ldap_status-$hostname - OK" TOTAL_TIME=$(echo "scale=4;$(expr ${END_TIME} - ${START_TIME}) / 1000000000" | bc -l)
if [[ $RESULT == 0 ]]; then
echo "0 ldap_status-$HOSTNAME total_time=${TOTAL_TIME} OK"
else else
echo "2 ldap_status-$hostname - $ldapresult" echo "2 ldap_status-$HOSTNAME total_time=${TOTAL_TIME} ${LDAP_RESULT}"
fi fi
done done
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment