[enh] hostname in mails

This commit is contained in:
2019-06-11 13:35:45 +02:00
parent 490e8b236d
commit 1aa42aa0e8

View File

@@ -2,6 +2,7 @@ import {moment} from "duniter/app/lib/common-libs/moment";
import {Conf} from "./types/conf";
import {ConfMail} from './types/conf'
import * as nodemailer from 'nodemailer'
import * as os from 'os'
export async function sendMail(conf: ConfMail, subject: string, html: string) {
@@ -33,7 +34,7 @@ export const mail = {
onEstablished: (conf: Conf, target: string) => {
return async () => {
console.log('Connection established')
await sendMail(conf.mail, '[dwatcher] Connection established', `
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] Connection established`, `
<p>
Connection to ${target} established on ${moment().format('DD-MM-YYYY HH:mm:ss')}.
</p>
@@ -45,7 +46,7 @@ export const mail = {
return async (waitingDelay: number) => {
console.log('Connection closed')
console.log('Waiting %s seconds...', waitingDelay)
await sendMail(conf.mail, '[dwatcher] Connection closed', `
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] Connection closed`, `
<p>
Connection to ${target} was lost on ${moment().format('dd-MM-YYYY HH:mm:ss')}.
</p>
@@ -59,7 +60,7 @@ export const mail = {
onRestartSuccess: (conf: Conf, target: string) => {
return async () => {
console.log('Connection recovered')
await sendMail(conf.mail, '[dwatcher] Connection recovered', `
await sendMail(conf.mail, `[dwatcher] [${os.hostname}] Connection recovered`, `
<p>
Connection to ${target} was recovered on ${moment().format('dd-MM-YYYY HH:mm:ss')}.
</p>
@@ -70,7 +71,7 @@ export const mail = {
onError: (conf: Conf, target: string) => {
return async (e: Error) => {
console.error(e.message || e)
// await sendMail(conf.mail, '[dwatcher] Connection error', `
// await sendMail(conf.mail, `[dwatcher] Connection error`, `
// <p>
// Connection error with ${target} on ${moment().format('dd-MM-YYYY HH:mm:ss')}:
// </p>