#!/usr/bin/python
#
# Version 0.1
#
# Initial release of localcheck in python to get version information of ndsd
#
# This check should be placed in /usr/lib/check_mk_agent/local and made executable with `chmod +x edir-version.py`
# The script assumes that you have exported the environment variables when installing eDirectory, if not it will fail/not get detected on discovery.

import subprocess

# The process to be executed
myexec = "ndsd"

# Attempt to execute the process, if successful output CheckMK formatted data, if not return nothing.
try:
    output = subprocess.check_output([myexec, "--version"])
    output_arr = output.split(' ')
    print("0 \"" +  output_arr[1] + "\" - Binary Version: " + output_arr[2] + ", DS Version: " + output_arr[3])

except subprocess.CalledProcessError as e:
    exit()