diff options
author | Saku Ytti <saku@ytti.fi> | 2018-05-30 19:30:50 +0300 |
---|---|---|
committer | Saku Ytti <saku@ytti.fi> | 2018-05-30 19:30:50 +0300 |
commit | c511a212c1388db35f0f42af2a33241986846e04 (patch) | |
tree | 833eff9264275822e8058d73b855c325127015ee /lib/oxidized/input | |
parent | 42bf10b7bce34ff577c469f6c2f659f3913cbf4a (diff) |
Add support for Cambium
Initial HTTP support
Diffstat (limited to 'lib/oxidized/input')
-rw-r--r-- | lib/oxidized/input/http.rb | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/lib/oxidized/input/http.rb b/lib/oxidized/input/http.rb new file mode 100644 index 0000000..c7767b3 --- /dev/null +++ b/lib/oxidized/input/http.rb @@ -0,0 +1,41 @@ +module Oxidized + require_relative "cli" + + begin + require "mechanize" + rescue LoadError + raise OxidizedError, "mechanize not found: sudo gem install mechanize" + end + + class HTTP < Input + include Input::CLI + + def connect node + @node = node + @m = Mechanize.new + @log = File.open(Oxidized::Config::Log + "/#{@node.ip}-http", "w") if Oxidized.config.input.debug? + + @node.model.cfg["http"].each { |cb| instance_exec(&cb) } + + url = URI::HTTP.build host: @node.ip, path: @main_page + @m_page = @m.get(url.to_s) + login + end + + def cmd cb + instance_exec(&cb) + end + + private + + def log str + @log.write(str) if @log + end + + def disconnect + ensure + @log.close if Oxidized.config.input.debug? + end + + end +end |