Class: Logtastic::ECS
- Inherits:
-
Object
- Object
- Logtastic::ECS
- Defined in:
- lib/logtastic/ecs.rb
Instance Method Summary collapse
- #count(**args) ⇒ Object
-
#initialize(index: nil, template: nil, ilm: nil, version: "1.5", output: :default) ⇒ ECS
constructor
A new instance of ECS.
- #query_index ⇒ Object
- #search(**args) ⇒ Object
- #write(event) ⇒ Object
- #write_now(event) ⇒ Object
Constructor Details
#initialize(index: nil, template: nil, ilm: nil, version: "1.5", output: :default) ⇒ ECS
Returns a new instance of ECS.
7 8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/logtastic/ecs.rb', line 7 def initialize(index: nil, template: nil, ilm: nil, version: "1.5", output: :default) @index = index @output = output @elasticsearch = Logtastic.client(@output) @setup = Logtastic::Setup.new( @elasticsearch, template: { json: { path: File.new(template_path(version)) } }.merge(template || {}), ilm: ilm ) @setup.perform! end |
Instance Method Details
#count(**args) ⇒ Object
32 33 34 |
# File 'lib/logtastic/ecs.rb', line 32 def count(**args) @elasticsearch.count({ index: query_index }.merge(**args)) end |
#query_index ⇒ Object
36 37 38 39 40 41 42 |
# File 'lib/logtastic/ecs.rb', line 36 def query_index if @setup.ilm_enabled? "#{@setup.rollover_alias}-*" else @setup.template_pattern end end |
#search(**args) ⇒ Object
28 29 30 |
# File 'lib/logtastic/ecs.rb', line 28 def search(**args) @elasticsearch.search({ index: query_index }.merge(**args)) end |
#write(event) ⇒ Object
20 21 22 |
# File 'lib/logtastic/ecs.rb', line 20 def write(event) Logtastic.write(@output, index: write_index(event), body: event) end |
#write_now(event) ⇒ Object
24 25 26 |
# File 'lib/logtastic/ecs.rb', line 24 def write_now(event) @elasticsearch.index(index: write_index(event), body: event) end |