BigIP-LTM-ParseConfig
view release on metacpan or search on metacpan
example/example.pl view on Meta::CPAN
use POSIX qw/strftime/;
use Getopt::Long;
use Spreadsheet::WriteExcel;
use File::Slurper qw/read_lines read_dir/;
my ( $opt_V, $opt_h, $opt_d, $opt_f );
sub usage () {
say encode(
'cp936',
decode_utf8(
"\nperl $0 -d directory(ç®å½) || -f f5_ltm_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();
# option handling initialization
if ($opt_V) {
say "F5 DevCenter BIGIP LTM configuration Parser V2.020";
exit(-1);
}
if ( $opt_h || not( $opt_d || $opt_f ) ) {
usage();
}
my $dirname = $opt_d;
sub write_excel {
my $ltm = shift;
my $time = strftime( "%Y%m%d", localtime() );
my $bip = BigIP::LTM::ParseConfig->new($ltm);
my $virtual_server = $bip->virtuals_all();
# Create a new Excel workbook
my $workbook
= Spreadsheet::WriteExcel->new(
"bigip-ltm-reports_$ltm" . "_$time" . '.xls' );
# Add a worksheet
my $worksheet = $workbook->add_worksheet( $ltm . '_Virtual_Server' );
# 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('center');
$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, 13, 28, $format_2 );
# Write a formatted and unformatted string, row and column notation.
my $excel_array = [
decode_utf8("VSåç§°"), decode_utf8("IPåè®®"),
decode_utf8("VSå°å->端å£"), decode_utf8("POOLåç§°"),
decode_utf8("POOLå°å->端å£"), decode_utf8("è´è½½æ¨¡å¼"),
decode_utf8("SNAT"), decode_utf8("SNAT->POOL"),
decode_utf8("å¥åº·æ£æ¥"), decode_utf8("é¿é¾æ¥"),
decode_utf8("é¿é¾æ¥-模å¼"), decode_utf8("IRULE"),
decode_utf8("PROFILES"), decode_utf8("å·¥åä¿¡æ¯"),
];
$worksheet->write_row( 0, 0, $excel_array, $format );
my ( $result, $vs_attr, $vs_info, $vs_member );
my $row = 0;
for my $vs ( keys %{$virtual_server} ) {
for my $attr ( keys %{ $virtual_server->{$vs} } ) {
$result->{$vs}{"virtual_server"} = $vs;
my $ret = $virtual_server->{$vs}{$attr};
if ( $attr =~ /\Apool\z/ ) {
$result->{$vs}{"pool"} = $ret;
}
elsif ( $attr =~ /destination/ ) {
$result->{$vs}{"destination"} = $ret =~ s/\:/\-\>/r;
}
elsif ( $attr =~ /persist_mode/ ) {
$result->{$vs}{"persist_mode"} = $ret;
}
elsif ( $attr =~ /ip-protocol/ ) {
$result->{$vs}{"ip-protocol"} = $ret;
}
elsif ( $attr =~ /\Apersist\z/ ) {
$result->{$vs}{"persist"}
= join( '', map {s@\/Common\/@@r} ( keys %{$ret} ) );
}
elsif ( $attr =~ /pool_details/ ) {
if ( exists $ret->{"load-balancing-mode"}
&& defined $ret->{"load-balancing-mode"} )
{
( run in 2.436 seconds using v1.01-cache-2.11-cpan-524268b4103 )