Class: Sysdig::AlertNotification

Inherits:
Model
  • Object
show all
Defined in:
lib/sysdig/alert_notification.rb

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

epoch_time, microsecond_datetime, upcase

Class Method Details

.dump_filter(h) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/sysdig/alert_notification.rb', line 14

def self.dump_filter(h)
  case h
  when Hash
    h.each_with_object([]) { |(k,v),r|
      r << "#{k} = #{Sysdig::AlertFilter.normalize_condition(v).inspect}"
    }.join(" and ")
  else h
  end
end

.load_filter(s, _) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/sysdig/alert_notification.rb', line 4

def self.load_filter(s, _)
  case s
  when String
    s.split(" and ").
      map        { |c| c.split(" = ") }.
      inject({}) { |r,(k,v)| r.merge(k => Sysdig::AlertFilter.normalize_condition(v)) }
  else s
  end
end

Instance Method Details

#resolve!Object



52
53
54
55
# File 'lib/sysdig/alert_notification.rb', line 52

def resolve!
  self.resolved = true
  self.save
end

#saveObject



37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/sysdig/alert_notification.rb', line 37

def save
  params = {
    "alert"     => self.alert_id,
    "filter"    => self.class.dump_filter(self.filter),
    "resolved"  => self.resolved,
    "severity"  => self.severity,
    "state"     => self.state,
    "timestamp" => self.timestamp.to_i * 1_000_000,
  }

  data = service.update_alert_notification(self.identity, params).body.fetch("notification")

  merge_attributes(data)
end