Showing posts with label ldap linux ldapsearch ad. Show all posts
Showing posts with label ldap linux ldapsearch ad. Show all posts

Thursday, September 1, 2011

LDAP search AD from linux: ldapsearch

So you have linux systems in a network that utilize LDAP via windows Active directory (AD), eh?  Yea, cool stuff.  The project came up as to how to monitor them, because the windows folks forget that a down domain controller (DC) means a down network.  I digress...

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

# Explanation: (of course the man page help too... :)
-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!