class Flapjack::Data::Medium
Constants
- TRANSPORTS
Public Class Methods
destroy_state(medium_id, st_id)
click to toggle source
# File lib/flapjack/data/medium.rb, line 141 def self.destroy_state(medium_id, st_id) # won't be deleted if still referenced elsewhere -- see the State # before_destroy callback Flapjack::Data::State.intersect(:id => st_id).destroy_all end
jsonapi_associations()
click to toggle source
# File lib/flapjack/data/medium.rb, line 385 def self.jsonapi_associations unless instance_variable_defined?('@jsonapi_associations') @jsonapi_associations = { :alerting_checks => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new( :get => true, :number => :multiple, :link => true, :includable => true, :type => 'check', :klass => Flapjack::Data::Check, :callback_classes => [ Flapjack::Data::Contact, Flapjack::Data::Rule, Flapjack::Data::ScheduledMaintenance ], :descriptions => { :get => "Returns all checks that have alerted through a medium (that are still failing." } ), :contact => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new( :post => true, :get => true, :number => :singular, :link => true, :includable => true, :descriptions => { :post => "Set a contact for a medium during medium creation (required).", :get => "Get the contact a medium belongs to." } ), :rules => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new( :post => true, :get => true, :patch => true, :delete => true, :number => :multiple, :link => true, :includable => true, :descriptions => { :post => "Associate this medium with rules on medium creation.", :get => "Get the rules this medium is associated with.", :patch => "Update the rules this medium is associated with.", :delete => "Delete associations between this medium and rules." } ) } populate_association_data(@jsonapi_associations) end @jsonapi_associations end
jsonapi_methods()
click to toggle source
# File lib/flapjack/data/medium.rb, line 347 def self.jsonapi_methods @jsonapi_methods ||= { :post => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new( :attributes => [:transport, :address, :interval, :rollup_threshold, :pagerduty_subdomain, :pagerduty_token, :pagerduty_ack_duration], :descriptions => { :singular => "Create a media record.", :multiple => "Create media records." } ), :get => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new( :attributes => [:transport, :address, :interval, :rollup_threshold, :pagerduty_subdomain, :pagerduty_token, :pagerduty_ack_duration], :descriptions => { :singular => "Returns data for a media record.", :multiple => "Returns data for media records." } ), :patch => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new( :attributes => [:transport, :address, :interval, :rollup_threshold, :pagerduty_subdomain, :pagerduty_token, :pagerduty_ack_duration], :descriptions => { :singular => "Update a media record.", :multiple => "Update media records." } ), :delete => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new( :descriptions => { :singular => "Delete a media record.", :multiple => "Delete media records." } ) } end
swagger_included_classes()
click to toggle source
# File lib/flapjack/data/medium.rb, line 333 def self.swagger_included_classes # hack -- hardcoding for now [ Flapjack::Data::Check, Flapjack::Data::Contact, Flapjack::Data::Medium, Flapjack::Data::Rule, Flapjack::Data::ScheduledMaintenance, Flapjack::Data::State, Flapjack::Data::Tag, Flapjack::Data::UnscheduledMaintenance ] end
Public Instance Methods
alerting_checks(opts = {})
click to toggle source
this can be called from the API (with no args) or from notifier.rb (which will pass an effective time)
# File lib/flapjack/data/medium.rb, line 64 def alerting_checks(opts = {}) time = opts[:time] || Time.now init_scope = Flapjack::Data::Check.intersect(:enabled => true, :alertable => true) ret = checks(:initial_scope => init_scope, :time => Time.now) return Flapjack::Data::Check.empty if ret.empty? start_range = Zermelo::Filters::IndexRange.new(nil, time, :by_score => true) end_range = Zermelo::Filters::IndexRange.new(time, nil, :by_score => true) sched_maint_check_ids = Flapjack::Data::ScheduledMaintenance. intersect(:start_time => start_range, :end_time => end_range). associated_ids_for(:check).values ret = ret.diff(:id => sched_maint_check_ids) unless sched_maint_check_ids.empty? unsched_maint_check_ids = Flapjack::Data::UnscheduledMaintenance. intersect(:start_time => start_range, :end_time => end_range). associated_ids_for(:check).values ret = ret.diff(:id => unsched_maint_check_ids) unless unsched_maint_check_ids.empty? ret end
checks(opts = {})
click to toggle source
# File lib/flapjack/data/medium.rb, line 89 def checks(opts = {}) time_zone = self.contact.time_zone time = opts[:time] || Time.now init_scope = opts[:initial_scope] || Flapjack::Data::Check.intersect(:enabled => true) # TODO maybe fold time validation into 'matching_checks' global_rejector_ids = self.rules.intersect(:enabled => true, :blackhole => true, :strategy => 'global').select {|rejector| rejector.is_occurring_at?(time, time_zone) }.map(&:id) unless global_rejector_ids.empty? # global blackhole return Flapjack::Data::Check.empty end rejector_ids = self.rules.intersect(:enabled => true, :blackhole => true, :strategy => ['all_tags', 'any_tag', 'no_tag']).select {|rejector| rejector.is_occurring_at?(time, time_zone) }.map(&:id) acceptors = self.rules.intersect(:enabled => true, :blackhole => false).select {|acceptor| acceptor.is_occurring_at?(time, time_zone) } # no positives return Flapjack::Data::Check.empty if acceptors.empty? ret = init_scope if acceptors.none? {|a| 'global'.eql?(a.strategy) } # if no global acceptor, scope by tags for acceptors acceptor_checks = Flapjack::Data::Rule.matching_checks(acceptors.map(&:id)) ret = ret.intersect(:id => acceptor_checks) end # then exclude by checks with tags matching rejector, if any rejector_checks = Flapjack::Data::Rule.matching_checks(rejector_ids) unless rejector_checks.empty? ret = ret.diff(:id => rejector_checks) end ret end