lib/flapjack/gateways/jsonapi.rb in flapjack-0.8.11 vs lib/flapjack/gateways/jsonapi.rb in flapjack-0.8.12
- old
+ new
@@ -1,11 +1,11 @@
#!/usr/bin/env ruby
# A HTTP-based API server, which provides queries to determine the status of
# entities and the checks that are reported against them.
#
-# There's a matching flapjack-diner gem at https://github.com/flpjck/flapjack-diner
+# There's a matching flapjack-diner gem at https://github.com/flapjack/flapjack-diner
# which consumes data from this API.
require 'time'
require 'rack/fiber_pool'
@@ -18,10 +18,11 @@
require 'flapjack/gateways/jsonapi/check_methods'
require 'flapjack/gateways/jsonapi/contact_methods'
require 'flapjack/gateways/jsonapi/entity_methods'
require 'flapjack/gateways/jsonapi/medium_methods'
+require 'flapjack/gateways/jsonapi/metrics_methods'
require 'flapjack/gateways/jsonapi/notification_rule_methods'
require 'flapjack/gateways/jsonapi/pagerduty_credential_methods'
require 'flapjack/gateways/jsonapi/report_methods'
module Flapjack
@@ -51,16 +52,23 @@
@contact_ids = contact_ids
end
end
class NotificationRuleNotFound < RuntimeError
- attr_reader :rule_id
- def initialize(rule_id)
- @rule_id = rule_id
+ attr_reader :notification_rule_id
+ def initialize(notification_rule_id)
+ @notification_rule_id = notification_rule_id
end
end
+ class NotificationRulesNotFound < RuntimeError
+ attr_reader :notification_rule_ids
+ def initialize(notification_rule_ids)
+ @notification_rule_ids = notification_rule_ids
+ end
+ end
+
class EntityNotFound < RuntimeError
attr_reader :entity
def initialize(entity)
@entity = entity
end
@@ -130,11 +138,13 @@
when Flapjack::Gateways::JSONAPI::ContactNotFound
rescue_error.call(404, e, request_info, "could not find contact '#{e.contact_id}'")
when Flapjack::Gateways::JSONAPI::ContactsNotFound
rescue_error.call(404, e, request_info, "could not find contacts '" + e.contact_ids.join(', ') + "'")
when Flapjack::Gateways::JSONAPI::NotificationRuleNotFound
- rescue_error.call(404, e, request_info,"could not find notification rule '#{e.rule_id}'")
+ rescue_error.call(404, e, request_info,"could not find notification rule '#{e.notification_rule_id}'")
+ when Flapjack::Gateways::JSONAPI::NotificationRulesNotFound
+ rescue_error.call(404, e, request_info, "could not find notification rules '" + e.notification_rule_ids.join(', ') + "'")
when Flapjack::Gateways::JSONAPI::EntityNotFound
rescue_error.call(404, e, request_info, "could not find entity '#{e.entity}'")
when Flapjack::Gateways::JSONAPI::EntityCheckNotFound
rescue_error.call(404, e, request_info, "could not find entity check '#{e.check}'")
when Flapjack::Gateways::JSONAPI::ResourceLocked
@@ -239,15 +249,10 @@
'Access-Control-Max-Age' => '1728000'
}
headers(cors_headers)
end
- def location(ids)
- location = "#{base_url}#{request.path_info}#{ids.length == 1 ? '/' + ids.first : '?ids=' + ids.join(',')}"
- headers({'Location' => location})
- end
-
def err(status, *msg)
msg_str = msg.join(", ")
logger.info "Error: #{msg_str}"
[status, {}, {:errors => msg}.to_json]
end
@@ -403,9 +408,10 @@
register Flapjack::Gateways::JSONAPI::CheckMethods
register Flapjack::Gateways::JSONAPI::ContactMethods
register Flapjack::Gateways::JSONAPI::EntityMethods
register Flapjack::Gateways::JSONAPI::MediumMethods
+ register Flapjack::Gateways::JSONAPI::MetricsMethods
register Flapjack::Gateways::JSONAPI::NotificationRuleMethods
register Flapjack::Gateways::JSONAPI::PagerdutyCredentialMethods
register Flapjack::Gateways::JSONAPI::ReportMethods
not_found do