#! /usr/bin/env bash

script="/root/ldap.pl"
submit="/usr/lib/nagios/plugins/libexec/submit_check_result"
contact_sync=$(perl "$script" 2>&1)
exit_code=$?

if [ $exit_code -ne 0 ]; then
        icinga_code=2
        if [ $exit_code -eq 2 ]; then
                icinga_code=1
        fi

else
        icinga_code=0
        contact_sync="Sync OK"
fi

$submit "localhost" "ad_contacts_sync" "$icinga_code" "$contact_sync"

exit 0

