Skip to content

Commit fcdfbbd

Browse files
authored
Merge pull request #626 from ClusterLabs/striker-data-collection-fixes
Striker data collection fixes
2 parents 8e5fe42 + f1584c7 commit fcdfbbd

File tree

2 files changed

+67
-33
lines changed

2 files changed

+67
-33
lines changed

man/striker-collect-debug.8

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ This restricts the data to be collected to the Striker dashboards and the specif
3535
.TP
3636
This can be used to specify which specific hosts data is collected from. Note that this can be used in conjuction with \fB\-\-anvil\fR to add additional hosts to collect data from, like DR hosts.
3737
.TP
38+
\fB\-\-with\-screenshots\fR
39+
.TP
40+
This collects VMs screenshots together with debug log. Disabled by default.
41+
.TP
3842
\fB\-\-output\-file\fR </path/to/file.tar.bz2>
3943
.TP
4044
This allows you to specify the output compressed tarball that the files will be saved in. By default, the output file is \fB/root/anvil-debug_<timestamp>.tar.bz2\fR. If this is a directory (ending in \fB/\fR), the normal file name is created, just in a different directory. If the path ends in a file that doesn't have the \fB.tar.bz2\fR suffix, that suffix will be added automatically. The output file will always be a bzip2's tarball.

tools/striker-collect-debug

Lines changed: 63 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ my $anvil = Anvil::Tools->new();
3636
$anvil->Get->switches({list => [
3737
"anvil",
3838
"hosts",
39+
"with-screenshots",
3940
"output-file"], man => $THIS_FILE});
4041
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => $anvil->data->{switches}});
4142
$anvil->Log->entry({source => $THIS_FILE, line => __LINE__, level => 2, key => "log_0115", variables => { program => $THIS_FILE }});
@@ -77,8 +78,7 @@ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list
7778
"sys::compile_directory" => $anvil->data->{sys}{compile_directory},
7879
}});
7980

80-
print "Data collection has begun.\n";
81-
print "Depending on how many systems we're collecting from, this could take a while.\n";
81+
print "Data collection has begun. This will take a while!\n\n";
8282

8383
# Get the directory portion of the output path and make sure it exists.
8484
my $tarball = process_output($anvil);
@@ -89,7 +89,8 @@ process_switches($anvil);
8989
collect_data($anvil);
9090

9191
# Create the tarball now.
92-
print "Data collection complete, creating the tarball now... ";
92+
print "\nData collection complete\n";
93+
print "- Creating the tarball now. PLEASE BE PATIENT!... ";
9394
my $shell_call = $anvil->data->{path}{exe}{tar}." -cvjf ".$tarball." ".$anvil->data->{sys}{compile_directory};
9495
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
9596
's1:tarball' => $tarball,
@@ -103,10 +104,22 @@ $anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list
103104
}});
104105
print "Done!\n";
105106

106-
print "\n[ Complete ] - The debug data is here: [".$tarball."]\n";
107-
print "[ Warning ] - The collected logs likely include sensitive information! Share it carefully!\n";
107+
print "- Removing temporary data dir [".$anvil->data->{sys}{compile_directory}."]... ";
108+
$shell_call = "rm -rf ".$anvil->data->{sys}{compile_directory};
109+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
110+
's1:tempdir' => $anvil->data->{sys}{compile_directory},
111+
's2:shell_call' => $shell_call,
112+
}});
108113

114+
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
115+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
116+
output => $output,
117+
return_code => $return_code,
118+
}});
119+
print "Done!\n";
109120

121+
print "\n[ Complete ] - The debug data collected here: [".$tarball."]\n";
122+
print "[ Warning ] - The collected data and logs likely include sensitive information! Share it carefully!\n";
110123

111124
$anvil->nice_exit({exit_code => 0});
112125

@@ -158,14 +171,22 @@ sub process_output
158171

159172
if ($output_directory ne "/")
160173
{
161-
print "- Creating the output directory: [".$output_directory."]... ";
162-
my $failed = $anvil->Storage->make_directory({directory => $output_directory});
163-
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { failed => $failed }});
164-
if ($failed)
174+
print "Preparing local machine\n";
175+
if (! -d $output_directory) {
176+
print "- Creating the output directory: [".$output_directory."]... ";
177+
my $failed = $anvil->Storage->make_directory({directory => $output_directory});
178+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { failed => $failed }});
179+
if ($failed)
180+
{
181+
print "Failed!\nUnable to create the directory: [".$anvil->data->{sys}{compile_directory}."]. The error should be logged.\n";
182+
$anvil->nice_exit({exit_code => 1});
183+
}
184+
print "Done!\n";
185+
}
186+
else
165187
{
166-
print "Failed!\nUnable to create the directory: [".$anvil->data->{sys}{compile_directory}."]. The error should be logged.\n";
167-
$anvil->nice_exit({exit_code => 1});
168-
}
188+
print "- Output directory [".$output_directory."] already exists.\n";
189+
}
169190
}
170191

171192
$tarball = $output_directory."/".$output_file;
@@ -178,13 +199,15 @@ sub collect_data
178199
{
179200
my ($anvil) = @_;
180201

202+
print "- Creating temporary data dir [".$anvil->data->{sys}{compile_directory}."]... ";
181203
my $failed = $anvil->Storage->make_directory({directory => $anvil->data->{sys}{compile_directory}});
182204
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { failed => $failed }});
183205
if ($failed)
184206
{
185207
print "Failed to create the directory: [".$anvil->data->{sys}{compile_directory}."]. The error should be logged.\n";
186208
$anvil->nice_exit({exit_code => 1});
187209
}
210+
print "Done!\n";
188211

189212
my $hosts = @{$anvil->data->{collect_from}};
190213
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { hosts => $hosts }});
@@ -675,33 +698,40 @@ sub collect_local_data
675698
}
676699
print "Done!\n";
677700

678-
# Grab screenshots.
679-
print "- Collecting server screenshots... ";
680-
if (-d $anvil->data->{path}{directories}{screenshots})
701+
if ($anvil->data->{switches}{'with-screenshots'})
681702
{
682-
$shell_call = $anvil->data->{path}{exe}{tar}." -cvjf ".$target_directory."/server-screenshots.bz2 ".$anvil->data->{path}{directories}{screenshots};
683-
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
684-
685-
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
686-
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
687-
output => $output,
688-
return_code => $return_code,
689-
}});
690-
if ($return_code)
703+
# Grab screenshots.
704+
print "- Collecting server screenshots... ";
705+
if (-d $anvil->data->{path}{directories}{screenshots})
691706
{
692-
# Failed
693-
print "Failed!\n";
694-
print "Expected the return code '0', but got: [".$return_code."]. The error, if any, was:\n";
695-
print "========\n";
696-
print $output."\n";
697-
print "========\n";
698-
$anvil->nice_exit({exit_code => 1});
707+
$shell_call = $anvil->data->{path}{exe}{tar}." -cvjf ".$target_directory."/server-screenshots.bz2 ".$anvil->data->{path}{directories}{screenshots};
708+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => { shell_call => $shell_call }});
709+
710+
($output, $return_code) = $anvil->System->call({shell_call => $shell_call});
711+
$anvil->Log->variables({source => $THIS_FILE, line => __LINE__, level => 2, list => {
712+
output => $output,
713+
return_code => $return_code,
714+
}});
715+
if ($return_code)
716+
{
717+
# Failed
718+
print "Failed!\n";
719+
print "Expected the return code '0', but got: [".$return_code."]. The error, if any, was:\n";
720+
print "========\n";
721+
print $output."\n";
722+
print "========\n";
723+
$anvil->nice_exit({exit_code => 1});
724+
}
725+
print "Done!\n";
726+
}
727+
else
728+
{
729+
print "Failed!\nScreenshot directory: [".$anvil->data->{path}{directories}{screenshots}."] doesn't exist, skipping.\n";
699730
}
700-
print "Done!\n";
701731
}
702732
else
703733
{
704-
print "Failed!\nScreenshot directory: [".$anvil->data->{path}{directories}{screenshots}."] doesn't exist, skipping.\n";
734+
print "- Screehshots collection disabled.\n";
705735
}
706736
}
707737

0 commit comments

Comments
 (0)