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

feat(xo-web/backup): add 'report recipients' when creating a metadata backup #7776

Merged
merged 2 commits into from
Jul 25, 2024
Merged
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
5 changes: 4 additions & 1 deletion CHANGELOG.unreleased.md
MathieuRA marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@

> Users must be able to say: “Nice enhancement, I'm eager to test it”

- [Backups] Add 'report recipients' when creating a metadata backup [#7569](https://github.com/vatesfr/xen-orchestra/issues/7569) (PR [#7776](https://github.com/vatesfr/xen-orchestra/pull/7776))

### Bug fixes

> Users must be able to say: “I had this issue, happy to know it's fixed”
Expand All @@ -22,6 +24,7 @@
- [Backups] NBD backups now ignore unreachable host and retry on reachable ones (PR [#7836](https://github.com/vatesfr/xen-orchestra/pull/7836))
- [New SR] Add confirmation modal before creating an SR if SRs are already present in the same path (for NFS/ISCSI) [#4273](https://github.com/vatesfr/xen-orchestra/issues/4273) (PR [#7845](https://github.com/vatesfr/xen-orchestra/pull/7845))
- [XO Tasks] Reduce the number of API calls that incorrectly stay in pending status (often `sr.getAllUnhealthyVdiChainsLength`) [Forum#79281](https://xcp-ng.org/forum/post/79281) [Forum#80010](https://xcp-ng.org/forum/post/80010)
- [Plugin/backup-reports] Fix _Metadata Backup_ report not sent in some cases (PR [#7776](https://github.com/vatesfr/xen-orchestra/pull/7776))

### Packages to release

Expand All @@ -45,6 +48,6 @@
- @xen-orchestra/xapi patch
- xen-api minor
- xo-server minor
- xo-web patch
- xo-web minor

<!--packages-end-->
13 changes: 10 additions & 3 deletions packages/xo-server-backup-reports/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -204,11 +204,13 @@ class BackupReportsXoPlugin {
throw new Error(`Unknown backup job type: ${job.type}`)
}

async _metadataHandler(log, { name: jobName }, schedule, force) {
async _metadataHandler(log, { name: jobName, settings }, schedule, force) {
const xo = this._xo

const formatDate = createDateFormatter(schedule?.timezone)

const mailReceivers = get(() => settings[''].reportRecipients)

const tasksByStatus = groupBy(log.tasks, 'status')

if (!force && log.data.reportWhen === 'failure') {
Expand All @@ -218,8 +220,12 @@ class BackupReportsXoPlugin {
for (const taskBatch of Object.values(tasksByStatus)) {
for (const task of taskBatch) {
task.additionnalData = await getAdditionnalData(task, { xo })
for (const subTask of task.tasks) {
subTask.additionnalData = await getAdditionnalData(subTask, { xo })

const subTasks = task.tasks
if (subTasks !== undefined) {
for (const subTask of subTasks) {
subTask.additionnalData = await getAdditionnalData(subTask, { xo })
}
}
}
}
Expand All @@ -235,6 +241,7 @@ class BackupReportsXoPlugin {
return this._sendReport({
...(await templatesTransform.markdown(templates.markdown.metadata(context))),
...(await templatesTransform.mjml(templates.mjml.metadata(context))),
mailReceivers,
subject: templates.mjml.metadataSubject(context),
success: log.status === 'success',
})
Expand Down
20 changes: 19 additions & 1 deletion packages/xo-web/src/xo-app/backup/new/metadata/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import {
editSchedule,
subscribeRemotes,
} from 'xo'
import { ReportRecipients } from '..'

import { constructPattern, destructPattern, FormFeedback, FormGroup, Input, Li, Ul } from '../../utils'

Expand Down Expand Up @@ -180,6 +181,18 @@ export default decorate([
setReportWhen({ setGlobalSettings }, { value }) {
setGlobalSettings('reportWhen', value)
},
addReportRecipient({ setGlobalSettings }, value) {
const { reportRecipients = [] } = this.state.settings?.[GLOBAL_SETTING_KEY] ?? {}
if (!reportRecipients.includes(value)) {
reportRecipients.push(value)
setGlobalSettings('reportRecipients', reportRecipients)
}
},
removeReportRecipient({ setGlobalSettings }, key) {
const { reportRecipients } = this.state.settings[GLOBAL_SETTING_KEY]
reportRecipients.splice(key, 1)
setGlobalSettings('reportRecipients', reportRecipients)
},
toggleMode:
(_, { mode }) =>
state => ({
Expand Down Expand Up @@ -274,7 +287,7 @@ export default decorate([
missingSchedules,
} = state.showErrors ? state : {}

const { reportWhen = 'failure' } = defined(() => state.settings[GLOBAL_SETTING_KEY], {})
const { reportWhen = 'failure', reportRecipients = [] } = defined(() => state.settings[GLOBAL_SETTING_KEY], {})

return (
<form id={state.idForm}>
Expand Down Expand Up @@ -360,6 +373,11 @@ export default decorate([
<CardBlock>
<RemoteProxy onChange={effects.setProxy} value={state.proxyId} />
<ReportWhen onChange={effects.setReportWhen} required value={reportWhen} />
<ReportRecipients
recipients={reportRecipients}
add={effects.addReportRecipient}
remove={effects.removeReportRecipient}
/>
</CardBlock>
</Card>
</Col>
Expand Down
Loading