config
This commit is contained in:
14
dist/config.js
vendored
Normal file
14
dist/config.js
vendored
Normal file
@ -0,0 +1,14 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const fs = require("fs");
|
||||
const cmdargs = require("command-line-args");
|
||||
const OPTION_DEFINITIONS = [
|
||||
{ name: 'verbose', alias: 'v', type: Boolean },
|
||||
{ name: 'config', alias: 'c', type: String, defaultValue: '~/mqttDispatcher.conf' }
|
||||
];
|
||||
function readConfig() {
|
||||
let options = cmdargs(OPTION_DEFINITIONS);
|
||||
exports.dict = JSON.parse(fs.readFileSync(options.config, "utf8"));
|
||||
}
|
||||
exports.readConfig = readConfig;
|
||||
//# sourceMappingURL=config.js.map
|
14
dist/main.js
vendored
14
dist/main.js
vendored
@ -2,23 +2,17 @@
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const log = require("./log");
|
||||
const mqtt = require("./mqttdispatcher");
|
||||
const fs = require("fs");
|
||||
const cmdargs = require("command-line-args");
|
||||
const config = require("./config");
|
||||
const EspThermToJson = require("./espthermtojson");
|
||||
const MissingEventDetector = require("./missingeventdetector");
|
||||
const OPTION_DEFINITIONS = [
|
||||
{ name: 'verbose', alias: 'v', type: Boolean },
|
||||
{ name: 'config', alias: 'c', type: String, defaultValue: '~/mqttDispatcher.conf' }
|
||||
];
|
||||
const OPTIONS = cmdargs(OPTION_DEFINITIONS);
|
||||
const CONFIG = JSON.parse(fs.readFileSync(OPTIONS.config, "utf8"));
|
||||
log.info("Dispatcher starting");
|
||||
let dispatcher = new mqtt.MqttDispatcher(CONFIG.brokerUrl, CONFIG.brokerUser, CONFIG.brokerPass, CONFIG.brokerCa);
|
||||
config.readConfig();
|
||||
let dispatcher = new mqtt.MqttDispatcher(config.dict.brokerUrl, config.dict.brokerUser, config.dict.brokerPass, config.dict.brokerCa);
|
||||
const ESP_THERM_TOPIC = 'IoT/espThermometer2/#';
|
||||
dispatcher.register(ESP_THERM_TOPIC, 'toJson', EspThermToJson.espThermToJson);
|
||||
let missingeventdetector = new MissingEventDetector.MissingEventDetector();
|
||||
dispatcher.register(ESP_THERM_TOPIC, 'MissingEventDetector', missingeventdetector);
|
||||
// let mongo : MongoSave.MongoSave = new MongoSave.MongoSave(CONFIG.mongoDbUrl)
|
||||
// let mongo : MongoSave.MongoSave = new MongoSave.MongoSave(config.dict.mongoDbUrl)
|
||||
// dispatcher.register(ESP_THERM_TOPIC, 'MongoSave', mongo);
|
||||
dispatcher.exec();
|
||||
log.info("Dispatcher running");
|
||||
|
13
dist/missingeventdetector.js
vendored
13
dist/missingeventdetector.js
vendored
@ -4,11 +4,8 @@ const nodemailer = require("nodemailer");
|
||||
const log = require("./log");
|
||||
const CallChain = require("./callchain");
|
||||
const Processor = require("./processor");
|
||||
const config = require("./config");
|
||||
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 {
|
||||
@ -16,8 +13,8 @@ class MissingEventProcessor extends Processor.AProcessor {
|
||||
super("MissingEventProcessor");
|
||||
this.clientMap = new Map();
|
||||
this.smtp = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: SMTP_PORT,
|
||||
host: config.dict.smtpHost,
|
||||
port: config.dict.smtpPort,
|
||||
secure: false
|
||||
});
|
||||
this.timer = setInterval(() => {
|
||||
@ -27,8 +24,8 @@ 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 = {
|
||||
from: SMTP_SENDER,
|
||||
to: SMTP_RECEIVER,
|
||||
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}`
|
||||
};
|
||||
|
Reference in New Issue
Block a user