Skip to content

Commit

Permalink
populate swagger method descriptions, allow notification tests to pas…
Browse files Browse the repository at this point in the history
…s simulated condition
  • Loading branch information
ali-graham committed Nov 20, 2015
1 parent 657fa60 commit 1dad2ed
Show file tree
Hide file tree
Showing 21 changed files with 265 additions and 261 deletions.
20 changes: 6 additions & 14 deletions lib/flapjack/data/acknowledgement.rb
Expand Up @@ -144,8 +144,10 @@ def self.jsonapi_methods
@jsonapi_methods ||= {
:post => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
:attributes => [:duration, :summary],
:description => "
"
:descriptions => {
:singular => "Acknowledge a check, or acknowledge all checks linked to a tag.",
:multiple => "Acknowledge multiple checks, or checks linked to different tags."
}
)
}
end
Expand All @@ -157,23 +159,13 @@ def self.jsonapi_associations
:post => true,
:number => :singular, :link => false, :includable => false,
:type => 'check',
:klass => Flapjack::Data::Check,
:descriptions => {
:post => "
"
}
:klass => Flapjack::Data::Check
),
:tag => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
:post => true,
:number => :singular, :link => false, :includable => false,
:type => 'tag',
:klass => Flapjack::Data::Tag,
:descriptions => {
:post => "
"
}
:klass => Flapjack::Data::Tag
)
}
populate_association_data(@jsonapi_associations)
Expand Down
2 changes: 1 addition & 1 deletion lib/flapjack/data/alert.rb
Expand Up @@ -83,7 +83,7 @@ def self.notification_type(act, cond)
case act
when 'acknowledgement'
'acknowledgement'
when 'test_notifications'
when /\Atest_notifications(?:\s+#{Flapjack::Data::Condition.unhealthy.keys.join('|')})?\z/
'test'
when nil
case cond
Expand Down
83 changes: 41 additions & 42 deletions lib/flapjack/data/check.rb
Expand Up @@ -348,15 +348,31 @@ def self.swagger_included_classes
def self.jsonapi_methods
@jsonapi_methods ||= {
:post => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
:attributes => [:name, :enabled]
:attributes => [:name, :enabled],
:descriptions => {
:singular => "Create a check.",
:multiple => "Create checks."
}
),
:get => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
:attributes => [:name, :enabled, :ack_hash, :failing, :condition]
:attributes => [:name, :enabled, :ack_hash, :failing, :condition],
:descriptions => {
:singular => "Returns data for a check.",
:multiple => "Returns data for multiple check records."
}
),
:patch => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
:attributes => [:name, :enabled]
:attributes => [:name, :enabled],
:descriptions => {
:singular => "Update a check.",
:multiple => "Update checks."
}
),
:delete => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
:descriptions => {
:singular => "Delete a check.",
:multiple => "Delete checks."
}
)
}
end
Expand All @@ -376,9 +392,8 @@ def self.jsonapi_associations
Flapjack::Data::ScheduledMaintenance
],
:descriptions => {
:get => "
"
:get => "While this check is failing, returns media records " \
"which are receiving notifications during this failure."
}
),
:contacts => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
Expand All @@ -391,9 +406,9 @@ def self.jsonapi_associations
Flapjack::Data::Tag
],
:descriptions => {
:get => "
"
:get => "Returns contacts whose notification rules will " \
"allow them to receive notifications for events on " \
"this check."
}
),
:current_scheduled_maintenances => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
Expand All @@ -402,18 +417,15 @@ def self.jsonapi_associations
:type => 'scheduled_maintenance',
:klass => Flapjack::Data::ScheduledMaintenance,
:descriptions => {
:get => "
"
:get => "Returns scheduled maintenance periods currently in " \
" effect for this check."
}
),
:current_state => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
:get => true,
:number => :singular, :link => true, :includable => true,
:descriptions => {
:get => "
"
:get => "Returns the current State record for this check."
}
),
:current_unscheduled_maintenance => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
Expand All @@ -422,63 +434,50 @@ def self.jsonapi_associations
:type => 'unscheduled_maintenance',
:klass => Flapjack::Data::UnscheduledMaintenance,
:descriptions => {
:get => "
"
:get => "If the check is currently acknowledged, returns the " \
"unscheduled maintenance period created for that."
}
),
:latest_notifications => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
:get => true,
:number => :multiple, :link => true, :includable => true,
:descriptions => {
:get => "
"
:get => "Returns the most recent State records for each " \
"problem condition that produced notifications."
}
),
:scheduled_maintenances => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
:get => true,
:number => :multiple, :link => true, :includable => false,
:descriptions => {
:get => "
"
:get => "Returns all scheduled maintenance periods for the " \
"check; default sort order is newest first."
}
),
:states => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
:get => true,
:number => :multiple, :link => true, :includable => false,
:descriptions => {
:get => "
"
:get => "Returns all state records for the check; default " \
"sort order is newest first."
}
),
:tags => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
:post => true, :get => true, :patch => true, :delete => true,
:number => :multiple, :link => true, :includable => true,
:descriptions => {
:get => "
",
:post => "
",
:patch => "
",
:delete => "
"
:post => "Associate tags with this check.",
:get => "Returns all tags linked to this check.",
:patch => "Update the tags associated with this check.",
:delete => "Delete associations between tags and this check."
}
),
:unscheduled_maintenances => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
:get => true,
:number => :multiple, :link => true, :includable => false,
:descriptions => {
:get => "
"
:get => "Returns all unscheduled maintenance periods for the " \
"check; default sort order is newest first."
}
)
}
Expand Down
57 changes: 24 additions & 33 deletions lib/flapjack/data/contact.rb
Expand Up @@ -230,26 +230,30 @@ def self.jsonapi_methods
@jsonapi_methods ||= {
:post => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
:attributes => [:name, :timezone],
:description => "
"
:descriptions => {
:singular => "Create a contact.",
:multiple => "Create contacts."
}
),
:get => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
:attributes => [:name, :timezone],
:description => "
"
:descriptions => {
:singular => "Get data for a contact.",
:multiple => "Get data for multiple contacts."
}
),
:patch => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
:attributes => [:name, :timezone],
:description => "
"
:descriptions => {
:singular => "Update a contact record.",
:multiple => "Update contact records."
}
),
:delete => Flapjack::Gateways::JSONAPI::Data::MethodDescriptor.new(
:description => "
"
:descriptions => {
:singular => "Delete a contact.",
:multiple => "Delete contacts."
}
),
}
end
Expand All @@ -263,45 +267,32 @@ def self.jsonapi_associations
:type => 'check',
:klass => Flapjack::Data::Check,
:descriptions => {
:get => "
"
:get => "Returns checks which this contact's notification " \
"rules allow it to receive notifications."
}
),
:media => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
:get => true,
:number => :multiple, :link => true, :includable => true,
:descriptions => {
:get => "
"
:get => "Returns media belonging to the contact."
}
),
:rules => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
:get => true,
:number => :multiple, :link => true, :includable => true,
:descriptions => {
:get => "
"
:get => "Returns rules belonging to the contact."
}
),
:tags => Flapjack::Gateways::JSONAPI::Data::JoinDescriptor.new(
:post => true, :get => true, :patch => true, :delete => true,
:number => :multiple, :link => true, :includable => true,
:descriptions => {
:post => "
",
:get => "
",
:patch => "
",
:delete => "
"
:post => "Associate tags with this contact.",
:get => "Returns all tags linked to this contact.",
:patch => "Update the tags associated with this contact.",
:delete => "Delete associations between tags and this contact."
}
)
}
Expand Down
11 changes: 8 additions & 3 deletions lib/flapjack/data/event.rb
Expand Up @@ -20,9 +20,10 @@ class Event
VALIDATIONS = {
proc {|e| e['state'].is_a?(String) &&
['ok', 'warning', 'critical', 'unknown', 'acknowledgement',
'test_notifications'].include?(e['state'].downcase) } =>
'test_notifications'].include?(e['state'].downcase) ||
!(e['state'] =~ /\Atest_notifications(?:\s+#{Flapjack::Data::Condition.unhealthy.keys.join('|')})?\z/).nil? } =>
"state must be one of 'ok', 'warning', 'critical', 'unknown', " +
"'acknowledgement' or 'test_notifications'",
"'acknowledgement', 'test_notifications', or 'test_notifications [problem]' ",

proc {|e| e['entity'].nil? || e['entity'].is_a?(String) } =>
"entity must be a string",
Expand Down Expand Up @@ -156,8 +157,12 @@ def self.create_acknowledgements(queue, checks, opts = {})

def self.test_notifications(queue, checks, opts = {})
raise "Check(s) must be provided" if checks.nil?
condition = opts[:condition] || 'critical'
unless Flapjack::Data::Condition.unhealthy.keys.include?(condition)
raise "Condition must be a problem"
end
checks.each do |check|
self.push(queue, 'state' => 'test_notifications',
self.push(queue, 'state' => "test_notifications #{condition}",
'check' => check.name,
'summary' => opts[:summary],
'details' => opts[:details])
Expand Down

0 comments on commit 1dad2ed

Please sign in to comment.