send mail in case of missing events
This commit is contained in:
parent
d9528decae
commit
e52502cdd3
27
dist/missingeventdetector.js
vendored
27
dist/missingeventdetector.js
vendored
@ -1,20 +1,45 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const nodemailer = require("nodemailer");
|
||||
const log = require("./log");
|
||||
const CallChain = require("./callchain");
|
||||
const Processor = require("./processor");
|
||||
const CHECK_PERIOD = 60; // seconds
|
||||
const SMTP_HOST = "localhost";
|
||||
const SMTP_PORT = 25;
|
||||
const SMTP_SENDER = "dispatcher@hottis.de";
|
||||
const SMTP_RECEIVER = "woho@hottis.de";
|
||||
class ClientEntry {
|
||||
}
|
||||
class MissingEventProcessor extends Processor.AProcessor {
|
||||
constructor() {
|
||||
super("MissingEventProcessor");
|
||||
this.clientMap = new Map();
|
||||
this.smtp = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: SMTP_PORT,
|
||||
secure: false
|
||||
});
|
||||
this.timer = setInterval(() => {
|
||||
this.clientMap.forEach((value, key) => {
|
||||
let currentTime = new Date().getTime();
|
||||
let elapsedTime = 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 = {
|
||||
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) => {
|
||||
log.info(`Missing event info mail sent, ${v.response}`);
|
||||
})
|
||||
.catch((reason) => {
|
||||
log.error(`Failure when sending missing event info: ${reason}`);
|
||||
});
|
||||
}
|
||||
});
|
||||
}, CHECK_PERIOD * 1000);
|
||||
}
|
||||
@ -30,8 +55,8 @@ class MissingEventProcessor extends Processor.AProcessor {
|
||||
clientEntry.count += 1;
|
||||
if (clientEntry.count >= 1) {
|
||||
clientEntry.delaySum += clientEntry.delay;
|
||||
}
|
||||
clientEntry.avgDelay = clientEntry.delaySum / clientEntry.count;
|
||||
}
|
||||
this.clientMap.set(client, clientEntry);
|
||||
log.info(`Entry for ${client} updated`);
|
||||
}
|
||||
|
@ -1,50 +0,0 @@
|
||||
0 info it worked if it ends with ok
|
||||
1 verbose cli [ '/usr/bin/nodejs',
|
||||
1 verbose cli '/usr/bin/npm',
|
||||
1 verbose cli 'start',
|
||||
1 verbose cli '--',
|
||||
1 verbose cli '-c',
|
||||
1 verbose cli 'config.json' ]
|
||||
2 info using npm@3.10.10
|
||||
3 info using node@v6.11.2
|
||||
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
|
||||
5 info lifecycle dispatcher@1.0.0~prestart: dispatcher@1.0.0
|
||||
6 silly lifecycle dispatcher@1.0.0~prestart: no script for prestart, continuing
|
||||
7 info lifecycle dispatcher@1.0.0~start: dispatcher@1.0.0
|
||||
8 verbose lifecycle dispatcher@1.0.0~start: unsafe-perm in lifecycle true
|
||||
9 verbose lifecycle dispatcher@1.0.0~start: PATH: /usr/lib/node_modules/npm/bin/node-gyp-bin:/home/wn/workspace-node/Dispatcher/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/local/games:/usr/games:/home/wn/.local/bin:/home/wn/bin:/opt/jdk/bin:/opt/apache-maven/bin:/home/wn/mos/bin
|
||||
10 verbose lifecycle dispatcher@1.0.0~start: CWD: /home/wn/workspace-node/Dispatcher
|
||||
11 silly lifecycle dispatcher@1.0.0~start: Args: [ '-c', 'node dist/main.js "-c" "config.json"' ]
|
||||
12 silly lifecycle dispatcher@1.0.0~start: Returned: code: 1 signal: null
|
||||
13 info lifecycle dispatcher@1.0.0~start: Failed to exec start script
|
||||
14 verbose stack Error: dispatcher@1.0.0 start: `node dist/main.js "-c" "config.json"`
|
||||
14 verbose stack Exit status 1
|
||||
14 verbose stack at EventEmitter.<anonymous> (/usr/lib/node_modules/npm/lib/utils/lifecycle.js:255:16)
|
||||
14 verbose stack at emitTwo (events.js:106:13)
|
||||
14 verbose stack at EventEmitter.emit (events.js:191:7)
|
||||
14 verbose stack at ChildProcess.<anonymous> (/usr/lib/node_modules/npm/lib/utils/spawn.js:40:14)
|
||||
14 verbose stack at emitTwo (events.js:106:13)
|
||||
14 verbose stack at ChildProcess.emit (events.js:191:7)
|
||||
14 verbose stack at maybeClose (internal/child_process.js:891:16)
|
||||
14 verbose stack at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
|
||||
15 verbose pkgid dispatcher@1.0.0
|
||||
16 verbose cwd /home/wn/workspace-node/Dispatcher
|
||||
17 error Linux 4.9.0-3-amd64
|
||||
18 error argv "/usr/bin/nodejs" "/usr/bin/npm" "start" "--" "-c" "config.json"
|
||||
19 error node v6.11.2
|
||||
20 error npm v3.10.10
|
||||
21 error code ELIFECYCLE
|
||||
22 error dispatcher@1.0.0 start: `node dist/main.js "-c" "config.json"`
|
||||
22 error Exit status 1
|
||||
23 error Failed at the dispatcher@1.0.0 start script 'node dist/main.js "-c" "config.json"'.
|
||||
23 error Make sure you have the latest version of node.js and npm installed.
|
||||
23 error If you do, this is most likely a problem with the dispatcher package,
|
||||
23 error not with npm itself.
|
||||
23 error Tell the author that this fails on your system:
|
||||
23 error node dist/main.js "-c" "config.json"
|
||||
23 error You can get information on how to open an issue for this project with:
|
||||
23 error npm bugs dispatcher
|
||||
23 error Or if that isn't available, you can get their info via:
|
||||
23 error npm owner ls dispatcher
|
||||
23 error There is likely additional logging output above.
|
||||
24 verbose exit [ 1, true ]
|
@ -17,6 +17,7 @@
|
||||
"@types/mongodb": "^2.2.10",
|
||||
"@types/mqtt": "0.0.34",
|
||||
"@types/node": "^8.0.14",
|
||||
"@types/nodemailer": "^3.1.2",
|
||||
"typescript": "^2.4.2"
|
||||
},
|
||||
"dependencies": {
|
||||
@ -24,6 +25,7 @@
|
||||
"command-line-args": "^4.0.7",
|
||||
"moment": "^2.18.1",
|
||||
"mongodb": "^2.2.31",
|
||||
"mqtt": "^2.9.2"
|
||||
"mqtt": "^2.9.2",
|
||||
"nodemailer": "^4.0.1"
|
||||
}
|
||||
}
|
||||
|
@ -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)
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user