I am trying to search through a Load Balancer config and extract some data. The configuration file looks like this
pool {
name "POOL_name1"
ttl 30
monitor all "tcp"
preferred rr
partition "Common"
member 12.24.5.100:80
}
pool {
name "Pool-name2"
ttl 30
monitor all "https_ignore_dwn"
preferred rr
fallback rr
partition "Common"
member 69.241.25.121:8443
member 69.241.25.122:8443
}
I am trying to assign each pool config to it’s own array, so I can loop through the array to find specific IP addresses and pool names. I tried the following regex, but its not working.
my @POOLDATA = <FILE>;
close FILE;
foreach (@POOLDATA) {
if (/^pool\s\{\s/ .. /^\}\s/) {
push (@POOLCONFIG, "$_");
}
}
Does anyone have a suggestion on how to separate each pool config into its own array? (or a better suggestion) Thank you in advance for your help
Output:
$VAR1 = [ { 'monitor all' => [ 'tcp' ], 'member' => [ '12.24.5.100:80' ], 'ttl' => [ '30' ], 'name' => [ 'POOL_name1' ], 'preferred' => [ 'rr' ], 'partition' => [ 'Common' ] }, { 'monitor all' => [ 'https_ignore_dwn' ], 'member' => [ '69.241.25.121:8443', '69.241.25.122:8443' ], 'ttl' => [ '30' ], 'name' => [ 'Pool-name2' ], 'preferred' => [ 'rr' ], 'partition' => [ 'Common' ] } ];Edit:
Of course, you can check for a member element, and fill in a default one if it isn’t found. In fact, with the basic structure in place, you should have been able to do that yourself.
One way to do it is to check for the end of a pool record: