@@ -375,10 +375,22 @@ class BackupReportsXoPlugin {
} )
}
const failedTask sText = [ ]
const skippedVmsText = [ ]
const successfulVmsText = [ ]
const interruptedVmsText = [ ]
const failedVm sText = {
default : [ ] ,
compact : [ ] ,
}
const skippedVmsText = {
default : [ ] ,
compact : [ ] ,
}
const successfulVmsText = {
default : [ ] ,
compact : [ ] ,
}
const interruptedVmsText = {
default : [ ] ,
compact : [ ] ,
}
const nagiosText = [ ]
let globalMergeSize = 0
@@ -393,8 +405,10 @@ class BackupReportsXoPlugin {
const { type , id } = taskLog . data ? ? { }
if ( taskLog . message === 'get SR record' || taskLog . message === 'get remote adapter' ) {
const text = [ ]
++ nFailures
failedTasksT ext. push (
t ext. push (
// It will ensure that it will never be in a nested list
''
)
@@ -402,25 +416,29 @@ class BackupReportsXoPlugin {
try {
if ( type === 'SR' ) {
const { name _label : name , uuid } = xo . getObject ( id )
failedTasksT ext. push ( ` ### ${ name } ` , '' , ` - **UUID**: ${ uuid } ` )
t ext. push ( ` ### ${ name } ` , '' , ` - **UUID**: ${ uuid } ` )
nagiosText . push ( ` [( ${ type } failed) ${ name } : ${ taskLog . result . message } ] ` )
} else {
const { name } = await xo . getRemote ( id )
failedTasksT ext. push ( ` ### ${ name } ` , '' , ` - **UUID**: ${ id } ` )
t ext. push ( ` ### ${ name } ` , '' , ` - **UUID**: ${ id } ` )
nagiosText . push ( ` [( ${ type } failed) ${ name } : ${ taskLog . result . message } ] ` )
}
} catch ( error ) {
logger . warn ( error )
failedTasksT ext. push ( ` ### ${ UNKNOWN _ITEM } ` , '' , ` - **UUID**: ${ id } ` )
t ext. push ( ` ### ${ UNKNOWN _ITEM } ` , '' , ` - **UUID**: ${ id } ` )
nagiosText . push ( ` [( ${ type } failed) ${ id } : ${ taskLog . result . message } ] ` )
}
failedTasksT ext. push (
t ext. push (
` - **Type**: ${ type } ` ,
... getTemporalDataMarkdown ( taskLog . end , taskLog . start , formatDate ) ,
... getWarningsMarkdown ( taskLog . warnings ) ,
` - **Error**: ${ taskLog . result . message } `
)
failedVmsText . default . push ( ... text )
failedVmsText . compact . push ( ... text )
continue
}
@@ -537,32 +555,39 @@ class BackupReportsXoPlugin {
if ( taskLog . result !== undefined ) {
if ( taskLog . status === 'skipped' ) {
++ nSkipped
skippedVmsText . push (
const common = [
... text ,
` - **Reason**: ${
taskLog . result . message === UNHEALTHY _VDI _CHAIN _ERROR
? UNHEALTHY _VDI _CHAIN _MESSAGE
: taskLog . result . message
} `
)
} ` ,
]
skippedVmsText . default . push ( ... common )
skippedVmsText . compact . push ( ... common )
nagiosText . push ( ` [(Skipped) ${ vm !== undefined ? vm . name _label : 'undefined' } : ${ taskLog . result . message } ] ` )
} else {
++ nFailures
failedTasksText . push ( ... text , ` - **Error**: ${ taskLog . result . message } ` )
const common = [ ... text , ` - **Error**: ${ taskLog . result . message } ` ]
failedVmsText . default . push ( ... common )
failedVmsText . compact . push ( ... common )
nagiosText . push ( ` [(Failed) ${ vm !== undefined ? vm . name _label : 'undefined' } : ${ taskLog . result . message } ] ` )
}
} else {
if ( taskLog . status === 'failure' ) {
++ nFailures
failedTasksTex t . push ( ... text , ... subText )
failedVmsText . defaul t . push ( ... text , ... subText )
failedVmsText . compact . push ( ... text )
nagiosText . push ( ` [ ${ vm !== undefined ? vm . name _label : 'undefined' } : (failed)[ ${ failedSubTasks . toString ( ) } ]] ` )
} else if ( taskLog . status === 'interrupted' ) {
++ nInterrupted
interruptedVmsText . push ( ... text , ... subText )
interruptedVmsText . default . push ( ... text , ... subText )
interruptedVmsText . compact . push ( ... text )
nagiosText . push ( ` [(Interrupted) ${ vm !== undefined ? vm . name _label : 'undefined' } ] ` )
} else {
successfulVmsText . push ( ... text , ... subText )
successfulVmsText . default . push ( ... text , ... subText )
successfulVmsText . compact . push ( ... text )
}
}
}
@@ -582,27 +607,37 @@ class BackupReportsXoPlugin {
... getWarningsMarkdown ( log . warnings ) ,
'' ,
]
const slackMarkdown = [ ... markdown ]
if ( nFailures !== 0 ) {
markdown . push ( '---' , '' , ` ## ${ nFailures } Failure ${ nFailures === 1 ? '' : 's' } ` , '' , ... failedTasksText )
const common = [ '---' , '' , ` ## ${ nFailures } Failure ${ nFailures === 1 ? '' : 's' } ` , '' ]
markdown . push ( ... common , ... failedVmsText . default )
slackMarkdown . push ( ... common , ... failedVmsText . compact )
}
if ( nSkipped !== 0 ) {
markdown . push ( '---' , '' , ` ## ${ nSkipped } Skipped ` , '' , ... skippedVmsText )
const common = [ '---' , '' , ` ## ${ nSkipped } Skipped ` , '' ]
markdown . push ( ... common , ... skippedVmsText . default )
slackMarkdown . push ( ... common , ... skippedVmsText . compact )
}
if ( nInterrupted !== 0 ) {
markdown . push ( '---' , '' , ` ## ${ nInterrupted } Interrupted ` , '' , ... interruptedVmsText )
const common = [ '---' , '' , ` ## ${ nInterrupted } Interrupted ` , '' ]
markdown . push ( ... common , ... interruptedVmsText . default )
slackMarkdown . push ( ... common , ... interruptedVmsText . compact )
}
if ( nSuccesses !== 0 && ( force || reportWhen !== 'failure' ) ) {
markdown . push ( '---' , '' , ` ## ${ nSuccesses } Success ${ nSuccesses === 1 ? '' : 'es' } ` , '' , ... successfulVmsText )
const common = [ '---' , '' , ` ## ${ nSuccesses } Success ${ nSuccesses === 1 ? '' : 'es' } ` , '' ]
markdown . push ( ... common , ... successfulVmsText . default )
slackMarkdown . push ( ... common , ... successfulVmsText . compact )
}
markdown . push ( '---' , '' , ` * ${ pkg . name } v ${ pkg . version } * ` )
return this . _sendReport ( {
mailReceivers ,
markdown : toMarkdown ( markdown ) ,
slackMarkdown : toMarkdown ( slackMarkdown ) ,
subject : ` [Xen Orchestra] ${ log . status } − Backup report for ${ jobName } ${ STATUS _ICON [ log . status ] } ` ,
success : log . status === 'success' ,
nagiosMarkdown :
@@ -614,7 +649,7 @@ class BackupReportsXoPlugin {
} )
}
_sendReport ( { mailReceivers , markdown , nagiosMarkdown , subject , success } ) {
_sendReport ( { mailReceivers , markdown , slackMarkdown = markdown , nagiosMarkdown , subject , success } ) {
if ( mailReceivers === undefined || mailReceivers . length === 0 ) {
mailReceivers = this . _mailsReceivers
}
@@ -634,7 +669,7 @@ class BackupReportsXoPlugin {
} ) ,
xo . sendSlackMessage !== undefined &&
xo . sendSlackMessage ( {
message : m arkdown,
message : slackM arkdown,
} ) ,
xo . sendPassiveCheck !== undefined &&
xo . sendPassiveCheck ( {