Reply

Searching via Options with Regular Expressions via the API

FYao
Techie
Posts: 4
4185     0

Hi,

I've started playing around with the API (6.12) to simplify some of searches I need to do related to FixedAddr.  Based on the documentation, I was able to easily write a script (once I got perl setup properly with Crypt-SSLeay) to grab all the FixedAddr entries that had a specific string in the comment.  When I went to do a search for a customized option (option 242) that started with a specific string, I was completely lost.  So, I decided to go for something easier, to just grab all the FixedAddr records and then do the seach in perl instead.  However, I'm stuck as to what type of data structure options is.  If I set it as a hash, when I do keys on it, it prints out ARRAY.  If I then add [0], it prints out nothing.

Does anyone have sample code that can be used to search FixedAddr with a customized option, or at least how to extract the options so that I can do it search in perl?

TIA,

- frank

Data::Dumper

Authority
Posts: 37
4186     0

When I'm playing around I'm always using print Dumper($result); to output the variable in its entirity and find out what type it is an contains.

Result from print Dumper($object)

FYao
Techie
Posts: 4
4186     0

Here's the output from Dumper:

$VAR1 = [
  bless( {
    'num' => '242',
    'value' => 'L2QVLAN=466',
    'name' => 'option242',
    'vendor_class' => 'DHCP'
  }, 'Infoblox:Smiley Very HappyHCP:Smiley Surprisedption' )
];

However, when I try to use any of the methods that you can use with Infoblox:Smiley Very HappyHCP:Smiley Surprisedption, say like this:

my $options = $object->options();
# print Dumper($options), "\n";
my $optval = $options->value();
print "$optval\n";

... I get the following error message, "Can't call method "value" on unblessed reference at wintest.pl line 26."

Back to Googling "perl bless".

getting closer

Authority
Posts: 37
4186     0

What happens when you try it like this?

my $optval = $options[0]->value();

 

This is what I did when we

Authority
Posts: 37
4186     0

This is what I did when we needed to change option 150 on Infoblox:Smiley Very HappyHCP::Network objects where a specific value needed to be changed :


foreach(@results)
{
  my found = 0;
  my $options = $_->options();
  foreach(@$options)
  {
    if(($_->num() == 150) && ($_->value() =~ m/192\.168\.4\.5/))
    {
      $found = 1;
      my $newvalue = '159.114.125.62,159.114.127.177';
      $_->value($newvalue);
    }
          
    if($found)
    {
      $_->options($options);
      my $response = $session->modify($_);
      print $response . "\t" . $_->network() . "\t";
    }
  }
}

Finally got it

FYao
Techie
Posts: 4
4186     0

So, once I realized that the option() method returned a reference to an array, I was able to do:

    my $options = $object->options();
    my @options = @{$options};

.. which is the amateurish way of that code segment you have.

thanks!

Showing results for 
Search instead for 
Do you mean 

Recommended for You