Reply
Highlighted

Infoblox API - Session "Search"

JCampos
Techie
Posts: 8
6109     0

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:Smiley Very HappyNS::View->new( name => 'Internal' ); my $searchHost = $session -> search ( object => "Infoblox:Smiley Very HappyNS::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:Smiley Very HappyNS::Record::Host' , please make sure this is a supported object type.Anyone see what the problem with the code is ?

Re: Infoblox API - Session

community Employee
Employee
Posts: 73
6110     0

Hi Jose,

Per the engineering team (response below)

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

Re: Infoblox API - Session

JCampos
Techie
Posts: 8
6110     0
Besides my lack of Perl and API skills, I also lack READING skills. Smiley Happy Thanks for the help.

Re: Infoblox API - Session

JCampos
Techie
Posts: 8
6110     0
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:Smiley Very HappyNS::View->new( name => 'Internal' ); my @searchhost = $session -> search ( object => "Infoblox:Smiley Very HappyNS::Host", name => "$hostname", views => [ $intView ], );

Re: Infoblox API - Session

JLeveillee
Techie
Posts: 13
6110     0
sub search4host {my ($hostname) = @_;my ($result, $response);my $intView = Infoblox:Smiley Very HappyNS::View->new( name => 'Internal' );my ($searchhost) = $session -> search (object => "Infoblox:Smiley Very HappyNS::Host",name => "$hostname",views => [ $intView ],);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().

Re: Infoblox API - Session

JCampos
Techie
Posts: 8
6110     0
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:Smiley Very HappyNS::View->new( name => 'Internal' ); my ($searchhost) = $session -> search ( object => "Infoblox:Smiley Very HappyNS::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 ?

Re: Infoblox API - Session

JCampos
Techie
Posts: 8
6110     0
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()" ?

Re: Infoblox API - Session

I-Team Employee
Employee
Posts: 186
6110     0

@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. 

 

Re: Infoblox API - Session

JCampos
Techie
Posts: 8
6110     0
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:Smiley Very HappyNS::View->new( name => 'Internal' ); my ($searchhost) = $session -> search ( object => "Infoblox:Smiley Very HappyNS::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"; }

Re: Infoblox API - Session

user42
Techie
Posts: 35
6110     0
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?

Re: Infoblox API - Session

JCampos
Techie
Posts: 8
6110     0
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.

Is there a way to get all the

JBurt
Techie
Posts: 6
6110     0

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

Re: Infoblox API - Session

HWin
Techie
Posts: 3
6110     0

Hi

I tried similar concept but always return as no reord found though the record is exist.

Showing results for 
Search instead for 
Do you mean 

Recommended for You