Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
serf2excel makes a list of hosts file of the Excel format from 'serf members'.
#!/usr/bin/perl
use Encode;
use Spreadsheet::WriteExcel;
$serf = '/usr/bin/serf';
my ($sec, $min, $hour, $day, $month, $year, $wday) = localtime;
$year += 1900;
$month++;
$hour = sprintf("%.2d", $hour);
$min = sprintf("%.2d", $min);
$sec = sprintf("%.2d", $sec);
#print "$year, $month, $day\n";
my $excel = Spreadsheet::WriteExcel->new("./hostlist.xls");
#my $font = "MS Pゴシック";
my $font = decode("utf8","MS Pゴシック");
$excel->{_formats}->[15]->set_properties(font => $font,
size => 9,
align => 'vcenter');
#my $sheet = $excel->add_worksheet( 'ホスト一覧' );
my $sheet = $excel->add_worksheet( decode("utf8","ホスト一覧") );
$sheet->set_column('A:B', 30);
#$sheet->hide_gridlines(2);
my $bold = $excel->add_format();
$bold->set_bold();
$bold->set_underline();
my $border = $excel->add_format();
$border->set_border();
$sheet->write(0,0, decode("utf8", 'とあるクラスタのホスト情報一覧'), $bold );
$sheet->write(1,0, decode("utf8", '更新日時: '.$year.''.$month.''.$day.''.$hour.':'.$min.':'.$sec) );
$sheet->write(4,0, decode("utf8", 'Hostname'), $border );
$sheet->write(4,1, decode("utf8", 'IP Address') , $border);
my $row_position = 5;
open(CMD, "$serf members | ");
foreach my $line (<CMD>) {
# print "$row_position\n";
chomp $line;
if ($line =~ /^(\S+)(\s+)(\S+)(\:)(\d+)/) {
$sheet->write($row_position,0, $1 , $border);
$sheet->write($row_position,1, $3 , $border);
}
$row_position++;
}
close (CMD);
exit;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.