BigIP-GTM-ParseConfig

 view release on metacpan or  search on metacpan

example/example.pl  view on Meta::CPAN

    say encode(
        'cp936',
        decode_utf8(
            "\nperl $0 -d directory(目录) || -f f5_GTM_config(单个配置文件)\n"
        )
    );
    say encode(
        'cp936',
        decode_utf8(
            '使用过程如有任何疑问,请联系careline@126.com')
    );
    exit();
}

#  use Getopt::Long qw(:config no_ignore_case bundling);
Getopt::Long::Configure( "bundling", "no_ignore_case" );
GetOptions(
    'V'   => \$opt_V,
    'h'   => \$opt_h,
    'f=s' => \$opt_f,
    'd=s' => \$opt_d,
) || die usage();

my %dc = (
    "DC_ChaoSuan"  => "超算机房",
    "DC_813"       => "朝阳门机房",
    "DC_PengBoShi" => "鹏博士机房",
    "DC_650"       => "汇天机房",
    "DC_HeFei"     => "合肥机房"
);

# option handling initialization
if ($opt_V) {
    say "F5 DevCenter BIGIP GTM configuration Parser V2.020";
    exit(-1);
}

if ( $opt_h || not( $opt_d || $opt_f ) ) {
    usage();
}

my $dirname = $opt_d;

sub write_excel {
    my $GTM  = shift;
    my $time = strftime( "%Y%m%d", localtime() );

    my $bip     = BigIP::GTM::ParseConfig->new($GTM);
    my $dns_all = $bip->wideips_all();

    # Create a new Excel workbook
    my $workbook
        = Spreadsheet::WriteExcel->new(
        "bigip-GTM-reports_$GTM" . "_$time" . '.xls' );

    # Add a worksheet
    my $worksheet = $workbook->add_worksheet( $GTM . '_DNS_details' );

    # Add and define a format
    my $format = $workbook->add_format();    # Add a format
    $format->set_bold();
    $format->set_color('blue');
    $format->set_bg_color('red');
    $format->set_size(18);
    $format->set_border(1);
    $format->set_align('center');
    $format->set_valign('vcenter');

    my $format_1 = $workbook->add_format();
    $format_1->set_size(12);
    $format_1->set_border(1);
    $format_1->set_align('left');
    $format_1->set_valign('vcenter');

    my $format_2 = $workbook->add_format();
    $format_1->set_size(12);
    $format_2->set_align('center');
    $format_2->set_valign('vcenter');

    # set column and row width;
    $worksheet->set_column( 0, 6, 45, $format_2 );

    # Write a formatted and unformatted string, row and column notation.
    my $excel_array = [
        decode_utf8("DNS条目"),
        decode_utf8("负载模式"),
        decode_utf8("POOL-优先级"),
        decode_utf8("VS映射关系"),
        decode_utf8("DNS解析明细"),
        decode_utf8("健康检查-服务类型"),
        decode_utf8("工单信息"),
    ];
    $worksheet->write_row( 0, 0, $excel_array, $format );

    my ( $result, $dns_attr );
    my $row = 0;
    foreach my $dns ( keys %{$dns_all} ) {
        foreach my $attr ( keys %{ $dns_all->{$dns} } ) {
            $result->{$dns}{"wide_ip"} = $dns;
            my $ret = $dns_all->{$dns}{$attr};

            $result->{$dns}{"report"}     ||= [];
            $result->{$dns}{"server"}     ||= [];
            $result->{$dns}{"monitor"}    ||= [];
            $result->{$dns}{"pool_order"} ||= [];

            if ( $attr =~ /\Apool-lb-mode\z/ ) {
                $result->{$dns}{"mode"} = $ret;
            }
            elsif ( $attr =~ /\Apools\z/ ) {
                my $pool;
                foreach ( keys %{$ret} ) {
                    my $rev = $ret->{$_};
                    $pool = $_;

                    my $order;
                    foreach ( keys %{$rev} ) {
                        $order .= join( " ", $_, '->', $rev->{$_}, ' ' )
                            if exists $rev->{$_};
                    }
                    my $pool_order = $pool . " \( $order \) ";



( run in 0.484 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )