class Alert
Attributes
contacts[RW]
level definition nil: no alert info: mail warning: summury and sms error: sms fatal: sms to boss
Public Class Methods
new(contacts, level={})
click to toggle source
# File lib/ymlex/argusyml.rb, line 10 def initialize contacts, level={} @contacts = contacts @default_level = { "oncall" => "", "manager" => "g_ecomop_maop_manager", "phone" => "", "rd" => "err", "op" => "warn", "qa" => nil }.merge(level) end
Public Instance Methods
get_alert(lvl={})
click to toggle source
# File lib/ymlex/argusyml.rb, line 20 def get_alert lvl={} level = @default_level.merge(lvl) if @contacts["op"].include? "g_ecomop_maop_all" oncall = "#z_ecomop_maop_oncall" elsif @contacts["op"].include? "g_ecom_udw_op" oncall = "#z_bdg_op_sdc" end #oncall = level["oncall"] manager = level["manager"] phone = level["phone"] mail = "" sms = "" hi = "" web = "" level.each do |role, lvl| if ["op","rd","qa"].include? role mail = "#{@contacts[role]};#{mail}" if lvl != nil if lvl =~ /fatal/ or (lvl =~ /(warn|err)/ and role != "op") sms = "#{@contacts[role]};#{sms}" end end end lvl = level["op"] mail = "#{mail}" if lvl != nil sms = "#{oncall};#{sms}" if lvl =~ /err/ or lvl =~ /fatal/ if lvl =~ /fatal/ remind_time = "900" elsif lvl =~ /err/ remind_time = "0" else remind_time = "0" end if lvl =~ /fatal/ merge_window = "0" rule_level = "4" elsif lvl =~ /err/ merge_window = "300" rule_level = "3" elsif lvl =~ /warn/ merge_window = "600" rule_level = "2" elsif lvl =~ /info/ merge_window = "600" rule_level = "1" else merge_window = "600" rule_level = "1" end web = "#{web};g_ecomop_maop_all;" if sms.include? "g_ecomop_maop_all" or sms.include? "#z_ecomop_maop_oncall" web = "#{web};g_ecom_udw_op;" if sms.include? "g_ecom_udw_op" or sms.include? "#z_bdg_op_sdc" sms.gsub!(/g_ecomop_maop_all/,'#z_ecomop_maop_oncall') sms.gsub!(/g_ecom_udw_op/,'#z_bdg_op_sdc') mail.gsub!(/g_ecomop_maop_all/,'ma-op') mail.gsub!(/g_ecom_udw_op/,'udw-op') mail_list = mail.split ";" mail_list_uniq = mail_list.uniq if mail_list_uniq.nil? #or mail_list_uniq.empty? mail = "" else mail_list_uniq.delete "" mail = mail_list_uniq.join ";" end sms_list = sms.split ";" sms_list_uniq = sms_list.uniq if sms_list_uniq.nil? #or sms_list_uniq.empty? sms = "" else sms_list_uniq.delete "" sms = sms_list_uniq.join ";" end hi_list = hi.split ";" hi_list_uniq = hi_list.uniq if hi_list_uniq.nil? #or hi_list_uniq.empty? hi = "" else hi_list_uniq.delete "" hi = hi_list_uniq.join ";" end web_list = web.split ";" web_list_uniq = web_list.uniq if web_list_uniq.nil? #or web_list_uniq.empty? web = "" else web_list_uniq.delete "" web = web_list_uniq.join ";" end alt = { "max_alert_times" => level["max_alert_times"] || "1", "alert_threshold_percent" => level["alert_threshold_percent"] || "0", "sms_threshold_percent" => level["sms_threshold_percent"] || "0", "remind_interval_second" => level["remind_interval_second"] || remind_time, "other" => { "merge_window" => merge_window, "level" => rule_level, "lvl" => lvl, }, "mail" => mail, "sms" => sms, "hi" => hi, "web" => web, } if lvl =~ /fatal/ and manager != "" alt["level1_upgrade_interval"] = "900" #alt["level1_upgrade_sms"] = "#{manager};#{@contacts['op']}".gsub(/g_ecomop_maop_all/,'#z_ecomop_maop_oncall') alt["level1_upgrade_sms"] = "#{manager};" alt["level1_upgrade_phone"] = "#{phone}" end alt end
get_hi(lvl=nil)
click to toggle source
# File lib/ymlex/argusyml.rb, line 150 def get_hi lvl=nil alert_info = get_alert lvl alert_info["hi"] end
get_mail(lvl=nil)
click to toggle source
# File lib/ymlex/argusyml.rb, line 140 def get_mail lvl=nil alert_info = get_alert lvl alert_info["mail"] end
get_sms(lvl=nil)
click to toggle source
# File lib/ymlex/argusyml.rb, line 145 def get_sms lvl=nil alert_info = get_alert lvl alert_info["sms"] end