config
This commit is contained in:
@ -3,5 +3,9 @@
|
|||||||
"brokerUser": "wn",
|
"brokerUser": "wn",
|
||||||
"brokerPass": "locutus",
|
"brokerPass": "locutus",
|
||||||
"brokerCa": "/home/wn/server-ca.crt",
|
"brokerCa": "/home/wn/server-ca.crt",
|
||||||
"mongoDbUrl": "mongodb://localhost/hottis"
|
"mongoDbUrl": "mongodb://localhost/hottis",
|
||||||
|
"smtpHost": "localhost",
|
||||||
|
"smtpPort": 25,
|
||||||
|
"smtpSender": "dispatcher@hottis.de",
|
||||||
|
"smtpReceiver": "woho@hottis.de"
|
||||||
}
|
}
|
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 });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
const log = require("./log");
|
const log = require("./log");
|
||||||
const mqtt = require("./mqttdispatcher");
|
const mqtt = require("./mqttdispatcher");
|
||||||
const fs = require("fs");
|
const config = require("./config");
|
||||||
const cmdargs = require("command-line-args");
|
|
||||||
const EspThermToJson = require("./espthermtojson");
|
const EspThermToJson = require("./espthermtojson");
|
||||||
const MissingEventDetector = require("./missingeventdetector");
|
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");
|
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/#';
|
const ESP_THERM_TOPIC = 'IoT/espThermometer2/#';
|
||||||
dispatcher.register(ESP_THERM_TOPIC, 'toJson', EspThermToJson.espThermToJson);
|
dispatcher.register(ESP_THERM_TOPIC, 'toJson', EspThermToJson.espThermToJson);
|
||||||
let missingeventdetector = new MissingEventDetector.MissingEventDetector();
|
let missingeventdetector = new MissingEventDetector.MissingEventDetector();
|
||||||
dispatcher.register(ESP_THERM_TOPIC, '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.register(ESP_THERM_TOPIC, 'MongoSave', mongo);
|
||||||
dispatcher.exec();
|
dispatcher.exec();
|
||||||
log.info("Dispatcher running");
|
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 log = require("./log");
|
||||||
const CallChain = require("./callchain");
|
const CallChain = require("./callchain");
|
||||||
const Processor = require("./processor");
|
const Processor = require("./processor");
|
||||||
|
const config = require("./config");
|
||||||
const CHECK_PERIOD = 60; // seconds
|
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 ClientEntry {
|
||||||
}
|
}
|
||||||
class MissingEventProcessor extends Processor.AProcessor {
|
class MissingEventProcessor extends Processor.AProcessor {
|
||||||
@ -16,8 +13,8 @@ class MissingEventProcessor extends Processor.AProcessor {
|
|||||||
super("MissingEventProcessor");
|
super("MissingEventProcessor");
|
||||||
this.clientMap = new Map();
|
this.clientMap = new Map();
|
||||||
this.smtp = nodemailer.createTransport({
|
this.smtp = nodemailer.createTransport({
|
||||||
host: SMTP_HOST,
|
host: config.dict.smtpHost,
|
||||||
port: SMTP_PORT,
|
port: config.dict.smtpPort,
|
||||||
secure: false
|
secure: false
|
||||||
});
|
});
|
||||||
this.timer = setInterval(() => {
|
this.timer = setInterval(() => {
|
||||||
@ -27,8 +24,8 @@ class MissingEventProcessor extends Processor.AProcessor {
|
|||||||
log.info(`Checking ${key}, elapsed: ${elapsedTime / 1000}, avg. delay: ${value.avgDelay / 1000}`);
|
log.info(`Checking ${key}, elapsed: ${elapsedTime / 1000}, avg. delay: ${value.avgDelay / 1000}`);
|
||||||
if ((value.avgDelay != 0) && (elapsedTime > (value.avgDelay * 3))) {
|
if ((value.avgDelay != 0) && (elapsedTime > (value.avgDelay * 3))) {
|
||||||
let mail = {
|
let mail = {
|
||||||
from: SMTP_SENDER,
|
from: config.dict.smtpSender,
|
||||||
to: SMTP_RECEIVER,
|
to: config.dict.smtpReceiver,
|
||||||
subject: `Missing Event Detected for ${key}`,
|
subject: `Missing Event Detected for ${key}`,
|
||||||
text: `Missing Event Detected: ${key}, elapsed: ${elapsedTime / 1000}, avg. delay: ${value.avgDelay / 1000}`
|
text: `Missing Event Detected: ${key}, elapsed: ${elapsedTime / 1000}, avg. delay: ${value.avgDelay / 1000}`
|
||||||
};
|
};
|
||||||
|
18
src/config.ts
Normal file
18
src/config.ts
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
import * as fs from 'fs'
|
||||||
|
import * as cmdargs from 'command-line-args'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
const OPTION_DEFINITIONS = [
|
||||||
|
{ name: 'verbose', alias: 'v', type: Boolean },
|
||||||
|
{ name: 'config', alias: 'c', type: String, defaultValue: '~/mqttDispatcher.conf' }
|
||||||
|
];
|
||||||
|
|
||||||
|
|
||||||
|
export let dict
|
||||||
|
|
||||||
|
export function readConfig() {
|
||||||
|
let options = cmdargs(OPTION_DEFINITIONS)
|
||||||
|
dict = JSON.parse(fs.readFileSync(options.config, "utf8"))
|
||||||
|
}
|
||||||
|
|
21
src/main.ts
21
src/main.ts
@ -1,28 +1,21 @@
|
|||||||
import * as log from './log'
|
import * as log from './log'
|
||||||
import * as mqtt from './mqttdispatcher'
|
import * as mqtt from './mqttdispatcher'
|
||||||
import * as callchain from './callchain'
|
import * as callchain from './callchain'
|
||||||
import * as fs from 'fs'
|
import * as config from './config'
|
||||||
import * as cmdargs from 'command-line-args'
|
|
||||||
|
|
||||||
import * as EspThermToJson from './espthermtojson'
|
import * as EspThermToJson from './espthermtojson'
|
||||||
import * as MongoSave from './mongosave'
|
import * as MongoSave from './mongosave'
|
||||||
import * as MissingEventDetector from './missingeventdetector'
|
import * as MissingEventDetector from './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")
|
log.info("Dispatcher starting")
|
||||||
|
|
||||||
let dispatcher = new mqtt.MqttDispatcher(CONFIG.brokerUrl,
|
config.readConfig()
|
||||||
CONFIG.brokerUser, CONFIG.brokerPass, CONFIG.brokerCa)
|
|
||||||
|
let dispatcher = new mqtt.MqttDispatcher(config.dict.brokerUrl,
|
||||||
|
config.dict.brokerUser, config.dict.brokerPass, config.dict.brokerCa)
|
||||||
|
|
||||||
const ESP_THERM_TOPIC : string = 'IoT/espThermometer2/#'
|
const ESP_THERM_TOPIC : string = 'IoT/espThermometer2/#'
|
||||||
dispatcher.register(ESP_THERM_TOPIC, 'toJson', EspThermToJson.espThermToJson)
|
dispatcher.register(ESP_THERM_TOPIC, 'toJson', EspThermToJson.espThermToJson)
|
||||||
@ -31,8 +24,8 @@ let missingeventdetector : MissingEventDetector.MissingEventDetector =
|
|||||||
new MissingEventDetector.MissingEventDetector()
|
new MissingEventDetector.MissingEventDetector()
|
||||||
dispatcher.register(ESP_THERM_TOPIC, '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.register(ESP_THERM_TOPIC, 'MongoSave', mongo);
|
||||||
|
|
||||||
|
|
||||||
dispatcher.exec()
|
dispatcher.exec()
|
||||||
|
@ -2,13 +2,10 @@ import * as nodemailer from 'nodemailer'
|
|||||||
import * as log from './log'
|
import * as log from './log'
|
||||||
import * as CallChain from './callchain'
|
import * as CallChain from './callchain'
|
||||||
import * as Processor from './processor'
|
import * as Processor from './processor'
|
||||||
|
import * as config from './config'
|
||||||
|
|
||||||
|
|
||||||
const CHECK_PERIOD : number = 60 // seconds
|
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 {
|
class ClientEntry {
|
||||||
@ -30,8 +27,8 @@ class MissingEventProcessor extends Processor.AProcessor {
|
|||||||
super("MissingEventProcessor")
|
super("MissingEventProcessor")
|
||||||
|
|
||||||
this.smtp = nodemailer.createTransport({
|
this.smtp = nodemailer.createTransport({
|
||||||
host: SMTP_HOST,
|
host: config.dict.smtpHost,
|
||||||
port: SMTP_PORT,
|
port: config.dict.smtpPort,
|
||||||
secure: false
|
secure: false
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -43,8 +40,8 @@ class MissingEventProcessor extends Processor.AProcessor {
|
|||||||
|
|
||||||
if ((value.avgDelay != 0) && (elapsedTime > (value.avgDelay * 3))) {
|
if ((value.avgDelay != 0) && (elapsedTime > (value.avgDelay * 3))) {
|
||||||
let mail : nodemailer.SendMailOptions = {
|
let mail : nodemailer.SendMailOptions = {
|
||||||
from: SMTP_SENDER,
|
from: config.dict.smtpSender,
|
||||||
to: SMTP_RECEIVER,
|
to: config.dict.smtpReceiver,
|
||||||
subject: `Missing Event Detected for ${key}`,
|
subject: `Missing Event Detected for ${key}`,
|
||||||
text: `Missing Event Detected: ${key}, elapsed: ${elapsedTime / 1000}, avg. delay: ${value.avgDelay / 1000}`
|
text: `Missing Event Detected: ${key}, elapsed: ${elapsedTime / 1000}, avg. delay: ${value.avgDelay / 1000}`
|
||||||
};
|
};
|
||||||
|
Reference in New Issue
Block a user