Created
April 18, 2014 05:08
-
-
Save zembutsu/10caa6b868fc994ec683 to your computer and use it in GitHub Desktop.
serf2excel makes a list of hosts file of the Excel format from 'serf members'.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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