Anywho, I was handed the project to monitor and alarm our AD (LDAP) domain controllers. I decided to write a nagios shell plugin, and the main query tool is the linux command: ldapsearch
# Example search
ldapsearch -x -D "user_name@example.com" -W -b "DC=example,DC=com" -h example.com "(sn=last_name)" cn displayName mail sn
# RESULTS:
# user_name, (other domain info returned here)
dn: CN=user_name,OU=one,OU=two,OU=three,DC=example,DC=com
cn: user_name
sn: last_name
displayName: Last, Name, M.
mail: mail_user_name@example.com
ldapsearch -x -D "user_name@example.com" -W -b "DC=example,DC=com" -h example.com "(sn=last_name)" cn displayName mail sn
# RESULTS:
# user_name, (other domain info returned here)
dn: CN=user_name,OU=one,OU=two,OU=three,DC=example,DC=com
cn: user_name
sn: last_name
displayName: Last, Name, M.
mail: mail_user_name@example.com
-x = simple search
-D = who to use for authentication
-W = ask for password (-w "password" otherwise)
-b = where to begin search
-h = domain controller address (-H ldaps://<address> otherwise)
"(sn=XYZ)" = search for sn (sir_name=XYZ) [known as filter]
last part with cn, displayName, etc... = what to return
Good luck!
No comments:
Post a Comment