Class: Oxidized::Output::Http
- Inherits:
-
Oxidized::Output
- Object
- Oxidized::Output
- Oxidized::Output::Http
- Defined in:
- lib/oxidized/output/http.rb
Instance Attribute Summary collapse
-
#commitref ⇒ Object
readonly
Returns the value of attribute commitref.
Instance Method Summary collapse
-
#initialize ⇒ Http
constructor
A new instance of Http.
- #setup ⇒ Object
- #store(node, outputs, opt = {}) ⇒ Object
Methods included from Oxidized::Output
Constructor Details
Instance Attribute Details
#commitref ⇒ Object (readonly)
Returns the value of attribute commitref.
4 5 6 |
# File 'lib/oxidized/output/http.rb', line 4 def commitref @commitref end |
Instance Method Details
#setup ⇒ Object
11 12 13 14 15 16 17 18 19 |
# File 'lib/oxidized/output/http.rb', line 11 def setup return unless @cfg.empty? Oxidized.asetus.user.output.http.user = 'Oxidized' Oxidized.asetus.user.output.http.pasword = 'secret' Oxidized.asetus.user.output.http.url = 'http://localhost/web-api/oxidized' Oxidized.asetus.save :user raise NoConfig, "no output http config, edit #{Oxidized::Config.configfile}" end |
#store(node, outputs, opt = {}) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/oxidized/output/http.rb', line 25 def store(node, outputs, opt = {}) @commitref = nil uri = URI.parse @cfg.url http = Net::HTTP.new uri.host, uri.port # if uri scheme is https, enable ssl and set verify mode if uri.scheme == "https" http.use_ssl = true http.verify_mode = @cfg.ssl_verify? ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE end headers = @cfg.headers? ? @cfg.headers : {} req = Net::HTTP::Post.new(uri.request_uri, headers.merge('Content-Type' => 'application/json')) req.basic_auth(@cfg.user, @cfg.password) if @cfg.user? && @cfg.password? req.body = generate_json(node, outputs, opt) response = http.request req case response.code.to_i when 200 || 201 logger.info "Configuration http backup complete for #{node}" p [:success] when (400..499) logger.info "Configuration http backup for #{node} failed status: #{response.body}" p [:bad_request] when (500..599) p [:server_problems] logger.info "Configuration http backup for #{node} failed status: #{response.body}" end end |