mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
Merge pull request #2127 from damnitjim/master
Adding notifications for Rackspace Monitoring
This commit is contained in:
commit
9bc7bdfd4d
12 changed files with 330 additions and 1 deletions
42
lib/fog/rackspace/models/monitoring/notification.rb
Normal file
42
lib/fog/rackspace/models/monitoring/notification.rb
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
require 'fog/core/model'
|
||||||
|
require 'fog/rackspace/models/monitoring/base'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Rackspace
|
||||||
|
class Monitoring
|
||||||
|
class Notification < Fog::Rackspace::Monitoring::Base
|
||||||
|
|
||||||
|
identity :id
|
||||||
|
|
||||||
|
attribute :label
|
||||||
|
attribute :details
|
||||||
|
attribute :type
|
||||||
|
|
||||||
|
def params
|
||||||
|
options = {
|
||||||
|
'label' => label,
|
||||||
|
'details' => details,
|
||||||
|
'type' => type,
|
||||||
|
}
|
||||||
|
options.reject {|key, value| value.nil?}
|
||||||
|
end
|
||||||
|
|
||||||
|
def save
|
||||||
|
if identity
|
||||||
|
data = service.update_notification(identity, params)
|
||||||
|
else
|
||||||
|
data = service.create_notification(params)
|
||||||
|
self.id = data.headers['X-Object-ID']
|
||||||
|
end
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
def destroy
|
||||||
|
requires :id
|
||||||
|
service.delete_notification(id)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
30
lib/fog/rackspace/models/monitoring/notifications.rb
Normal file
30
lib/fog/rackspace/models/monitoring/notifications.rb
Normal file
|
@ -0,0 +1,30 @@
|
||||||
|
require 'fog/core/collection'
|
||||||
|
require 'fog/rackspace/models/monitoring/notification'
|
||||||
|
|
||||||
|
module Fog
|
||||||
|
module Rackspace
|
||||||
|
class Monitoring
|
||||||
|
class Notifications < Fog::Collection
|
||||||
|
|
||||||
|
model Fog::Rackspace::Monitoring::Notification
|
||||||
|
|
||||||
|
attribute :marker
|
||||||
|
|
||||||
|
def all(options={})
|
||||||
|
data = service.list_notifications(options).body
|
||||||
|
marker = data['metadata']['next_marker']
|
||||||
|
|
||||||
|
load(data['values'])
|
||||||
|
end
|
||||||
|
|
||||||
|
def get(notification_id)
|
||||||
|
data = service.get_notification(notification_id).body
|
||||||
|
new(data)
|
||||||
|
rescue Fog::Rackspace::Monitoring::NotFound
|
||||||
|
nil
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
|
@ -40,6 +40,8 @@ module Fog
|
||||||
collection :data_points
|
collection :data_points
|
||||||
model :check_type
|
model :check_type
|
||||||
collection :check_types
|
collection :check_types
|
||||||
|
model :notification
|
||||||
|
collection :notifications
|
||||||
|
|
||||||
request_path 'fog/rackspace/requests/monitoring'
|
request_path 'fog/rackspace/requests/monitoring'
|
||||||
request :list_agent_tokens
|
request :list_agent_tokens
|
||||||
|
@ -52,26 +54,31 @@ module Fog
|
||||||
request :list_check_types
|
request :list_check_types
|
||||||
request :list_overview
|
request :list_overview
|
||||||
request :list_notification_plans
|
request :list_notification_plans
|
||||||
|
request :list_notifications
|
||||||
|
|
||||||
request :get_agent_token
|
request :get_agent_token
|
||||||
request :get_alarm
|
request :get_alarm
|
||||||
request :get_alarm_example
|
request :get_alarm_example
|
||||||
request :get_check
|
request :get_check
|
||||||
request :get_entity
|
request :get_entity
|
||||||
|
request :get_notification
|
||||||
|
|
||||||
request :create_agent_token
|
request :create_agent_token
|
||||||
request :create_alarm
|
request :create_alarm
|
||||||
request :create_check
|
request :create_check
|
||||||
request :create_entity
|
request :create_entity
|
||||||
|
request :create_notification
|
||||||
|
|
||||||
request :update_check
|
request :update_check
|
||||||
request :update_entity
|
request :update_entity
|
||||||
request :update_alarm
|
request :update_alarm
|
||||||
|
request :update_notification
|
||||||
|
|
||||||
request :delete_agent_token
|
request :delete_agent_token
|
||||||
request :delete_alarm
|
request :delete_alarm
|
||||||
request :delete_check
|
request :delete_check
|
||||||
request :delete_entity
|
request :delete_entity
|
||||||
|
request :delete_notification
|
||||||
|
|
||||||
request :evaluate_alarm_example
|
request :evaluate_alarm_example
|
||||||
|
|
||||||
|
|
18
lib/fog/rackspace/requests/monitoring/create_notification.rb
Normal file
18
lib/fog/rackspace/requests/monitoring/create_notification.rb
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
module Fog
|
||||||
|
module Rackspace
|
||||||
|
class Monitoring
|
||||||
|
class Real
|
||||||
|
def create_notification(options = {})
|
||||||
|
data = options.dup
|
||||||
|
request(
|
||||||
|
:body => JSON.encode(data),
|
||||||
|
:expects => [201],
|
||||||
|
:method => 'POST',
|
||||||
|
:path => 'notifications'
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
16
lib/fog/rackspace/requests/monitoring/delete_notification.rb
Normal file
16
lib/fog/rackspace/requests/monitoring/delete_notification.rb
Normal file
|
@ -0,0 +1,16 @@
|
||||||
|
module Fog
|
||||||
|
module Rackspace
|
||||||
|
class Monitoring
|
||||||
|
class Real
|
||||||
|
def delete_notification(notification_id)
|
||||||
|
request(
|
||||||
|
:expects => [204],
|
||||||
|
:method => 'DELETE',
|
||||||
|
:path => "notifications/#{notification_id}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
50
lib/fog/rackspace/requests/monitoring/get_notification.rb
Normal file
50
lib/fog/rackspace/requests/monitoring/get_notification.rb
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
module Fog
|
||||||
|
module Rackspace
|
||||||
|
class Monitoring
|
||||||
|
class Real
|
||||||
|
|
||||||
|
def get_notification(notification_id)
|
||||||
|
request(
|
||||||
|
:expects => [200],
|
||||||
|
:method => 'GET',
|
||||||
|
:path => "notifications/#{notification_id}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
def get_notification(notification_id)
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = {
|
||||||
|
"created_at" => 1378783452067,
|
||||||
|
"details" => {
|
||||||
|
"address" => "test@test.com"
|
||||||
|
},
|
||||||
|
"id" => "ntnJN3MQrA",
|
||||||
|
"label" => "my email update test",
|
||||||
|
"type" => "email",
|
||||||
|
"updated_at" => 1378784136307
|
||||||
|
}
|
||||||
|
|
||||||
|
response.headers = {
|
||||||
|
"Date"=> Time.now.utc.to_s,
|
||||||
|
"Content-Type"=>"application/json; charset=UTF-8",
|
||||||
|
"X-RateLimit-Limit"=>"50000",
|
||||||
|
"X-RateLimit-Remaining"=>"49627",
|
||||||
|
"X-RateLimit-Window"=>"24 hours",
|
||||||
|
"X-RateLimit-Type"=>"global",
|
||||||
|
"X-Response-Id"=>"j23jlk234jl2j34j",
|
||||||
|
"X-LB"=>"dfw1-maas-prod-api0",
|
||||||
|
"Vary"=>"Accept-Encoding",
|
||||||
|
"Transfer-Encoding"=>"chunked"
|
||||||
|
}
|
||||||
|
response
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
67
lib/fog/rackspace/requests/monitoring/list_notifications.rb
Normal file
67
lib/fog/rackspace/requests/monitoring/list_notifications.rb
Normal file
|
@ -0,0 +1,67 @@
|
||||||
|
module Fog
|
||||||
|
module Rackspace
|
||||||
|
class Monitoring
|
||||||
|
class Real
|
||||||
|
|
||||||
|
def list_notifications(options={})
|
||||||
|
request(
|
||||||
|
:expects => [200],
|
||||||
|
:method => 'GET',
|
||||||
|
:path => "notifications",
|
||||||
|
:query => options
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
class Mock
|
||||||
|
def list_notifications(options={})
|
||||||
|
account_id = Fog::Mock.random_numbers(6).to_s
|
||||||
|
server_id = Fog::Rackspace::MockData.uuid
|
||||||
|
entity_id = Fog::Mock.random_letters(10)
|
||||||
|
entity_label = Fog::Mock.random_letters(10)
|
||||||
|
|
||||||
|
response = Excon::Response.new
|
||||||
|
response.status = 200
|
||||||
|
response.body = {
|
||||||
|
"values"=> [
|
||||||
|
{
|
||||||
|
"created_at"=>1378783452067,
|
||||||
|
"details"=>{
|
||||||
|
"address"=>"test@test.com"
|
||||||
|
},
|
||||||
|
"id"=>"ntnJN3MQrA",
|
||||||
|
"label"=>"my email update test",
|
||||||
|
"type"=>"email",
|
||||||
|
"updated_at"=>1378784136307
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"metadata" => {
|
||||||
|
"count" => 1,
|
||||||
|
"limit" => 100,
|
||||||
|
"marker" => nil,
|
||||||
|
"next_marker" => nil,
|
||||||
|
"next_href" => nil
|
||||||
|
}
|
||||||
|
}
|
||||||
|
response.headers = {
|
||||||
|
"Date" => Time.now.utc.to_s,
|
||||||
|
"Content-Type" => "application/json; charset=UTF-8",
|
||||||
|
"X-RateLimit-Limit" => "50000",
|
||||||
|
"X-RateLimit-Remaining" => "49627",
|
||||||
|
"X-RateLimit-Window" => "24 hours",
|
||||||
|
"X-RateLimit-Type" => "global",
|
||||||
|
"X-Response-Id" => "j23jlk234jl2j34j",
|
||||||
|
"X-LB" => "dfw1-maas-prod-api0",
|
||||||
|
"Vary" => "Accept-Encoding",
|
||||||
|
"Transfer-Encoding" => "chunked"
|
||||||
|
}
|
||||||
|
response.remote_ip = Fog::Rackspace::MockData.ipv4_address
|
||||||
|
response
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
17
lib/fog/rackspace/requests/monitoring/update_notification.rb
Normal file
17
lib/fog/rackspace/requests/monitoring/update_notification.rb
Normal file
|
@ -0,0 +1,17 @@
|
||||||
|
module Fog
|
||||||
|
module Rackspace
|
||||||
|
class Monitoring
|
||||||
|
class Real
|
||||||
|
def update_notification(id, options)
|
||||||
|
request(
|
||||||
|
:body => JSON.encode(options),
|
||||||
|
:expects => [204],
|
||||||
|
:method => 'PUT',
|
||||||
|
:path => "notifications/#{id}"
|
||||||
|
)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
19
tests/rackspace/models/monitoring/notification_tests.rb
Normal file
19
tests/rackspace/models/monitoring/notification_tests.rb
Normal file
|
@ -0,0 +1,19 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Monitoring | notification', ['rackspace','rackspace_monitoring']) do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
service = Fog::Rackspace::Monitoring.new
|
||||||
|
|
||||||
|
options = { :label => "fog_#{Time.now.to_i.to_s}", :type => "email", :details => {:address => "test@test.com"} }
|
||||||
|
|
||||||
|
model_tests(service.notifications, options, false) do
|
||||||
|
|
||||||
|
tests('#update').succeeds do
|
||||||
|
new_label = "new_label_#{Time.now.to_i.to_s}"
|
||||||
|
@instance.label = new_label
|
||||||
|
@instance.save
|
||||||
|
@instance.label = nil # blank out label just to make sure
|
||||||
|
@instance.reload
|
||||||
|
returns(new_label) { @instance.label }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
10
tests/rackspace/models/monitoring/notifications_tests.rb
Normal file
10
tests/rackspace/models/monitoring/notifications_tests.rb
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Monitoring | notifications', ['rackspace','rackspace_monitoring']) do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
service = Fog::Rackspace::Monitoring.new
|
||||||
|
|
||||||
|
options = { :label => "fog_#{Time.now.to_i.to_s}", :type => "email", :details => {:address => "test@test.com"} }
|
||||||
|
collection_tests(service.notifications, options, false) do
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
|
@ -13,7 +13,7 @@ Shindo.tests('Fog::Rackspace::Monitoring | list_tests', ['rackspace','rackspace_
|
||||||
now = Time.now.to_i
|
now = Time.now.to_i
|
||||||
SLEEP_TIME= 2
|
SLEEP_TIME= 2
|
||||||
sleep(SLEEP_TIME) unless Fog.mocking?
|
sleep(SLEEP_TIME) unless Fog.mocking?
|
||||||
|
|
||||||
tests('success') do
|
tests('success') do
|
||||||
tests('#get list of checks').formats(LIST_HEADERS_FORMAT) do
|
tests('#get list of checks').formats(LIST_HEADERS_FORMAT) do
|
||||||
account.list_checks(entity_id).data[:headers]
|
account.list_checks(entity_id).data[:headers]
|
||||||
|
@ -33,6 +33,9 @@ Shindo.tests('Fog::Rackspace::Monitoring | list_tests', ['rackspace','rackspace_
|
||||||
tests('#list notification plans').formats(LIST_HEADERS_FORMAT) do
|
tests('#list notification plans').formats(LIST_HEADERS_FORMAT) do
|
||||||
account.list_notification_plans().data[:headers]
|
account.list_notification_plans().data[:headers]
|
||||||
end
|
end
|
||||||
|
tests('#list notifications').formats(LIST_HEADERS_FORMAT) do
|
||||||
|
account.list_notifications().data[:headers]
|
||||||
|
end
|
||||||
tests('#get list of data points').formats(LIST_HEADERS_FORMAT) do
|
tests('#get list of data points').formats(LIST_HEADERS_FORMAT) do
|
||||||
options = {
|
options = {
|
||||||
:points => 1,
|
:points => 1,
|
||||||
|
@ -50,6 +53,10 @@ Shindo.tests('Fog::Rackspace::Monitoring | list_tests', ['rackspace','rackspace_
|
||||||
account.list_check_types(-1)
|
account.list_check_types(-1)
|
||||||
end
|
end
|
||||||
# This test has been put on hold due to a bug that incorrectly returns 200 OK to this request
|
# This test has been put on hold due to a bug that incorrectly returns 200 OK to this request
|
||||||
|
# tests('#fail to list notifications').raises(ArgumentError) do
|
||||||
|
# account.list_notifications(-1)
|
||||||
|
# end
|
||||||
|
# This test has been put on hold due to a bug that incorrectly returns 200 OK to this request
|
||||||
#tests('#fail to list metrics').raises(Fog::Rackspace::Monitoring::NotFound) do
|
#tests('#fail to list metrics').raises(Fog::Rackspace::Monitoring::NotFound) do
|
||||||
#account.list_metrics(-1,-1)
|
#account.list_metrics(-1,-1)
|
||||||
#end
|
#end
|
||||||
|
|
46
tests/rackspace/requests/monitoring/notification_tests.rb
Normal file
46
tests/rackspace/requests/monitoring/notification_tests.rb
Normal file
|
@ -0,0 +1,46 @@
|
||||||
|
Shindo.tests('Fog::Rackspace::Monitoring | notification_tests', ['rackspace','rackspace_monitoring']) do
|
||||||
|
account = Fog::Rackspace::Monitoring.new
|
||||||
|
notification_id = nil
|
||||||
|
tests('success') do
|
||||||
|
tests('#create new notification').formats(DATA_FORMAT) do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
response = account.create_notification(:label => "Foo", :type => "email", :details => {:address => "test@test.com"}).data
|
||||||
|
|
||||||
|
notification_id = response[:headers]["X-Object-ID"]
|
||||||
|
response
|
||||||
|
end
|
||||||
|
tests('#get notification').formats(LIST_HEADERS_FORMAT) do
|
||||||
|
account.get_notification(notification_id).data[:headers]
|
||||||
|
end
|
||||||
|
tests('#update notification').formats(DATA_FORMAT) do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
options = {:testing => "Bar"}
|
||||||
|
account.update_notification(notification_id,options).data
|
||||||
|
end
|
||||||
|
tests('#delete notification').formats(DELETE_DATA_FORMAT) do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
account.delete_notification(notification_id).data
|
||||||
|
end
|
||||||
|
end
|
||||||
|
tests('failure') do
|
||||||
|
tests('#create new notification(-1)').raises(Fog::Rackspace::Monitoring::BadRequest) do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
account.create_notification(:label => "")
|
||||||
|
end
|
||||||
|
tests('#get notification(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
|
||||||
|
account.get_notification(-1)
|
||||||
|
end
|
||||||
|
tests('#update invalid notification(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
options = { :testing => "Bar" }
|
||||||
|
response = account.update_notification(-1,options)
|
||||||
|
end
|
||||||
|
tests('#delete notification(-1)').raises(Fog::Rackspace::Monitoring::NotFound) do
|
||||||
|
pending if Fog.mocking?
|
||||||
|
account.delete_notification(-1)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
Loading…
Add table
Add a link
Reference in a new issue