config option to disable database access, abstraction of alarm mail sending

This commit is contained in:
Wolfgang Hottgenroth
2017-08-28 10:27:21 +02:00
parent 5dc3259a31
commit 9356a81fd1
4 changed files with 36 additions and 27 deletions

View File

@ -1,4 +1,3 @@
import * as nodemailer from 'nodemailer'
import * as log from './log'
import * as CallChain from './callchain'
import * as Processor from './processor'
@ -20,20 +19,11 @@ class ClientEntry {
class MissingEventProcessor extends Processor.AProcessor {
private timer : NodeJS.Timer
private clientMap : Map<string, ClientEntry> = new Map<string, ClientEntry>()
private smtp : nodemailer.Transporter
constructor() {
super("MissingEventProcessor")
this.smtp = nodemailer.createTransport({
host: config.dict.smtpHost,
port: config.dict.smtpPort,
secure: false,
tls: {
rejectUnauthorized: false
}
});
this.timer = setInterval(() => {
this.clientMap.forEach((value : ClientEntry, key : string) : void => {
@ -42,20 +32,7 @@ class MissingEventProcessor extends Processor.AProcessor {
log.info(`Checking ${key}, elapsed: ${elapsedTime / 1000}, avg. delay: ${value.avgDelay / 1000}`)
if ((value.avgDelay != 0) && (elapsedTime > (value.avgDelay * 3))) {
let mail : nodemailer.SendMailOptions = {
from: config.dict.smtpSender,
to: config.dict.smtpReceiver,
subject: `Missing Event Detected for ${key}`,
text: `Missing Event Detected: ${key}, elapsed: ${elapsedTime / 1000}, avg. delay: ${value.avgDelay / 1000}`
};
this.smtp.sendMail(mail)
.then((v : nodemailer.SentMessageInfo) => {
log.info(`Missing event info mail sent, ${v.response}`)
})
.catch((reason : any) => {
log.error(`Failure when sending missing event info: ${reason}`)
})
log.sendAlarmMail(`Missing Event Detected: ${key}, elapsed: ${elapsedTime / 1000}, avg. delay: ${value.avgDelay / 1000}`)
}
})
}, CHECK_PERIOD * 1000)