Module: Gzr::Alert

Instance Method Summary collapse

Instance Method Details

#alert_notificationsObject



137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
# File 'lib/gzr/modules/alert.rb', line 137

def alert_notifications()
  data = []
  req = {}
  begin
    req[:limit] = 64
    loop do
      page = @sdk.alert_notifications(req).collect { |a| a.to_attrs }
      data+=page
      break unless page.length == req[:limit]
      req[:offset] = (req[:offset] || 0) + req[:limit]
    end
  rescue LookerSDK::NotFound => e
    # do nothing
  rescue LookerSDK::Error => e
    say_error "Error querying alert_notifications()"
    say_error e
    raise
  end
  data
end

#create_alert(req) ⇒ Object



172
173
174
175
176
177
178
179
180
# File 'lib/gzr/modules/alert.rb', line 172

def create_alert(req)
  begin
    @sdk.create_alert(req).to_attrs
  rescue LookerSDK::Error => e
    say_error "Error calling create_alert(#{JSON.pretty_generate(req)})"
    say_error e
    raise
  end
end

#delete_alert(alert_id) ⇒ Object



123
124
125
126
127
128
129
130
131
132
133
134
135
# File 'lib/gzr/modules/alert.rb', line 123

def delete_alert(alert_id)
  begin
    @sdk.delete_alert(alert_id)
  rescue LookerSDK::NotFound => e
    say_error "Alert #{alert_id} not found"
    say_error e
    raise
  rescue LookerSDK::Error => e
    say_error "Error calling delete_alert(#{alert_id})"
    say_error e
    raise
  end
end

#follow_alert(alert_id) ⇒ Object



75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/gzr/modules/alert.rb', line 75

def follow_alert(alert_id)
  begin
    @sdk.follow_alert(alert_id)
  rescue LookerSDK::NotFound => e
    say_error "Alert #{alert_id} not found"
    say_error e
    raise
  rescue LookerSDK::Error => e
    say_error "Error following alert(#{alert_id})"
    say_error e
    raise
  end
end

#get_alert(alert_id) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/gzr/modules/alert.rb', line 26

def get_alert(alert_id)
  data = nil
  begin
    data = @sdk.get_alert(alert_id).to_attrs
  rescue LookerSDK::NotFound => e
    # do nothing
  rescue LookerSDK::Error => e
    say_error "Error querying get_alert(#{alert_id})"
    say_error e
    raise
  end
  if data and data[:owner_id]
    owner = get_user_by_id(data[:owner_id])
    data[:owner] = owner.select do |k,v|
      [:email,:last_name,:first_name].include?(k) && !(v.nil? || v.empty?)
    end if owner
  end
  data
end

#read_alert_notification(notification_id) ⇒ Object



158
159
160
161
162
163
164
165
166
167
168
169
170
# File 'lib/gzr/modules/alert.rb', line 158

def read_alert_notification(notification_id)
  begin
    @sdk.read_alert_notification(notification_id).to_attrs
  rescue LookerSDK::NotFound => e
    say_error "Alert notification #{notification_id} not found"
    say_error e
    raise
  rescue LookerSDK::Error => e
    say_error "Error calling read_alert_notification(#{notification_id})"
    say_error e
    raise
  end
end

#search_alerts(group_by: nil, fields: nil, disabled: nil, frequency: nil, condition_met: nil, last_run_start: nil, last_run_end: nil, all_owners: nil) ⇒ Object



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
# File 'lib/gzr/modules/alert.rb', line 46

def search_alerts(group_by: nil, fields: nil, disabled: nil, frequency: nil, condition_met: nil, last_run_start: nil, last_run_end: nil, all_owners: nil)
  data = []
  begin
    req = {}
    req[:group_by] = group_by unless group_by.nil?
    req[:fields] = fields unless fields.nil?
    req[:disabled] = disabled unless disabled.nil?
    req[:frequency] = frequency unless frequency.nil?
    req[:condition_met] = condition_met unless condition_met.nil?
    req[:last_run_start] = last_run_start unless last_run_start.nil?
    req[:last_run_end] = last_run_end unless last_run_end.nil?
    req[:all_owners] = all_owners unless all_owners.nil?
    req[:limit] = 64
    loop do
      page = @sdk.search_alerts(req).collect { |a| a.to_attrs }
      data+=page
      break unless page.length == req[:limit]
      req[:offset] = (req[:offset] || 0) + req[:limit]
    end
  rescue LookerSDK::NotFound => e
    # do nothing
  rescue LookerSDK::Error => e
    say_error "Error querying search_alerts(#{JSON.pretty_generate(req)})"
    say_error e
    raise
  end
  data
end

#unfollow_alert(alert_id) ⇒ Object



89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/gzr/modules/alert.rb', line 89

def unfollow_alert(alert_id)
  begin
    @sdk.unfollow_alert(alert_id)
  rescue LookerSDK::NotFound => e
    say_error "Alert #{alert_id} not found"
    say_error e
    raise
  rescue LookerSDK::Error => e
    say_error "Error unfollowing alert(#{alert_id})"
    say_error e
    raise
  end
end

#update_alert(alert_id, req) ⇒ Object



182
183
184
185
186
187
188
189
190
# File 'lib/gzr/modules/alert.rb', line 182

def update_alert(alert_id,req)
  begin
    @sdk.update_alert(alert_id,req).to_attrs
  rescue LookerSDK::Error => e
    say_error "Error calling update_alert(#{alert_id}, #{JSON.pretty_generate(req)})"
    say_error e
    raise
  end
end

#update_alert_field(alert_id, owner_id: nil, is_disabled: nil, disabled_reason: nil, is_public: nil, threshold: nil) ⇒ Object



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/gzr/modules/alert.rb', line 103

def update_alert_field(alert_id, owner_id: nil, is_disabled: nil, disabled_reason: nil, is_public: nil, threshold: nil)
  req = {}
  req[:owner_id] = owner_id unless owner_id.nil?
  req[:is_disabled] = is_disabled unless is_disabled.nil?
  req[:disabled_reason] = disabled_reason unless disabled_reason.nil?
  req[:is_public] = is_public unless is_public.nil?
  req[:threshold] = threshold unless threshold.nil?
  begin
    @sdk.update_alert_field(alert_id, req).to_attrs
  rescue LookerSDK::NotFound => e
    say_error "Alert #{alert_id} not found"
    say_error e
    raise
  rescue LookerSDK::Error => e
    say_error "Error calling update_alert_field(#{alert_id},#{JSON.pretty_generate(req)})"
    say_error e
    raise
  end
end