Class: Interferon::AlertDSL

Inherits:
Object
  • Object
show all
Includes:
DSLMixin
Defined in:
lib/interferon/alert_dsl.rb

Instance Method Summary collapse

Methods included from DSLMixin

#[], #initialize, #method_missing

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Interferon::DSLMixin

Instance Method Details

#applies(v = nil, &block) ⇒ Object



48
49
50
# File 'lib/interferon/alert_dsl.rb', line 48

def applies(v = nil, &block)
  get_or_set(:@applies, v, block, false)
end

#evaluation_delay(v = nil, &block) ⇒ Object



94
95
96
# File 'lib/interferon/alert_dsl.rb', line 94

def evaluation_delay(v = nil, &block)
  get_or_set(:@evaluation_delay, v, block, nil)
end

#is_work_hour?(args = {}) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
67
68
69
70
71
# File 'lib/interferon/alert_dsl.rb', line 64

def is_work_hour?(args = {})
  # Args can contain
  # :hours => range of work hours (0 to 23h), for example (9..16)
  # :days => range of week days (0 = sunday), for example (1..5) (Monday to Friday)
  # :timezone => example 'America/Los_Angeles'
  # 9 to 5 Monday to Friday in PST is the default
  WorkHoursHelper.is_work_hour?(Time.now.utc, args)
end

#message(v = nil, &block) ⇒ Object



40
41
42
# File 'lib/interferon/alert_dsl.rb', line 40

def message(v = nil, &block)
  get_or_set(:@message, v, block, '')
end

#metric(_v = nil) ⇒ Object



106
107
108
# File 'lib/interferon/alert_dsl.rb', line 106

def metric(_v = nil)
  @metric ||= MetricDSL.new(@hostinfo)
end

#monitor_type(v = nil, &block) ⇒ Object



44
45
46
# File 'lib/interferon/alert_dsl.rb', line 44

def monitor_type(v = nil, &block)
  get_or_set(:@monitor_type, v, block, 'metric alert')
end

#name(v = nil, &block) ⇒ Object



36
37
38
# File 'lib/interferon/alert_dsl.rb', line 36

def name(v = nil, &block)
  get_or_set(:@name, v, block, '', &:strip)
end

#no_data_timeframe(v = nil, &block) ⇒ Object



77
78
79
# File 'lib/interferon/alert_dsl.rb', line 77

def no_data_timeframe(v = nil, &block)
  get_or_set(:@no_data_timeframe, v, block, nil)
end

#notify(_v = nil) ⇒ Object



102
103
104
# File 'lib/interferon/alert_dsl.rb', line 102

def notify(_v = nil)
  @notify ||= NotifyDSL.new(@hostinfo)
end

#notify_no_data(v = nil, &block) ⇒ Object



73
74
75
# File 'lib/interferon/alert_dsl.rb', line 73

def notify_no_data(v = nil, &block)
  get_or_set(:@notify_no_data, v, block, false)
end

#require_full_window(v = nil, &block) ⇒ Object



98
99
100
# File 'lib/interferon/alert_dsl.rb', line 98

def require_full_window(v = nil, &block)
  get_or_set(:@require_full_window, v, block, nil)
end

#silenced(v = nil, &block) ⇒ Object



52
53
54
55
56
57
58
59
60
61
62
# File 'lib/interferon/alert_dsl.rb', line 52

def silenced(v = nil, &block)
  get_or_set(:@silenced, v, block, {}) do |val|
    if val.is_a? Hash
      val
    elsif val == true
      { '*' => nil }
    else
      {}
    end
  end
end

#thresholds(v = nil, &block) ⇒ Object



90
91
92
# File 'lib/interferon/alert_dsl.rb', line 90

def thresholds(v = nil, &block)
  get_or_set(:@thresholds, v, block, nil)
end

#timeout(v = nil, &block) ⇒ Object



81
82
83
# File 'lib/interferon/alert_dsl.rb', line 81

def timeout(v = nil, &block)
  get_or_set(:@timeout, v, block, nil)
end

#timeout_hObject



85
86
87
88
# File 'lib/interferon/alert_dsl.rb', line 85

def timeout_h
  # timeout is in seconds, but set it to 1 hour at least
  timeout ? [1, timeout.to_i / 3600].max : nil
end