Class: Agents::SignalspamAgent

Inherits:
Agent
  • Object
show all
Includes:
FormConfigurable
Defined in:
lib/huginn_signalspam_agent/signalspam_agent.rb

Instance Method Summary collapse

Instance Method Details

#checkObject



83
84
85
# File 'lib/huginn_signalspam_agent/signalspam_agent.rb', line 83

def check
  report
end

#default_optionsObject



33
34
35
36
37
38
39
40
41
# File 'lib/huginn_signalspam_agent/signalspam_agent.rb', line 33

def default_options
  {
    'username' => '',
    'password' => '',
    'raw_email' => '',
    'debug' => 'false',
    'expected_receive_period_in_days' => '2',
  }
end

#receive(incoming_events) ⇒ Object



74
75
76
77
78
79
80
81
# File 'lib/huginn_signalspam_agent/signalspam_agent.rb', line 74

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

#validate_optionsObject



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/huginn_signalspam_agent/signalspam_agent.rb', line 48

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

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

  unless options['raw_email'].present?
    errors.add(:base, "raw_email 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)


70
71
72
# File 'lib/huginn_signalspam_agent/signalspam_agent.rb', line 70

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