[pve-devel] [PATCH manager 2/2] Fix #1048: vzdump: include job-* hook logs in email

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Jul 7 08:34:48 CEST 2016


this is missing the HTML mail part and there is a newline before the
"post" part..

also, the layout is kinda wonky, but not sure how/whether to fix that:

  Jul 07 08:25:01 INFO: HOOK: job-start
  Jul 07 08:25:01 INFO: HOOK-ENV: dumpdir=/backups/dump;storeid=backups
  100: Jul 07 08:25:01 INFO: Starting Backup of VM 100 (lxc)
----snip----
  2000: Jul 07 08:27:10 INFO: HOOK-ENV: vmtype=qemu;dumpdir=/backups/dump;storeid=backups;hostname=sid;tarfile=/backups/dump/vzdump-qemu-2000-2016_07_07-08_25_02.vma;logfile=/backups/dump/vzdump-qemu-2000-2016_07_07-08_25_02.log
  2000: Jul 07 08:27:10 INFO: Finished Backup of VM 2000 (00:02:08)
  
  Jul 07 08:27:10 INFO: HOOK: job-end
  Jul 07 08:27:10 INFO: HOOK-ENV: dumpdir=/backups/dump;storeid=backups
  Jul 07 08:27:10 INFO: Backup job finished successfully

note: we also don't align the VM IDs which can be differently long

On Wed, Jul 06, 2016 at 01:52:33PM +0200, Wolfgang Bumiller wrote:
> ---
>  PVE/VZDump.pm | 27 +++++++++++++++++++--------
>  1 file changed, 19 insertions(+), 8 deletions(-)
> 
> diff --git a/PVE/VZDump.pm b/PVE/VZDump.pm
> index 45baca6..8216ce4 100644
> --- a/PVE/VZDump.pm
> +++ b/PVE/VZDump.pm
> @@ -363,7 +363,7 @@ sub read_vzdump_defaults {
>  }
>  
>  sub sendmail {
> -    my ($self, $tasklist, $totaltime, $err) = @_;
> +    my ($self, $tasklist, $totaltime, $err, $detail_pre, $detail_post) = @_;
>  
>      my $opts = $self->{opts};
>  
> @@ -426,6 +426,7 @@ sub sendmail {
>      $text .= "Detailed backup logs:\n\n";
>      $text .= "$cmdline\n\n";
>  
> +    $text .= $detail_pre if defined($detail_pre);
>      foreach my $task (@$tasklist) {
>  	my $vmid = $task->{vmid};
>  	my $log = $task->{tmplog};
> @@ -438,6 +439,7 @@ sub sendmail {
>  	close (TMP);
>  	$text .= "\n";
>      }
> +    $text .= $detail_post if defined($detail_post);
>  
>      # html part
>      my $html = "<html><body>\n";
> @@ -1110,36 +1112,45 @@ sub exec_backup {
>  	}
>      }
>  
> +    # Use in-memory files for the outer hook logs to pass them to sendmail.
> +    my $job_start_log = '';
> +    my $job_end_log = '';
> +    open my $job_start_fd, '>', \$job_start_log;
> +    open my $job_end_fd, '>', \$job_end_log;
> +
>      my $starttime = time();
>      my $errcount = 0;
>      eval {
>  
> -	$self->run_hook_script ('job-start');
> +	$self->run_hook_script ('job-start', undef, $job_start_fd);
>  
>  	foreach my $task (@$tasklist) {
>  	    $self->exec_backup_task ($task);
>  	    $errcount += 1 if $task->{state} ne 'ok';
>  	}
>  
> -	$self->run_hook_script ('job-end');    
> +	$self->run_hook_script ('job-end', undef, $job_end_fd);
>      };
>      my $err = $@;
>  
> -    $self->run_hook_script ('job-abort') if $err;    
> +    $self->run_hook_script ('job-abort', undef, $job_end_fd) if $err;
>  
>      if ($err) {
> -	debugmsg ('err', "Backup job failed - $err", undef, 1);
> +	debugmsg ('err', "Backup job failed - $err", $job_end_fd, 1);
>      } else {
>  	if ($errcount) {
> -	    debugmsg ('info', "Backup job finished with errors", undef, 1);
> +	    debugmsg ('info', "Backup job finished with errors", $job_end_fd, 1);
>  	} else {
> -	    debugmsg ('info', "Backup job finished successfully", undef, 1);
> +	    debugmsg ('info', "Backup job finished successfully", $job_end_fd, 1);
>  	}
>      }
>  
> +    close $job_start_fd;
> +    close $job_end_fd;
> +
>      my $totaltime = time() - $starttime;
>  
> -    eval { $self->sendmail ($tasklist, $totaltime); };
> +    eval { $self->sendmail ($tasklist, $totaltime, undef, $job_start_log, $job_end_log); };
>      debugmsg ('err', $@) if $@;
>  
>      die $err if $err;
> -- 
> 2.1.4
> 
> 
> _______________________________________________
> pve-devel mailing list
> pve-devel at pve.proxmox.com
> http://pve.proxmox.com/cgi-bin/mailman/listinfo/pve-devel
> 




More information about the pve-devel mailing list