diff --git a/lookup_plugins/ldap.py b/lookup_plugins/ldap.py index bd04a89a8c20a36334c06696def3772598e21b35..d7af6f9733b2660e930e432f9a093b7fb452849c 100644 --- a/lookup_plugins/ldap.py +++ b/lookup_plugins/ldap.py @@ -60,6 +60,19 @@ class LookupModule(LookupBase): result = [res.decode('utf-8') for res in result['ipHostNumber']] return result + def all_ip(self, host): + """ + Retrieve all IP addresses of a device + query('ldap', 'all_ip', HOST) + """ + interfaces_query_id = self.base.search(f"cn={host},ou=hosts,{self.base_dn}", ldap.SCOPE_ONELEVEL) + interfaces_result = self.base.result(interfaces_query_id) + result = [] + for dn, interface in interfaces_result[1]: + for ip in interface['ipHostNumber']: + result.append(ip.decode('utf-8')) + return result + def cn(self, host, vlan): """ Retrieve aliases of an interface of a device @@ -78,6 +91,18 @@ class LookupModule(LookupBase): result = [res.decode('utf-8') for res in result['cn']] return result + def all_cn(self, host): + """ + Retrieve all aliases addresses of a device + query('ldap', 'all_cn', HOST) + """ + interfaces_query_id = self.base.search(f"cn={host},ou=hosts,{self.base_dn}", ldap.SCOPE_ONELEVEL) + interfaces_result = self.base.result(interfaces_query_id) + result = [] + for dn, interface in interfaces_result[1]: + for cn in interface['cn']: + result.append(cn.decode('utf-8')) + return result def subnet_ipv4(self, subnet): """ @@ -99,8 +124,12 @@ class LookupModule(LookupBase): result = self.query(*terms[1:]) elif terms[0] == 'ip': result = self.ip(*terms[1:]) + elif terms[0] == 'all_ip': + result = self.all_ip(*terms[1:]) elif terms[0] == 'cn': result = self.cn(*terms[1:]) + elif terms[0] == 'all_cn': + result = self.all_cn(*terms[1:]) elif terms[0] == 'subnet_ipv4': result = self.subnet_ipv4(*terms[1:]) elif terms[0] == 'group':