summaryrefslogtreecommitdiff
path: root/lib/oxidized/output/http.rb
diff options
context:
space:
mode:
authorNeil Lathwood <neil@lathwood.co.uk>2018-04-27 11:38:06 +0100
committerNeil Lathwood <neil@lathwood.co.uk>2018-04-27 11:38:06 +0100
commitb1194745929043b578c409f794ecb433aa515fa9 (patch)
tree133e7103073b707aaca855eb3df4d5025bebae06 /lib/oxidized/output/http.rb
parent9156243b9debfc0bc2b05dfe98a910ce5153bf49 (diff)
parent34fd5369feee94ab45c5a81d7769b1df717e4c8c (diff)
Rebased and fixed conflicts
Diffstat (limited to 'lib/oxidized/output/http.rb')
-rw-r--r--lib/oxidized/output/http.rb50
1 files changed, 23 insertions, 27 deletions
diff --git a/lib/oxidized/output/http.rb b/lib/oxidized/output/http.rb
index 13ba300..0467261 100644
--- a/lib/oxidized/output/http.rb
+++ b/lib/oxidized/output/http.rb
@@ -7,9 +7,9 @@ module Oxidized
def setup
if @cfg.empty?
- CFGS.user.output.http.user = 'Oxidized'
+ CFGS.user.output.http.user = 'Oxidized'
CFGS.user.output.http.pasword = 'secret'
- CFGS.user.output.http.url = 'http://localhost/web-api/oxidized'
+ CFGS.user.output.http.url = 'http://localhost/web-api/oxidized'
CFGS.save :user
raise NoConfig, 'no output http config, edit ~/.config/oxidized/config'
end
@@ -17,42 +17,38 @@ module Oxidized
require "net/http"
require "uri"
require "json"
- def store node, outputs, opt={}
+ def store node, outputs, opt = {}
@commitref = nil
json = JSON.pretty_generate(
- {
- 'msg' => opt[:msg],
- 'user' => opt[:user],
- 'email' => opt[:email],
- 'group' => opt[:group],
- 'node' => node,
- 'config' => outputs.to_cfg,
- # actually we need to also iterate outputs, for other types like in gitlab. But most people don't use 'type' functionality.
- }
+ {
+ 'msg' => opt[:msg],
+ 'user' => opt[:user],
+ 'email' => opt[:email],
+ 'group' => opt[:group],
+ 'node' => node,
+ 'config' => outputs.to_cfg,
+ # actually we need to also iterate outputs, for other types like in gitlab. But most people don't use 'type' functionality.
+ }
)
uri = URI.parse @cfg.url
http = Net::HTTP.new uri.host, uri.port
- #http.use_ssl = true if uri.scheme = 'https'
- req = Net::HTTP::Post.new(uri.request_uri, initheader = { 'Content-Type' => 'application/json'})
+ # http.use_ssl = true if uri.scheme = 'https'
+ req = Net::HTTP::Post.new(uri.request_uri, initheader = { 'Content-Type' => 'application/json' })
req.basic_auth @cfg.user, @cfg.password
req.body = json
response = http.request req
case response.code.to_i
- when 200 || 201
- Oxidized.logger.info "Configuration http backup complete for #{node}"
- p [:success]
- when (400..499)
- Oxidized.logger.info "Configuration http backup for #{node} failed status: #{response.body}"
- p [:bad_request]
- when (500..599)
- p [:server_problems]
- Oxidized.logger.info "Configuration http backup for #{node} failed status: #{response.body}"
+ when 200 || 201
+ Oxidized.logger.info "Configuration http backup complete for #{node}"
+ p [:success]
+ when (400..499)
+ Oxidized.logger.info "Configuration http backup for #{node} failed status: #{response.body}"
+ p [:bad_request]
+ when (500..599)
+ p [:server_problems]
+ Oxidized.logger.info "Configuration http backup for #{node} failed status: #{response.body}"
end
-
end
-
end
end
-
-