Class: Ey::Core::Client::Alert
Instance Attribute Summary collapse
Instance Method Summary
collapse
assoc_accessor, assoc_coverage, assoc_reader, assoc_writer, associations, collection_reader
Methods inherited from Model
#destroy, range_parser, #save, #to_s, #update!, #url
Instance Attribute Details
#agent ⇒ Object
40
41
42
43
44
|
# File 'lib/ey-core/models/alert.rb', line 40
def agent
type, identity = resource_keys
(type == "agents" || nil) && self.connection.agents.get!(identity)
end
|
#database_server ⇒ Object
46
47
48
49
50
|
# File 'lib/ey-core/models/alert.rb', line 46
def database_server
type, identity = resource_keys
(type == "database-servers" || nil) && self.connection.database_servers.get!(identity)
end
|
#resource ⇒ Object
22
23
24
25
26
|
# File 'lib/ey-core/models/alert.rb', line 22
def resource
type, identity = resource_keys
self.connection.public_send(type.gsub("-", "_")).get!(identity)
end
|
#server ⇒ Object
34
35
36
37
38
|
# File 'lib/ey-core/models/alert.rb', line 34
def server
type, identity = resource_keys
(type == "servers" || nil) && self.connection.servers.get!(identity)
end
|
Instance Method Details
#acknowledge! ⇒ Object
52
53
54
55
|
# File 'lib/ey-core/models/alert.rb', line 52
def acknowledge!
requires :id
merge_attributes(self.connection.acknowledge_alert("id" => self.id).body["legacy_alert"])
end
|
#resource_keys ⇒ Object
28
29
30
31
32
|
# File 'lib/ey-core/models/alert.rb', line 28
def resource_keys
requires :resource_url
resource_url.split("/")[-2..-1]
end
|
#save! ⇒ Object
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
|
# File 'lib/ey-core/models/alert.rb', line 57
def save!
response = if new_record?
params = {
"url" => self.collection.url,
"alert" => {
"description" => description,
"external_id" => external_id,
"finished_at" => finished_at,
"message" => message,
"name" => name,
"severity" => severity,
"started_at" => started_at,
}
}
if @database_server
params.merge!(database_server_id: @database_server.identity)
elsif @server
params.merge!(server_id: @server.identity)
end
self.connection.create_alert(params)
else
requires :identity
params = {
:id => self.id,
:alert => {
:acknowledged => acknowledged,
:external_id => external_id,
:finished_at => finished_at,
:ignored => ignored,
:message => message,
:severity => severity,
:started_at => started_at
}
}
self.connection.update_alert(params)
end
merge_attributes(response.body["alert"])
end
|