#!/usr/bin/env bash
# File: /usr/lib/nagios/plugins/check_justconnect_ldap
#    0 - all ok
#    1 - warning
#    2 - critical
#    3 - unknown 

# Check if properties file has been specified
checkPropertiesFile() {
    if [ -z "$1" ]
    then
        echo "No ldap.properties file given."
        exit 3
    fi
    # read the properties
    . $1
}

checkPropertiesFile $1
ldapsearch -D "$USER_DN" -w "$PASSWORD" -b "$BASE" -H "$URL" "objectClass=justconnect_dummy_object" >/dev/null
RETVAL=$?
if [ "$RETVAL" = 0 ]; then
    echo "Connecting to ldap successfull." 
    exit 0
fi
echo "Failed to to connect to ldap."
exit 2