[enh] Watch ww and ww2 diff

This commit is contained in:
2019-08-31 17:43:29 +02:00
parent f71fe39271
commit 10925352ab
7 changed files with 130 additions and 16 deletions

View File

@@ -31,40 +31,40 @@ export async function sendMail(conf: ConfMail, subject: string, html: string) {
export const mail = {
onEstablished: (conf: Conf, target: string) => {
return async () => {
console.log('Connection established for %s', target)
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] Connection established`, `
onEstablished: (conf: Conf, target: string, message = `Connection established for ${target}`, getHtml: () => string = () => `
<p>
Connection from [${os.hostname}] to ${target} established on ${moment().format('DD-MM-YYYY HH:mm:ss')}.
</p>
`)
`) => {
return async () => {
console.log(`${message}`)
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml())
}
},
onDisconnect: (conf: Conf, target: string) => {
return async (waitingDelay: number) => {
console.log('Connection closed for %s', target)
console.log('Waiting %s seconds...', (waitingDelay / 1000).toFixed(0))
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] Connection closed`, `
onDisconnect: (conf: Conf, target: string, message = `Connection closed for ${target}`, getHtml: (waitingDelay: number) => string = (waitingDelay: number) => `
<p>
Connection from [${os.hostname}] to ${target} was lost on ${moment().format('dd-MM-YYYY HH:mm:ss')}.
</p>
<p>
Waiting ${(waitingDelay / 1000).toFixed(0)} seconds before trying to reconnect.
</p>
`)
`) => {
return async (waitingDelay: number) => {
console.log(`${message}`)
console.log('Waiting %s seconds...', (waitingDelay / 1000).toFixed(0))
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(waitingDelay))
}
},
onRestartSuccess: (conf: Conf, target: string) => {
return async () => {
console.log('Connection recovered for %s', target)
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] Connection recovered`, `
onRestartSuccess: (conf: Conf, target: string, message = `Connection recovered for ${target}`, getHtml: () => string = () => `
<p>
Connection from [${os.hostname}] to ${target} was recovered on ${moment().format('dd-MM-YYYY HH:mm:ss')}.
</p>
`)
`) => {
return async () => {
console.log(`${message}`)
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml())
}
},