-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHpeLdapSearch.py
executable file
·41 lines (35 loc) · 1.12 KB
/
HpeLdapSearch.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
import subprocess
def get_user_info(email, fields):
ldapsearch = "/usr/bin/ldapsearch"
host = 'ldap.hp.com'
baseDN = 'ou=people,o=hp.com'
searchFilter = '(&(uid=' + email + '))'
cmd = [ldapsearch, '-x', '-LLL', '-h', host, '-b', baseDN, searchFilter] + fields
result = {}
# output = subprocess.check_output(["echo", "Hello World!"])
# print ("output",output)
output = subprocess.check_output(cmd).decode("utf-8").split('\n')
for line in output:
if ":" in line:
attribute, value = line.split(':', 1)
attribute = attribute.strip()
value = value.strip()
result.update({attribute: value})
return result
# if ":" in (output):
# attribute, value = output.split(':', 1)
# print ("attribute",attribute,value)
# output.split('\n')
# print ("output after split",output)
# for line in output:
# if ":" in output:
# attribute, value = output.split(':', 1)
# attribute = attribute.strip()
# value = value.strip()
# result.update({attribute: value})
# return result
def main():
fields = ["cn", "hpStatus"]
if __name__ == '__main__':
import sys
main()