Class: Agents::WriteFileAgent

Inherits:
Agent
  • Object
show all
Includes:
FormConfigurable
Defined in:
lib/huginn_write_file_agent/write_file_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



92
93
94
# File 'lib/huginn_write_file_agent/write_file_agent.rb', line 92

def check
  write_file
end

#default_optionsObject



38
39
40
41
42
43
44
45
46
47
# File 'lib/huginn_write_file_agent/write_file_agent.rb', line 38

def default_options
  {
    'path' => '/tmp/huginn_output.txt',
    'content' => 'Default content',
    'mode' => '0644',
    'owner' => 'huginn:huginn',
    'expected_receive_period_in_days' => '10',
    'debug' => 'false'
  }
end

#receive(incoming_events) ⇒ Object



83
84
85
86
87
88
89
90
# File 'lib/huginn_write_file_agent/write_file_agent.rb', line 83

def receive(incoming_events)
  incoming_events.each do |event|
    interpolate_with(event) do
      log event
      write_file
    end
  end
end

#validate_optionsObject



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/huginn_write_file_agent/write_file_agent.rb', line 55

def validate_options
#      errors.add(:base, "type has invalid value: should be 'generate'") if interpolated['type'].present? && !%w(generate).include?(interpolated['type'])

  unless options['path'].present?
    errors.add(:base, "path is a required field")
  end

  unless options['mode'].present?
    errors.add(:base, "mode is a required field")
  end

  unless options['owner'].present?
    errors.add(:base, "owner is a required field")
  end

  if options.has_key?('debug') && boolify(options['debug']).nil?
    errors.add(:base, "if provided, debug must be true or false")
  end

  unless options['expected_receive_period_in_days'].present? && options['expected_receive_period_in_days'].to_i > 0
    errors.add(:base, "Please provide 'expected_receive_period_in_days' to indicate how many days can pass before this Agent is considered to be not working")
  end
end

#working?Boolean

Returns:

  • (Boolean)


79
80
81
# File 'lib/huginn_write_file_agent/write_file_agent.rb', line 79

def working?
  event_created_within?(options['expected_receive_period_in_days']) && !recent_error_logs?
end