Class: SumoLogic::Client
- Inherits:
-
Object
- Object
- SumoLogic::Client
- Defined in:
- lib/sumologic.rb
Instance Attribute Summary collapse
-
#http ⇒ Object
Returns the value of attribute http.
Instance Method Summary collapse
- #collector(collector_id) ⇒ Object
- #collectors(limit = nil, offset = nil) ⇒ Object
- #create_content(path, data) ⇒ Object
- #dashboard(dashboard_id) ⇒ Object
- #dashboard_data(dashboard_id) ⇒ Object
- #dashboards(monitors = false) ⇒ Object
- #delete_collector(collector) ⇒ Object
- #delete_content(path) ⇒ Object
- #delete_source(collector_id, source) ⇒ Object
- #get_content(path) ⇒ Object
-
#initialize(access_id = nil, access_key = nil, endpoint = SumoLogic::URL) ⇒ Client
constructor
A new instance of Client.
- #params_limit_offset(limit, offset) ⇒ Object
- #post(path, data = {}) ⇒ Object
- #search(query, from_time = nil, to_time = nil, time_zone = 'UTC') ⇒ Object
- #search_job(query, from_time = nil, to_time = nil, time_zone = 'UTC') ⇒ Object
- #search_job_messages(search_job, limit = nil, offset = 0) ⇒ Object
- #search_job_records(search_job, limit = nil, offset = 0) ⇒ Object
- #search_job_status(search_job = {}) ⇒ Object
- #source(collector_id, source_id) ⇒ Object
- #sources(collector_id, limit = nil, offset = nil) ⇒ Object
- #update_collector(collector, etag) ⇒ Object
- #update_source(collector_id, source, etag) ⇒ Object
Constructor Details
#initialize(access_id = nil, access_key = nil, endpoint = SumoLogic::URL) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/sumologic.rb', line 13 def initialize(access_id=nil, access_key=nil, endpoint=SumoLogic::URL) @endpoint = endpoint headers = {'Content-Type' => 'application/json', 'Accept' => 'application/json'} @http = Faraday.new(url: @endpoint, headers: headers) do |conn| conn.basic_auth(access_id, access_key) conn.use FaradayMiddleware::FollowRedirects, limit: 5 conn.use :cookie_jar conn.request :json conn.response :json, content_type: 'application/json' conn.adapter Faraday.default_adapter end end |
Instance Attribute Details
#http ⇒ Object
Returns the value of attribute http.
11 12 13 |
# File 'lib/sumologic.rb', line 11 def http @http end |
Instance Method Details
#collector(collector_id) ⇒ Object
64 65 66 |
# File 'lib/sumologic.rb', line 64 def collector(collector_id) @http.get "collectors/#{collector_id}" end |
#collectors(limit = nil, offset = nil) ⇒ Object
60 61 62 |
# File 'lib/sumologic.rb', line 60 def collectors(limit=nil, offset=nil) @http.get 'collectors', params_limit_offset(limit, offset) end |
#create_content(path, data) ⇒ Object
100 101 102 |
# File 'lib/sumologic.rb', line 100 def create_content(path, data) @http.post "content/#{path}", data end |
#dashboard(dashboard_id) ⇒ Object
117 118 119 120 |
# File 'lib/sumologic.rb', line 117 def dashboard(dashboard_id) r = @http.get "dashboards/#{dashboard_id}" return r.body.key?('dashboard') ? r.body['dashboard'] : nil end |
#dashboard_data(dashboard_id) ⇒ Object
122 123 124 125 |
# File 'lib/sumologic.rb', line 122 def dashboard_data(dashboard_id) r = @http.get "dashboards/#{dashboard_id}/data" return r.body.key?('dashboardMonitorDatas') ? r.body['dashboardMonitorDatas'] : nil end |
#dashboards(monitors = false) ⇒ Object
112 113 114 115 |
# File 'lib/sumologic.rb', line 112 def dashboards(monitors=false) r = @http.get 'dashboards', {dashboards: monitors} return r.body.key?('dashboards') ? r.body['dashboards'] : nil end |
#delete_collector(collector) ⇒ Object
76 77 78 |
# File 'lib/sumologic.rb', line 76 def delete_collector(collector) @http.delete "collectors/#{collector['id']}" end |
#delete_content(path) ⇒ Object
108 109 110 |
# File 'lib/sumologic.rb', line 108 def delete_content(path) @http.delete "content/#{path}" end |
#delete_source(collector_id, source) ⇒ Object
96 97 98 |
# File 'lib/sumologic.rb', line 96 def delete_source(collector_id, source) @http.delete "collectors/#{collector_id}/sources/#{source['source']['id']}" end |
#get_content(path) ⇒ Object
104 105 106 |
# File 'lib/sumologic.rb', line 104 def get_content(path) @http.get "content/#{path}" end |
#params_limit_offset(limit, offset) ⇒ Object
127 128 129 130 131 132 |
# File 'lib/sumologic.rb', line 127 def params_limit_offset(limit, offset) params = {} params[:limit] = limit unless limit.nil? params[:offset] = offset unless offset.nil? params end |
#post(path, data = {}) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/sumologic.rb', line 26 def post(path, data={}) @http.post do |req| req.url path req.body = data unless data.empty? end end |
#search(query, from_time = nil, to_time = nil, time_zone = 'UTC') ⇒ Object
33 34 35 36 37 38 |
# File 'lib/sumologic.rb', line 33 def search(query, from_time=nil, to_time=nil, time_zone='UTC') @http.get do |req| req.url 'logs/search' req.params = {q: query, from: from_time, to: to_time, tz: time_zone} end end |
#search_job(query, from_time = nil, to_time = nil, time_zone = 'UTC') ⇒ Object
40 41 42 43 44 45 46 |
# File 'lib/sumologic.rb', line 40 def search_job(query, from_time=nil, to_time=nil, time_zone='UTC') params = {query: query, from: from_time, to: to_time, timeZone: time_zone} @http.post do |req| req.url 'search/jobs' req.body = MultiJson.encode(params) end end |
#search_job_messages(search_job, limit = nil, offset = 0) ⇒ Object
52 53 54 |
# File 'lib/sumologic.rb', line 52 def (search_job, limit=nil, offset=0) @http.get "search/jobs/#{search_job['id']}/messages", params_limit_offset(limit, offset) end |
#search_job_records(search_job, limit = nil, offset = 0) ⇒ Object
56 57 58 |
# File 'lib/sumologic.rb', line 56 def search_job_records(search_job, limit=nil, offset=0) @http.get "search/jobs/#{search_job['id']}/records", params_limit_offset(limit, offset) end |
#search_job_status(search_job = {}) ⇒ Object
48 49 50 |
# File 'lib/sumologic.rb', line 48 def search_job_status(search_job={}) @http.get "search/jobs/#{search_job['id']}" end |
#source(collector_id, source_id) ⇒ Object
84 85 86 |
# File 'lib/sumologic.rb', line 84 def source(collector_id, source_id) @http.get "collectors/#{collector_id}/sources/#{source_id}" end |
#sources(collector_id, limit = nil, offset = nil) ⇒ Object
80 81 82 |
# File 'lib/sumologic.rb', line 80 def sources(collector_id, limit=nil, offset=nil) @http.get "collectors/#{collector_id}/sources", params_limit_offset(limit, offset) end |
#update_collector(collector, etag) ⇒ Object
68 69 70 71 72 73 74 |
# File 'lib/sumologic.rb', line 68 def update_collector(collector, etag) @http.put do |req| req.url "collectors/#{collector['collector']['id']}" req.headers['If-Match'] = etag req.body = collector end end |
#update_source(collector_id, source, etag) ⇒ Object
88 89 90 91 92 93 94 |
# File 'lib/sumologic.rb', line 88 def update_source(collector_id, source, etag) @http.put do |req| req.url "collectors/#{collector_id}/sources/#{source['source']['id']}" req.headers['If-Match'] = etag req.body = source end end |