Skip to content

Instantly share code, notes, and snippets.

@frobware
Created April 11, 2024 14:01
Show Gist options
  • Save frobware/bff4a0e6f560dcfc68be7e494a26b207 to your computer and use it in GitHub Desktop.
Save frobware/bff4a0e6f560dcfc68be7e494a26b207 to your computer and use it in GitHub Desktop.
OCPBUGS-29690: Match weight == 0
#!/usr/bin/env perl
use strict;
use warnings;
# Store the current backend block.
my $backend_block = '';
# Flag to start capturing lines into the backend block.
my $capture_block = 0;
# Flag to check if the backend block contains a server with weight 0.
my $has_zero_weight = 0;
while (my $line = <>) {
if ($line =~ /^backend/) {
# If starting a new backend block, check if the previous one
# had a zero weight server and, if so, print the captured
# backend block.
if ($capture_block && $has_zero_weight) {
print $backend_block;
}
$backend_block = $line;
$capture_block = 1;
$has_zero_weight = 0;
} elsif ($capture_block) {
$backend_block .= $line;
if ($line =~ /weight 0/) {
$has_zero_weight = 1;
}
}
}
if ($capture_block && $has_zero_weight) {
print $backend_block;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment