From f1ff0dc1d3bb6b3d21bd13e01421dd6adc6ac9b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Vysko=C4=8Dil?= <vyskocilpavel@muni.cz> Date: Sun, 16 Feb 2020 19:14:46 +0100 Subject: [PATCH] Rewrited ldap_status.sh * Using variable names in uppercase * Add time counter --- README.md | 17 +++++++++-------- ldap_status.sh | 36 ++++++++++++++++++++---------------- 2 files changed, 29 insertions(+), 24 deletions(-) diff --git a/README.md b/README.md index c643b01..bdfa8cd 100644 --- a/README.md +++ b/README.md @@ -82,20 +82,21 @@ This script checks if the LDAP servers are accessible * Attributes to be filled: <pre> # LDAP username - user="" + USER="" # LDAP password - password="" + PASSWORD="" # Base dn of LDAP tree - basedn="" + BASEDN="" - # eduPersonPrincipalName which will be searched - searchedIdentity="" + # eduPersonPrincipalName which the script will look for + IDENTITY="" - # List of LDPA hostnames separated by space - # Included ldap:// or ldaps:// - hostnames="" + # List of LDAP HOSTNAMES separated by whitespace + # Each value must start with ldap:// or ldaps:// + # For example: "ldaps://hostname.com ldap://hostname.com" + HOSTNAMES="" </pre> ## List of plugins diff --git a/ldap_status.sh b/ldap_status.sh index ef18c73..89729df 100755 --- a/ldap_status.sh +++ b/ldap_status.sh @@ -1,32 +1,36 @@ #!/bin/bash # LDAP username -user="" +USER="" # LDAP password -password="" +PASSWORD="" # Base dn of LDAP tree -basedn="" +BASEDN="" -# eduPersonPrincipalName which will be searched -searchedIdentity="" +# eduPersonPrincipalName which the script will look for +IDENTITY="" -# List of LDPA hostnames separated by space -# Included ldap:// or ldaps:// -hostnames="" +# List of LDAP HOSTNAMES separated by whitespace +# Each value must start with ldap:// or ldaps:// +# For example: "ldaps://hostname.com ldap://hostname.com" +HOSTNAMES="" -for hostname in $hostnames +for HOSTNAME in $HOSTNAMES do - if [[ -z $password ]]; then - ldapresult=$(ldapsearch -x -H $hostname -b $basedn "(eduPersonPrincipalNames=$searchedIdentity)" 2>&1) + START_TIME=$(date +%s%N) + if [[ -z $PASSWORD ]]; then + LDAP_RESULT=$(timeout 10 ldapsearch -x -H $HOSTNAME -b $BASEDN "(eduPersonPrincipalNames=$IDENTITY)" 2>&1) 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 - result=$? - if [[ $result == 0 ]]; then - echo "0 ldap_status-$hostname - OK" + RESULT=$? + END_TIME=$(date +%s%N) + 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 - echo "2 ldap_status-$hostname - $ldapresult" + echo "2 ldap_status-$HOSTNAME total_time=${TOTAL_TIME} ${LDAP_RESULT}" fi done -- GitLab