Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for tape jobs #81

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 9 additions & 7 deletions AlertSender.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ try {
}

# If agent backup, gather and include session info.
If ($jobType -eq 'EpAgentBackup') {
If ($jobType -in 'EpAgentBackup','BackupToTape','FileToTape') {
# Gather session data sizes and timings.
[Float]$processedSize = $session.Info.Progress.ProcessedSize
[Float]$transferSize = $session.Info.Progress.TransferedSize
Expand Down Expand Up @@ -250,6 +250,8 @@ try {
'EEndPoint' { $jobTypeNice = 'Windows Agent Backup' }
}
}
FileToTape { $jobTypeNice = 'File Tape Backup' }
BackupToTape { $jobTypeNice = 'Repo Tape Backup' }
}

# Decide whether to mention user
Expand Down Expand Up @@ -293,15 +295,13 @@ try {


# Build embed parameters
If ($jobType -ne 'EpAgentBackup') {
If ($jobType -in 'EpAgentBackup','BackupToTape','FileToTape') {
$payloadParams = @{
JobName = $jobName
JobType = $jobTypeNice
Status = $status
DataSize = $dataSizeRound
ProcessedSize = $processedSizeRound
TransferSize = $transferSizeRound
DedupRatio = $dedupRatio
CompressRatio = $compressRatio
Speed = $speedRound
Bottleneck = $bottleneck
Duration = $durationFormatted
Expand All @@ -313,13 +313,15 @@ try {
}
}

elseif ($jobType -eq 'EpAgentBackup') {
else {
$payloadParams = @{
JobName = $jobName
JobType = $jobTypeNice
Status = $status
ProcessedSize = $processedSizeRound
DataSize = $dataSizeRound
TransferSize = $transferSizeRound
DedupRatio = $dedupRatio
CompressRatio = $compressRatio
Speed = $speedRound
Bottleneck = $bottleneck
Duration = $durationFormatted
Expand Down
17 changes: 13 additions & 4 deletions Bootstrap.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ $configFile = "$PSScriptRoot\config\conf.json"
$date = (Get-Date -UFormat %Y-%m-%d_%T).Replace(':','.')
$logFile = "$PSScriptRoot\log\$($date)_Bootstrap.log"
$idRegex = '[0-9a-f]{8}-([0-9a-f]{4}-){3}[0-9a-f]{12}'
$supportedTypes = 'Backup', 'EpAgentBackup','Replica'
$supportedTypes = 'Backup', 'EpAgentBackup','Replica','BackupToTape','FileToTape'

# Start logging to file
Start-Logging -Path $logFile
Expand Down Expand Up @@ -56,17 +56,26 @@ $sessionId = ([regex]::Matches($parentCmd, $idRegex)).Value[1]
# At time of writing, there is no alternative way to discover the job time.
Write-LogMessage -Tag 'INFO' -Message 'Getting VBR job details'
$job = Get-VBRJob -WarningAction SilentlyContinue | Where-Object {$_.Id.Guid -eq $jobId}
if (!$job) {
# Can't locate non tape job so check if it's a tape job
$job = Get-VBRTapejob -WarningAction SilentlyContinue | Where-Object {$_.Id.Guid -eq $jobId}
$JobType = $job.Type
}
else {
$JobType = $job.JobType
}


# Get the session information and name.
Write-LogMessage -Tag 'INFO' -Message 'Getting VBR session information'
$sessionInfo = Get-VBRSessionInfo -SessionId $sessionId -JobType $job.JobType
$sessionInfo = Get-VBRSessionInfo -SessionId $sessionId -JobType $JobType
$jobName = $sessionInfo.JobName
$vbrSessionLogger = $sessionInfo.Session.Logger

$vbrLogEntry = $vbrSessionLogger.AddLog('[VeeamNotify] Parsing job & session information...')

# Quit if job type is not supported.
If ($job.JobType -notin $supportedTypes) {
If ($JobType -notin $supportedTypes) {
Write-LogMessage -Tag 'ERROR' -Message "Job type '$($job.JobType)' is not supported."
Exit 1
}
Expand All @@ -84,7 +93,7 @@ Else {
$newLogfile = "$PSScriptRoot\log\$($date)-$($logJobName).log"

# Build argument string for the alert sender script.
$powershellArguments = "-file $PSScriptRoot\AlertSender.ps1", "-JobName `"$jobName`"", "-Id `"$sessionId`"","-JobType `"$($job.JobType)`"", `
$powershellArguments = "-file $PSScriptRoot\AlertSender.ps1", "-JobName `"$jobName`"", "-Id `"$sessionId`"","-JobType `"$($JobType)`"", `
"-Config `"$($configRaw)`"", "-Logfile `"$newLogfile`""

$vbrSessionLogger.UpdateSuccess($vbrLogEntry, '[VeeamNotify] Parsed job & session information.') | Out-Null
Expand Down
76 changes: 59 additions & 17 deletions resources/NotificationHandler.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,64 @@ function New-DiscordPayload {
}

# Build field object.
if (-not ($JobType.EndsWith('Agent Backup'))) {


if ($JobType.EndsWith('Agent Backup')) {
$fieldArray = @(
[PSCustomObject]@{
name = 'Backup Size'
value = $DataSize
inline = 'true'
},
name = 'Processed Size'
value = $ProcessedSize
inline = 'true'
}
[PSCustomObject]@{
name = 'Transferred Data'
value = $TransferSize
inline = 'true'
}
[PSCustomObject]@{
name = 'Processing Rate'
value = $Speed
inline = 'true'
}
[PSCustomObject]@{
name = 'Bottleneck'
value = $Bottleneck
inline = 'true'
}
[PSCustomObject]@{
name = 'Dedup Ratio'
value = $DedupRatio
name = 'Start Time'
value = $timestampStart
inline = 'true'
}
[PSCustomObject]@{
name = 'Compression Ratio'
value = $CompressRatio
name = 'End Time'
value = $timestampEnd
inline = 'true'
}
[PSCustomObject]@{
name = 'Duration'
value = $Duration
inline = 'true'
}
)
}
# TODO look furhter into what detail can be pulled out that is tape specefic, eg tapes used etc
elseif ($JobType.EndsWith('Tape Backup')) {
$fieldArray = @(
[PSCustomObject]@{
name = 'Processed Size'
value = $ProcessedSize
inline = 'true'
}
[PSCustomObject]@{
name = 'Transferred Data'
value = $TransferSize
inline = 'true'
}
[PSCustomObject]@{
name = 'Processing Rate'
value = $Speed
inline = 'true'
inline = 'true'
}
[PSCustomObject]@{
name = 'Bottleneck'
Expand All @@ -129,22 +161,32 @@ function New-DiscordPayload {
)
}

elseif ($JobType.EndsWith('Agent Backup')) {
else {
$fieldArray = @(
[PSCustomObject]@{
name = 'Processed Size'
value = $ProcessedSize
inline = 'true'
}
name = 'Backup Size'
value = $DataSize
inline = 'true'
},
[PSCustomObject]@{
name = 'Transferred Data'
value = $TransferSize
inline = 'true'
inline = 'true'
}
[PSCustomObject]@{
name = 'Dedup Ratio'
value = $DedupRatio
inline = 'true'
}
[PSCustomObject]@{
name = 'Compression Ratio'
value = $CompressRatio
inline = 'true'
}
[PSCustomObject]@{
name = 'Processing Rate'
value = $Speed
inline = 'true'
inline = 'true'
}
[PSCustomObject]@{
name = 'Bottleneck'
Expand Down
9 changes: 7 additions & 2 deletions resources/VBRSessionInfo.psm1
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Function Get-VBRSessionInfo {
}

# Agent job
{$_ -eq 'EpAgentBackup'} {
{$_ -in 'EpAgentBackup','BackupToTape','FileToTape'} {
# Fetch current session to load .NET module
# It appears some of the underlying .NET items are lazy-loaded, so this is necessary
# to load in whatever's required to utilise the GetByOriginalSessionId method.
Expand All @@ -33,7 +33,12 @@ Function Get-VBRSessionInfo {
$session = [Veeam.Backup.Core.CBackupSession]::GetByOriginalSessionId($SessionId)

# Copy the job's name to it's own variable.
$jobName = $job.Info.Name
if ($JobType -eq 'EpAgentBackup') {
$jobName = $job.Info.Name
}
elseif ($JobType -in 'BackupToTape','FileToTape') {
$jobName = $job.Name
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion resources/version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v1.0.1
v1.0.2