Skip to content

Commit

Permalink
fix(xo-server-backup-reports): support failed targets (#5694)
Browse files Browse the repository at this point in the history
Introduced by d282d8d
  • Loading branch information
badrAZ committed Mar 26, 2021
1 parent 7d04559 commit 22ba130
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 10 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.unreleased.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
>
> In case of conflict, the highest (lowest in previous list) `$version` wins.
- xo-server-backup-reports patch
- @vates/disposable patch
- xo-server-transport-email minor
- @xen-orchestra/fs minor
Expand Down
56 changes: 46 additions & 10 deletions packages/xo-server-backup-reports/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -375,7 +375,7 @@ class BackupReportsXoPlugin {
})
}

const failedVmsText = []
const failedTasksText = []
const skippedVmsText = []
const successfulVmsText = []
const interruptedVmsText = []
Expand All @@ -391,17 +391,53 @@ class BackupReportsXoPlugin {
continue
}

const vmId = taskLog.data.id
const { type, id } = taskLog.data ?? {}
if (taskLog.message === 'get SR record' || taskLog.message === 'get remote adapter') {
++nFailures
failedTasksText.push(
// It will ensure that it will never be in a nested list
''
)

try {
if (type === 'SR') {
const { name_label: name, uuid } = xo.getObject(id)
failedTasksText.push(`### ${name}`, '', `- **UUID**: ${uuid}`)
nagiosText.push(`[(${type} failed) ${name} : ${taskLog.result.message} ]`)
} else {
const { name } = await xo.getRemote(id)
failedTasksText.push(`### ${name}`, '', `- **UUID**: ${id}`)
nagiosText.push(`[(${type} failed) ${name} : ${taskLog.result.message} ]`)
}
} catch (error) {
logger.warn(error)
failedTasksText.push(`### ${UNKNOWN_ITEM}`, '', `- **UUID**: ${id}`)
nagiosText.push(`[(${type} failed) ${id} : ${taskLog.result.message} ]`)
}

failedTasksText.push(
`- **Type**: ${type}`,
...getTemporalDataMarkdown(taskLog.end, taskLog.start, formatDate),
...getWarningsMarkdown(taskLog.warnings),
`- **Error**: ${taskLog.result.message}`
)
continue
}

if (type !== 'VM') {
continue
}

let vm
try {
vm = xo.getObject(vmId)
vm = xo.getObject(id)
} catch (e) {}
const text = [
// It will ensure that it will never be in a nested list
'',
`### ${vm !== undefined ? vm.name_label : 'VM not found'}`,
'',
`- **UUID**: ${vm !== undefined ? vm.uuid : vmId}`,
`- **UUID**: ${vm !== undefined ? vm.uuid : id}`,
...getTemporalDataMarkdown(taskLog.end, taskLog.start, formatDate),
...getWarningsMarkdown(taskLog.warnings),
]
Expand Down Expand Up @@ -512,14 +548,14 @@ class BackupReportsXoPlugin {
nagiosText.push(`[(Skipped) ${vm !== undefined ? vm.name_label : 'undefined'} : ${taskLog.result.message} ]`)
} else {
++nFailures
failedVmsText.push(...text, `- **Error**: ${taskLog.result.message}`)
failedTasksText.push(...text, `- **Error**: ${taskLog.result.message}`)

nagiosText.push(`[(Failed) ${vm !== undefined ? vm.name_label : 'undefined'} : ${taskLog.result.message} ]`)
}
} else {
if (taskLog.status === 'failure') {
++nFailures
failedVmsText.push(...text, ...subText)
failedTasksText.push(...text, ...subText)
nagiosText.push(`[${vm !== undefined ? vm.name_label : 'undefined'}: (failed)[${failedSubTasks.toString()}]]`)
} else if (taskLog.status === 'interrupted') {
++nInterrupted
Expand All @@ -531,24 +567,24 @@ class BackupReportsXoPlugin {
}
}

const nVms = log.tasks.length
const nSuccesses = nVms - nFailures - nSkipped - nInterrupted
const nTasks = log.tasks.length
const nSuccesses = nTasks - nFailures - nSkipped - nInterrupted
const markdown = [
`## Global status: ${log.status}`,
'',
`- **Job ID**: ${log.jobId}`,
`- **Run ID**: ${log.id}`,
`- **mode**: ${mode}`,
...getTemporalDataMarkdown(log.end, log.start, formatDate),
`- **Successes**: ${nSuccesses} / ${nVms}`,
`- **Successes**: ${nSuccesses} / ${nTasks}`,
globalTransferSize !== 0 && `- **Transfer size**: ${formatSize(globalTransferSize)}`,
globalMergeSize !== 0 && `- **Merge size**: ${formatSize(globalMergeSize)}`,
...getWarningsMarkdown(log.warnings),
'',
]

if (nFailures !== 0) {
markdown.push('---', '', `## ${nFailures} Failure${nFailures === 1 ? '' : 's'}`, '', ...failedVmsText)
markdown.push('---', '', `## ${nFailures} Failure${nFailures === 1 ? '' : 's'}`, '', ...failedTasksText)
}

if (nSkipped !== 0) {
Expand Down

0 comments on commit 22ba130

Please sign in to comment.