bloxHub

www.infoblox.com/community
12 posts / 0 new
Infoblox API - Session "Search"

I'm wrinting a perl script which uses the "session -> search" method to look for a DNS Host record. In the code below The $hostname variable contains the FQDN of the host I'm searching for :

sub search4host {
my ($hostname) = @_;
my ($result, $response);

my $intView = Infoblox::DNS::View->new( name => 'Internal' );

my $searchHost = $session -> search (
object => "Infoblox::DNS::Record::Host",
name => "$hostname" ,
views => [ $intView ],
) ;

$result = $session->status_code();
$response = $session->status_detail();

print "($result) $response\n" ;

The script gets the following error:
<1001> General failure searching object type 'Infoblox::DNS::Record::Host' , please make sure this is a supported object type.

Anyone see what the problem with the code is ?

+1
0
-1
Tags
Infoblox Grid
Re: Infoblox API - Session "Search"

Hi Jose,

Per the engineering team (response below)

it's called DNS::Host, not DNS::Record::Host

+1
0
-1
Re: Infoblox API - Session "Search"

Besides my lack of Perl and API skills, I also lack READING skills. :)
Thanks for the help.

+1
0
-1
Re: Infoblox API - Session "Search"

Now that I've got the search routine to work, how do I get the IP address associated with the (found) host record ?

sub search4host {
my ($hostname) = @_;
my ($result, $response);

my $intView = Infoblox::DNS::View->new( name => 'Internal' );

my @searchhost = $session -> search (
object => "Infoblox::DNS::Host",
name => "$hostname",
views => [ $intView ],
);

+1
0
-1
Re: Infoblox API - Session "Search"
  1. sub search4host {
  2. my ($hostname) = @_;
  3. my ($result, $response);
  4. my $intView = Infoblox::DNS::View->new( name => 'Internal' );
  5. my ($searchhost) = $session -> search (
  6. object => "Infoblox::DNS::Host",
  7. name => "$hostname",
  8. views => [ $intView ],
  9. );
  10. my $ref_ipv4addrs = $searchhost->ipv4addrs();

$ref_ipv4addrs will now contain all the addresses or fixed address objects. You could use foreach to loop through, and confirm the type of object by using ref().

+1
0
-1
Re: Infoblox API - Session "Search"

Jerlev,
thanks for the help...I can't get it to work... The code below gets the error " undefined subroutine @main::ipv4addr caledd at......."

sub search4host {
my ($hostname) = @_;
my ($result, $response);

my $intView = Infoblox::DNS::View->new( name => 'Internal' );

my ($searchhost) = $session -> search (
object => "Infoblox::DNS::Host",
name => "$hostname",
views => [ $intView ],
);

$result = $session->status_code();
$response = $session->status_detail();

if ( $result == 0 ) {
print "Host record found\n" ;
my $hostip = $searchhost =>ipv4addr() ;
print "Host IP = $hostip" ;
}
else {
print "Host record not found\n";
}

Also, why did you change @searchhost to $searchhost ?

+1
0
-1
Re: Infoblox API - Session "Search"

Jerlev,
found the problem - had a typo in it.
I still would like to understand why you changed @searchhost to $searchhost . Also, can you please explain what you mean by "ref()" ?

+1
0
-1
Re: Infoblox API - Session "Search"

@searchhost is an array. $searchhost is a scalar. What he did was use a scalar variable to store a reference to the information. 

ref() is a function that lets you look at a variable and figure out what's in it. You can find an overview of ref here:

http://perldoc.perl.org/functions/ref.html

If you haven't used references in perl, they can be confusing to start, but they give you some ways of dealing with data that give ytou a lot of flexibility. They are worth studying if you're going to work in perl. 

 

+1
0
-1
Re: Infoblox API - Session "Search"

Chuq,
thanks for the help. I finally figured out how to get the IP address. The statement " my $hostip = $searchhost ->ipv4addrs() ; " returns a pointer to the array REFERENCE, not the array itself, which I had assumed.

sub search4host {
my ($hostname) = @_;
my ($result, $response, $returnvalue) ;

my $intView = Infoblox::DNS::View->new( name => 'Internal' );

my ($searchhost) = $session -> search (
object => "Infoblox::DNS::Host",
name => "$hostname",
views => [ $intView ],
);

$result = $session->status_code();
$response = $session->status_detail();

if ( $result == 0 ) {
print "Host record found\n" ;
my $hostip = $searchhost ->ipv4addrs() ;
foreach my $ip ( @ { $hostip } ) {
print "Host IP = $ip\n" ;
}
}
else {
print "Host record not found\n";
}

+1
+1
-1
Re: Infoblox API - Session "Search"

Hi IncaTiger, can you tell me how to upload these custom scripts onto the infoblox grid and make them executable and talk to infoblox databse?

+1
0
-1
Re: Infoblox API - Session "Search"

Amit,
The scripts do not get loaded into the Grid. In my case, the scripts are loaded on a Windows server which has the Infoblox API installed on it.
Check out the API Guide . It'll guide you thru the install process.

+1
+2
-1
Is there a way to get all the records

I'm looking to retrieve all of the IPAM::Address, DNS::Record::A and DNS:Record:AAAAA records from the IB database without regard to any other values. Once I get the records back, I plan to search for particular IP addresses and/or domain names.

Is there any easy way to do this? 

Jeff Burt

AT&T Government Solutions

+1
0
-1