[enh] add cc for mail in webDiffServers

This commit is contained in:
2019-08-31 18:19:09 +02:00
parent 8b60767622
commit 9966caa22a
3 changed files with 13 additions and 12 deletions

View File

@@ -4,7 +4,7 @@ import {ConfMail} from './types/conf'
import * as nodemailer from 'nodemailer' import * as nodemailer from 'nodemailer'
import * as os from 'os' import * as os from 'os'
export async function sendMail(conf: ConfMail, subject: string, html: string) { export async function sendMail(conf: ConfMail, subject: string, html: string, cc?: string) {
if (conf.enabled) { if (conf.enabled) {
let transporter = nodemailer.createTransport({ let transporter = nodemailer.createTransport({
@@ -23,7 +23,7 @@ export async function sendMail(conf: ConfMail, subject: string, html: string) {
let info = await transporter.sendMail({ let info = await transporter.sendMail({
from: conf.from, from: conf.from,
to: conf.to, to: conf.to,
cc: conf.cc, cc: (conf.cc ? [conf.cc] : []).concat(cc ? [cc] : []).join(','),
subject, subject,
html html
}) })
@@ -37,9 +37,9 @@ export const mail = {
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 () => { return async (cc?: string) => {
console.log(`${message}`) console.log(`${message}`)
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml()) await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(), cc)
} }
}, },
@@ -51,10 +51,10 @@ export const mail = {
Waiting ${(waitingDelay / 1000).toFixed(0)} seconds before trying to reconnect. Waiting ${(waitingDelay / 1000).toFixed(0)} seconds before trying to reconnect.
</p> </p>
`) => { `) => {
return async (waitingDelay: number) => { return async (waitingDelay: number, cc?: string) => {
console.log(`${message}`) console.log(`${message}`)
console.log('Waiting %s seconds...', (waitingDelay / 1000).toFixed(0)) console.log('Waiting %s seconds...', (waitingDelay / 1000).toFixed(0))
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(waitingDelay)) await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(waitingDelay), cc)
} }
}, },
@@ -63,9 +63,9 @@ export const mail = {
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 () => { return async (cc?: string) => {
console.log(`${message}`) console.log(`${message}`)
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml()) await sendMail(conf.mail, `[dwatcher] [${os.hostname}] ${message}`, getHtml(), cc)
} }
}, },

View File

@@ -25,6 +25,7 @@ export interface ConfWebDiff {
file1: string file1: string
file2: string file2: string
frequency: number frequency: number
cc?: string
} }
export interface ConfBMA extends ConfURL { export interface ConfBMA extends ConfURL {

View File

@@ -62,21 +62,21 @@ export function webDiffWatcher(conf: Conf) {
conf.reconnectionDelays, conf.reconnectionDelays,
mail.onEstablished(conf, target, 'webdiff successfully started'), () => mail.onEstablished(conf, target, 'webdiff successfully started')(webDiffConf.cc),
// When a disconnection is detected // When a disconnection is detected
mail.onDisconnect(conf, target, 'Diff detected', (waitingDelay: number) => ` (waitingDelay: number) => mail.onDisconnect(conf, target, 'Diff detected', (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.
</p> </p>
`), `)(waitingDelay, webDiffConf.cc),
async () => { async () => {
console.log('Trying to connect to %s', target) console.log('Trying to connect to %s', target)
}, },
mail.onRestartSuccess(conf, target), () => mail.onRestartSuccess(conf, target)(webDiffConf.cc),
async (e) => { async (e) => {
console.error(e.message) console.error(e.message)