Class: Interferon::Alert

Inherits:
Object
  • Object
show all
Defined in:
lib/interferon/alert.rb

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ Alert

Returns a new instance of Alert.



3
4
5
6
7
8
9
10
# File 'lib/interferon/alert.rb', line 3

def initialize(path)
  @path = path
  @filename = File.basename(path)

  @text = File.read(@path)

  @dsl = nil
end

Instance Method Details

#[](attr) ⇒ Object



37
38
39
40
41
# File 'lib/interferon/alert.rb', line 37

def [](attr)
  raise 'This alert has not yet been evaluated' unless @dsl

  @dsl.send(attr)
end

#change_name(name) ⇒ Object



25
26
27
28
29
# File 'lib/interferon/alert.rb', line 25

def change_name(name)
  raise 'This alert has not yet been evaluated' unless @dsl

  @dsl.name(name)
end

#evaluate(hostinfo) ⇒ Object



16
17
18
19
20
21
22
23
# File 'lib/interferon/alert.rb', line 16

def evaluate(hostinfo)
  dsl = AlertDSL.new(hostinfo)
  dsl.instance_eval(@text, @filename, 1)
  @dsl = dsl

  # return the alert and not the DSL object, which is private
  self
end

#silenceObject



31
32
33
34
35
# File 'lib/interferon/alert.rb', line 31

def silence
  raise 'This alert has not yet been evaluated' unless @dsl

  @dsl.silenced(true)
end

#to_sObject



12
13
14
# File 'lib/interferon/alert.rb', line 12

def to_s
  @filename
end