#!/bin/bash
#
# Version 0.1
#
# Initial release of localcheck to get version information of ndsd via bash
# A similar check is available in this repository written in python (edir-version.py)
#
# This check should be placed in /usr/lib/check_mk_agent/local and made executable with `chmod +x edir-version.sh`

# Check if ndsd is present on the system, if not then exit (nothing to do)
# This assumes that you have exported the environment variables when installing eDirectory
/usr/bin/which ndsd >/dev/null 2>&1
if [ $? -ne 0 ]; then
    exit;
fi

# Execute command to retrieve information
VersionInfo=$(ndsd --version)

# Output formatted information to CheckMK
echo "0 \"$(echo $VersionInfo | awk '{ print $2 }')\" - Binary Version $(echo $VersionInfo | awk '{ print $3 }'), DS Version $(echo $VersionInfo | awk '{ print $4 }')"