Class: Flydata::Helper::Action::SendLogs

Inherits:
BaseAction
  • Object
show all
Includes:
Util::FileUtil
Defined in:
lib/flydata/helper/action/send_logs.rb

Constant Summary collapse

DEFAULT_NUM_OF_LINES =
100

Instance Attribute Summary

Attributes inherited from BaseAction

#config

Instance Method Summary collapse

Methods included from Util::FileUtil

#read_line, #tail, #write_line

Methods inherited from BaseAction

#config_hash

Constructor Details

#initialize(config) ⇒ SendLogs

Returns a new instance of SendLogs.



13
14
15
16
# File 'lib/flydata/helper/action/send_logs.rb', line 13

def initialize(config)
  super
  @api_client = ApiClient.instance
end

Instance Method Details

#execute(opts = {}) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/flydata/helper/action/send_logs.rb', line 18

def execute(opts = {})
  num_of_lines = DEFAULT_NUM_OF_LINES
  action_id = opts[:id]
  begin
    num_of_lines = opts[:config_hash][:num_of_lines].to_i
  rescue
    # Use default number of lines if config is nil, mal-formed etc
  end
  log_info("Sending logs - num_of_lines:#{num_of_lines}")
  tailed_lines = tail(FLYDATA_LOG, num_of_lines)
  @api_client.agent.send_logs(action_id, tailed_lines)
end