send mail in case of missing events
This commit is contained in:
@ -1,9 +1,15 @@
|
||||
import * as nodemailer from 'nodemailer'
|
||||
import * as log from './log'
|
||||
import * as CallChain from './callchain'
|
||||
import * as Processor from './processor'
|
||||
|
||||
|
||||
const CHECK_PERIOD : number = 60 // seconds
|
||||
const SMTP_HOST : string = "localhost"
|
||||
const SMTP_PORT : number = 25
|
||||
const SMTP_SENDER : string = "dispatcher@hottis.de"
|
||||
const SMTP_RECEIVER : string = "woho@hottis.de"
|
||||
|
||||
|
||||
class ClientEntry {
|
||||
client : string
|
||||
@ -17,14 +23,40 @@ 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: SMTP_HOST,
|
||||
port: SMTP_PORT,
|
||||
secure: false
|
||||
});
|
||||
|
||||
this.timer = setInterval(() => {
|
||||
this.clientMap.forEach((value : ClientEntry, key : string) : void => {
|
||||
let currentTime : number = new Date().getTime()
|
||||
let elapsedTime : number = currentTime - value.lastEvent
|
||||
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: SMTP_SENDER,
|
||||
to: SMTP_RECEIVER,
|
||||
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}`)
|
||||
})
|
||||
}
|
||||
})
|
||||
}, CHECK_PERIOD * 1000)
|
||||
}
|
||||
|
Reference in New Issue
Block a user