Class: Sysdig::Alert

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

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Model

epoch_time

Class Method Details

.dump_filter(hash) ⇒ Object



3
4
5
# File 'lib/sysdig/alert.rb', line 3

def self.dump_filter(hash)
  hash.map { |k,v| [k, normalize_filter_condition(v).inspect].join(" = ") }.join(", ")
end

.load_filter(string) ⇒ Object



7
8
9
# File 'lib/sysdig/alert.rb', line 7

def self.load_filter(string)
  string.split(", ").map { |t| t.split(" = ") }.inject({}) { |r,(k,c)| r.merge(k => normalize_filter_condition(c)) }
end

.normalize_filter_condition(string) ⇒ Object



11
12
13
# File 'lib/sysdig/alert.rb', line 11

def self.normalize_filter_condition(string)
  string.gsub(/(^\\?\")|(\\?\"$)/, "")
end

Instance Method Details

#destroyObject



37
38
39
40
41
# File 'lib/sysdig/alert.rb', line 37

def destroy
  requires :identity

  service.destroy_alert(identity)
end

#saveObject



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
# File 'lib/sysdig/alert.rb', line 43

def save
  params = {
    "condition"         => self.condition,
    "description"       => self.description,
    "enabled"           => self.enabled,
    "filter"            => self.class.dump_filter(filter || {}),
    "groupAggregations" => self.group_aggregations,
    "groupBy"           => self.group_by,
    "groupCondition"    => self.group_condition,
    "name"              => self.name,
    "notify"            => self.notify,
    "segmentBy"         => self.segment_by,
    "segmentCondition"  => self.segment_condition,
    "severity"          => self.severity,
    "timespan"          => self.timespan,
    "type"              => self.type,
  }

  data = (
    (new_record? && service.create_alert(params)) ||
    service.update_alert(self.identity, params.merge("version" => self.version))
  ).body.fetch("alert")

  merge_attributes(data)
end