mailing: dynamic title
This commit is contained in:
@@ -110,17 +110,22 @@ async function sendEmail(subject: string, html: string, cc?: string) {
|
|||||||
|
|
||||||
export const mail = {
|
export const mail = {
|
||||||
|
|
||||||
onEstablished: (target: string, message = `Connection established for ${target}`, getHtml: () => string = () => `
|
onEstablished: (target: string,
|
||||||
|
message: () => string|undefined = () => `Connection established for ${target}`,
|
||||||
|
getHtml: () => string = () => `
|
||||||
<p>
|
<p>
|
||||||
Connection from [${os.hostname}] to ${target} established on ${moment().format('DD-MM-YYYY HH:mm:ss')}.
|
Connection from [${os.hostname}] to ${target} established on ${moment().format('DD-MM-YYYY HH:mm:ss')}.
|
||||||
</p>
|
</p>
|
||||||
`) => {
|
`) => {
|
||||||
return async (cc?: string) => {
|
return async (cc?: string) => {
|
||||||
await queueEmail(`[dw] [${os.hostname}] ${message}`, getHtml(), cc)
|
await queueEmail(`[dw] [${os.hostname}] ${message()}`, getHtml(), cc)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onDisconnect: (target: string, message = `Connection closed for ${target}`, getErrorMessage: () => string = () => '', getHtml: (waitingDelay: number, recallDelay: number) => string = (waitingDelay: number, recallDelay: number) => `
|
onDisconnect: (target: string,
|
||||||
|
message: () => string|undefined = () => `Connection closed for ${target}`,
|
||||||
|
getErrorMessage: () => string = () => '',
|
||||||
|
getHtml: (waitingDelay: number, recallDelay: number) => string = (waitingDelay: number, recallDelay: number) => `
|
||||||
<p>
|
<p>
|
||||||
Connection from [${os.hostname}] to ${target} was lost on ${moment().format('dd-MM-YYYY HH:mm:ss')}.
|
Connection from [${os.hostname}] to ${target} was lost on ${moment().format('dd-MM-YYYY HH:mm:ss')}.
|
||||||
</p>
|
</p>
|
||||||
@@ -131,18 +136,20 @@ export const mail = {
|
|||||||
`) => {
|
`) => {
|
||||||
return async (waitingDelay: number, recallDelay: number, cc?: string) => {
|
return async (waitingDelay: number, recallDelay: number, cc?: string) => {
|
||||||
console.log('Waiting %s seconds...', (waitingDelay / 1000).toFixed(0))
|
console.log('Waiting %s seconds...', (waitingDelay / 1000).toFixed(0))
|
||||||
await queueEmail(`[dw] [${os.hostname}] ${message}`, getHtml(waitingDelay, recallDelay), cc)
|
await queueEmail(`[dw] [${os.hostname}] ${message()}`, getHtml(waitingDelay, recallDelay), cc)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onRestartSuccess: (target: string, message = `Connection recovered for ${target}`, getHtml: () => string = () => `
|
onRestartSuccess: (target: string,
|
||||||
|
message: () => string|undefined = () => `Connection recovered for ${target}`,
|
||||||
|
getHtml: () => string = () => `
|
||||||
<p>
|
<p>
|
||||||
Connection from [${os.hostname}] to ${target} was recovered on ${moment().format('dd-MM-YYYY HH:mm:ss')}.
|
Connection from [${os.hostname}] to ${target} was recovered on ${moment().format('dd-MM-YYYY HH:mm:ss')}.
|
||||||
</p>
|
</p>
|
||||||
`) => {
|
`) => {
|
||||||
return async (cc?: string) => {
|
return async (cc?: string) => {
|
||||||
console.log(`${message}`)
|
console.log(`${message()}`)
|
||||||
await queueEmail(`[dw] [${os.hostname}] ${message}`, getHtml(), cc)
|
await queueEmail(`[dw] [${os.hostname}] ${message()}`, getHtml(), cc)
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ export function urlWatcher(conf: Conf, checkValidity: (data: any) => Promise<Url
|
|||||||
conf.waitingDelay,
|
conf.waitingDelay,
|
||||||
conf.recallDelay,
|
conf.recallDelay,
|
||||||
|
|
||||||
mail.onEstablished(urlConf.address, getOkTitle()),
|
mail.onEstablished(urlConf.address, () => getOkTitle()),
|
||||||
|
|
||||||
// When a disconnection is detected
|
// When a disconnection is detected
|
||||||
(waitingDelay: number, recallDelay, error?: any) => {
|
(waitingDelay: number, recallDelay, error?: any) => {
|
||||||
@@ -57,14 +57,14 @@ export function urlWatcher(conf: Conf, checkValidity: (data: any) => Promise<Url
|
|||||||
koTitle = getKoTitle()
|
koTitle = getKoTitle()
|
||||||
koMessage = () => `<p>${error.errorMessage}</p>`
|
koMessage = () => `<p>${error.errorMessage}</p>`
|
||||||
}
|
}
|
||||||
return mail.onDisconnect(urlConf.address, koTitle, koMessage)(waitingDelay, recallDelay)
|
return mail.onDisconnect(urlConf.address, () => koTitle, koMessage)(waitingDelay, recallDelay)
|
||||||
},
|
},
|
||||||
|
|
||||||
async () => {
|
async () => {
|
||||||
console.log('Trying to connect to %s', urlConf.address)
|
console.log('Trying to connect to %s', urlConf.address)
|
||||||
},
|
},
|
||||||
|
|
||||||
mail.onRestartSuccess(urlConf.address, getRecoveredTitle()),
|
mail.onRestartSuccess(urlConf.address, () => getRecoveredTitle()),
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -61,10 +61,10 @@ export function webDiffWatcher(conf: Conf) {
|
|||||||
conf.waitingDelay,
|
conf.waitingDelay,
|
||||||
conf.recallDelay,
|
conf.recallDelay,
|
||||||
|
|
||||||
() => mail.onEstablished(target, 'webdiff successfully started')(webDiffConf.cc),
|
() => mail.onEstablished(target, () => 'webdiff successfully started')(webDiffConf.cc),
|
||||||
|
|
||||||
// When a disconnection is detected
|
// When a disconnection is detected
|
||||||
(waitingDelay: number, recallDelay: number) => mail.onDisconnect(target, 'Diff detected', undefined, (waitingDelay: number) => `
|
(waitingDelay: number, recallDelay: number) => mail.onDisconnect(target, () => 'Diff detected', undefined, (waitingDelay: number) => `
|
||||||
${htmlDiff}
|
${htmlDiff}
|
||||||
<p>
|
<p>
|
||||||
Waiting ${(waitingDelay / 1000).toFixed(0)} seconds before trying to reconnect.
|
Waiting ${(waitingDelay / 1000).toFixed(0)} seconds before trying to reconnect.
|
||||||
|
|||||||
@@ -44,16 +44,16 @@ export function ws2pWatcher(conf: Conf) {
|
|||||||
conf.waitingDelay,
|
conf.waitingDelay,
|
||||||
conf.recallDelay,
|
conf.recallDelay,
|
||||||
|
|
||||||
mail.onEstablished(target, `State OK WS2P on ${wserver.address}`),
|
mail.onEstablished(target, () => `State OK WS2P on ${wserver.address}`),
|
||||||
|
|
||||||
// When a disconnection is detected
|
// When a disconnection is detected
|
||||||
mail.onDisconnect(target, `State FAILURE WS2P on ${wserver.address}`),
|
mail.onDisconnect(target, () => `State FAILURE WS2P on ${wserver.address}`),
|
||||||
|
|
||||||
async () => {
|
async () => {
|
||||||
console.log('Trying to connect to %s', target)
|
console.log('Trying to connect to %s', target)
|
||||||
},
|
},
|
||||||
|
|
||||||
mail.onRestartSuccess(target, `State RECOVERED WS2P on ${wserver.address}`),
|
mail.onRestartSuccess(target, () => `State RECOVERED WS2P on ${wserver.address}`),
|
||||||
)
|
)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user