
use lib '/usr/local/generic/perl_m';
use Net::LDAP;

$DBHOST= 'ldap';
$DBPORT= '2000';
$BASEDN= 'o=mycompany';

sub getHosts {

my ($arefHosts, $arefFilters)= @_;

#------------------------------------------------------------------------------
# This function actually generates the list of hosts that match our
# filters.
#------------------------------------------------------------------------------

my ($filter, $results, $record);
my ($ldap)= new Net::LDAP(
	$DBHOST,
	'-port'	=> $DBPORT
);

$ldap->ldapbind;

foreach $filter (@$arefFilters) {
	$results= $ldap->search (
		'-base'		=> $BASEDN,
		'-attrs'	=> 'hostname',
		'-filter'	=> $filter
	);

	foreach $record ($results->all_entries) {
		push(@$arefHosts, $record->get_attribute(hostname)->[0]);
	}
}

$ldap->unbind;

#------------------------------------------------------------------------------
# The end.
#------------------------------------------------------------------------------

}

1;
