lib/ring/sqa/alarm.rb in ring-sqa-0.0.23 vs lib/ring/sqa/alarm.rb in ring-sqa-0.1.0

- old
+ new

@@ -1,7 +1,8 @@ require_relative 'alarm/email' require_relative 'alarm/udp2irc' +require_relative 'alarm/exec' require_relative 'alarm/cfg' require_relative 'alarm/message' require_relative 'mtr' require_relative 'paste' @@ -12,31 +13,32 @@ def set alarm_buffer if @alarm == false @alarm = true msg = compose_message alarm_buffer Log.info msg[:short] - @methods.each { |alarm_method| alarm_method.send msg } + @methods.each { |alarm_method| alarm_send alarm_method, 'raise', msg, alarm_buffer } end end def clear if @alarm == true @alarm = false - msg = { short: "#{@hostname}: clearing alarm" } + msg = { short: "#{@hostname}: clearing #{@afi} alarm" } msg[:long] = msg[:short] Log.info msg[:short] - @methods.each { |alarm_method| alarm_method.send msg } + @methods.each { |alarm_method| alarm_send alarm_method, 'clear', msg, nil } end end private def initialize nodes @nodes = nodes @methods = [] @methods << Email.new if CFG.email.to? - @methods << UDP2IRC.new if CFG.irc.password? + @methods << UDP2IRC.new if Array === CFG.irc or CFG.irc.password? + @methods << Exec.new if CFG.exec.command? @hostname = Ring::SQA::CFG.host.name @afi = Ring::SQA::CFG.afi @alarm = false end @@ -66,9 +68,17 @@ time -= 1 end msg[:long] = message nodes_list, mtr_list, buffer_list, exceeding_nodes.size msg + end + + def alarm_send alarm_method, status, msg, alarm_buffer=nil + alarm_method.send(short: msg[:short], + long: msg[:long], + status: status, + alarm_buffer: alarm_buffer, + nodes: @nodes) end end end