@@ -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.
8484my $tarball = process_output($anvil );
@@ -89,7 +89,8 @@ process_switches($anvil);
8989collect_data($anvil );
9090
9191# Create the tarball now.
92- print " Data collection complete, creating the tarball now... " ;
92+ print " \n Data collection complete\n " ;
93+ print " - Creating the tarball now. PLEASE BE PATIENT!... " ;
9394my $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}});
104105print " 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!\n Unable 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!\n Unable 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!\n Screenshot directory: [" .$anvil -> data-> {path }{directories }{screenshots }." ] doesn't exist, skipping.\n " ;
699730 }
700- print " Done!\n " ;
701731 }
702732 else
703733 {
704- print " Failed! \n Screenshot directory: [ " . $anvil -> data -> { path }{ directories }{ screenshots }. " ] doesn't exist, skipping .\n " ;
734+ print " - Screehshots collection disabled .\n " ;
705735 }
706736 }
707737
0 commit comments