Class: Alert

Inherits:
Object
  • Object
show all
Defined in:
lib/ymlex/argusyml.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contacts, level = {}) ⇒ Alert

Returns a new instance of Alert.



10
11
12
13
14
15
16
17
# File 'lib/ymlex/argusyml.rb', line 10

def initialize contacts, level={}
  @contacts = contacts
  @default_level = { "oncall" => "#z_ecomop_maop_oncall", 
                     "manager" => "g_ecomop_maop_manager",
                     "rd" => "err", 
                     "op" => "warn", 
                     "qa" => nil }.merge(level)
end

Instance Attribute Details

#contactsObject (readonly)

level definition nil: no alert info: mail warning: summury and sms error: sms fatal: sms to boss



9
10
11
# File 'lib/ymlex/argusyml.rb', line 9

def contacts
  @contacts
end

Instance Method Details

#get_alert(lvl = {}) ⇒ Object



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# File 'lib/ymlex/argusyml.rb', line 19

def get_alert lvl={}
  level = @default_level.merge(lvl)
  oncall = level["oncall"]
  manager = level["manager"]

  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 = "g_ecomop_maop_all;g_ecomop_maop_manager;" if sms.include? "g_ecomop_maop_all" or sms.include? "#z_ecomop_maop_oncall" or (lvl =~ /fatal/ and (manager.include? "#z_ecomop_maop_oncall" or manager.include? "g_ecomop_maop_manager"))
  sms.gsub!(/g_ecomop_maop_all/,'#z_ecomop_maop_oncall')
  mail.gsub!(/g_ecomop_maop_all/,'ma-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

  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};"
  end
  alt
end

#get_hi(lvl = nil) ⇒ Object



129
130
131
132
# File 'lib/ymlex/argusyml.rb', line 129

def get_hi lvl=nil
  alert_info = get_alert lvl
  alert_info["hi"]
end

#get_mail(lvl = nil) ⇒ Object



119
120
121
122
# File 'lib/ymlex/argusyml.rb', line 119

def get_mail lvl=nil
  alert_info = get_alert lvl
  alert_info["mail"]
end

#get_sms(lvl = nil) ⇒ Object



124
125
126
127
# File 'lib/ymlex/argusyml.rb', line 124

def get_sms lvl=nil
  alert_info = get_alert lvl
  alert_info["sms"]
end