config
This commit is contained in:
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 mqtt from './mqttdispatcher'
|
||||
import * as callchain from './callchain'
|
||||
import * as fs from 'fs'
|
||||
import * as cmdargs from 'command-line-args'
|
||||
import * as config from './config'
|
||||
|
||||
import * as EspThermToJson from './espthermtojson'
|
||||
import * as MongoSave from './mongosave'
|
||||
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")
|
||||
|
||||
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 : string = 'IoT/espThermometer2/#'
|
||||
dispatcher.register(ESP_THERM_TOPIC, 'toJson', EspThermToJson.espThermToJson)
|
||||
@ -31,8 +24,8 @@ let missingeventdetector : MissingEventDetector.MissingEventDetector =
|
||||
new MissingEventDetector.MissingEventDetector()
|
||||
dispatcher.register(ESP_THERM_TOPIC, 'MissingEventDetector', missingeventdetector)
|
||||
|
||||
let mongo : MongoSave.MongoSave = new MongoSave.MongoSave(CONFIG.mongoDbUrl)
|
||||
dispatcher.register(ESP_THERM_TOPIC, 'MongoSave', mongo);
|
||||
// let mongo : MongoSave.MongoSave = new MongoSave.MongoSave(config.dict.mongoDbUrl)
|
||||
// dispatcher.register(ESP_THERM_TOPIC, 'MongoSave', mongo);
|
||||
|
||||
|
||||
dispatcher.exec()
|
||||
|
@ -2,13 +2,10 @@ import * as nodemailer from 'nodemailer'
|
||||
import * as log from './log'
|
||||
import * as CallChain from './callchain'
|
||||
import * as Processor from './processor'
|
||||
import * as config from './config'
|
||||
|
||||
|
||||
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 {
|
||||
@ -30,8 +27,8 @@ class MissingEventProcessor extends Processor.AProcessor {
|
||||
super("MissingEventProcessor")
|
||||
|
||||
this.smtp = nodemailer.createTransport({
|
||||
host: SMTP_HOST,
|
||||
port: SMTP_PORT,
|
||||
host: config.dict.smtpHost,
|
||||
port: config.dict.smtpPort,
|
||||
secure: false
|
||||
});
|
||||
|
||||
@ -43,8 +40,8 @@ class MissingEventProcessor extends Processor.AProcessor {
|
||||
|
||||
if ((value.avgDelay != 0) && (elapsedTime > (value.avgDelay * 3))) {
|
||||
let mail : nodemailer.SendMailOptions = {
|
||||
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