-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
app.rb
executable file
·43 lines (34 loc) · 1.25 KB
/
app.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env ruby
require 'bundler/setup'
Bundler.require
$LOAD_PATH.unshift(File.expand_path('./lib', __dir__))
require 'dotenv/load'
require 'loop'
require 'config'
require 'stdout_logger'
logger = StdoutLogger.new
logger.info 'MQTT collector for SOLECTRUS, ' \
"Version #{ENV.fetch('VERSION', '<unknown>')}, " \
"built at #{ENV.fetch('BUILDTIME', '<unknown>')}"
logger.info 'https://github.com/solectrus/mqtt-collector'
logger.info 'Copyright (c) 2023-2024 Georg Ledermann and contributors, released under the MIT License'
logger.info "\n"
config = Config.new(ENV, logger:)
logger.info "Using Ruby #{RUBY_VERSION} on platform #{RUBY_PLATFORM}"
logger.info "Subscribing from MQTT broker at #{config.mqtt_url}"
logger.info "Pushing to InfluxDB at #{config.influx_url}, " \
"bucket #{config.influx_bucket}"
logger.info "\n"
mapper = Mapper.new(config:)
if mapper.topics.empty?
logger.error 'No mappings defined - exiting.'
exit 1
else
logger.info "Subscribing to #{mapper.topics.length} topics:"
max_length = mapper.topics.map(&:length).max
mapper.topics.each do |topic|
logger.info "- #{topic.ljust(max_length, ' ')} => #{mapper.formatted_mapping(topic)}"
end
logger.info "\n"
end
Loop.new(config:).start