diff --git a/Gemfile b/Gemfile index c1ef9bd..e4fa24e 100644 --- a/Gemfile +++ b/Gemfile @@ -4,7 +4,7 @@ gem 'faraday', '~> 0.9' gem 'tilt', '~> 2' gem 'yajl-ruby', '~> 1.3.1', :require => [ 'yajl', 'yajl/json_gem' ] -gem 'activesupport', '>= 3.2', :require => 'active_support' +gem 'activesupport', '~> 4.1.11', :require => 'active_support' # service: mail gem 'mail', '~> 2.2' diff --git a/Gemfile.lock b/Gemfile.lock index cb9d342..e828ffd 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,14 +1,13 @@ GEM remote: https://rubygems.org/ specs: - activesupport (4.0.0) - i18n (~> 0.6, >= 0.6.4) - minitest (~> 4.2) - multi_json (~> 1.3) + activesupport (4.1.16) + i18n (~> 0.6, >= 0.6.9) + json (~> 1.7, >= 1.7.7) + minitest (~> 5.1) thread_safe (~> 0.1) - tzinfo (~> 0.3.37) + tzinfo (~> 1.1) addressable (2.4.0) - atomic (1.1.14) aws-partitions (1.24.0) aws-sdk-core (3.6.0) aws-partitions (~> 1.0) @@ -19,6 +18,7 @@ GEM aws-sigv4 (~> 1.0) aws-sigv4 (1.0.2) builder (3.2.2) + concurrent-ruby (1.1.5) descendants_tracker (0.0.3) diff-lcs (1.2.5) eventmachine (1.2.5) @@ -46,7 +46,8 @@ GEM httparty (0.12.0) json (~> 1.8) multi_xml (>= 0.5.2) - i18n (0.6.5) + i18n (0.9.5) + concurrent-ruby (~> 1.0) jeweler (2.1.2) builder bundler (>= 1.0) @@ -65,7 +66,7 @@ GEM treetop (~> 1.4.8) mime-types (1.25.1) mini_portile2 (2.1.0) - minitest (4.7.5) + minitest (5.11.3) multi_json (1.13.1) multi_xml (0.5.5) multipart-post (2.0.0) @@ -105,8 +106,7 @@ GEM simple_oauth (0.1.9) test-unit (3.2.7) power_assert - thread_safe (0.1.3) - atomic + thread_safe (0.3.6) tilt (2.0.7) tinder (1.10.1) eventmachine (~> 1.0) @@ -124,7 +124,8 @@ GEM eventmachine (>= 0.12.8) http_parser.rb (~> 0.5.1) simple_oauth (~> 0.1.4) - tzinfo (0.3.38) + tzinfo (1.2.5) + thread_safe (~> 0.1) yajl-ruby (1.3.1) yard (0.8.7.2) @@ -132,7 +133,7 @@ PLATFORMS ruby DEPENDENCIES - activesupport (>= 3.2) + activesupport (~> 4.1.11) aws-sdk-sns (~> 1) faraday (~> 0.9) flowdock (~> 0.3) @@ -150,4 +151,4 @@ DEPENDENCIES yard (~> 0.8) BUNDLED WITH - 1.17.2 + 1.17.3 diff --git a/lib/appoptics-services/numbers.rb b/lib/appoptics-services/numbers.rb index b808eb5..4fa4619 100644 --- a/lib/appoptics-services/numbers.rb +++ b/lib/appoptics-services/numbers.rb @@ -31,4 +31,3 @@ def self.number_decimal_places(number) end end end - diff --git a/lib/appoptics-services/output.rb b/lib/appoptics-services/output.rb index bd53ada..ff240e7 100644 --- a/lib/appoptics-services/output.rb +++ b/lib/appoptics-services/output.rb @@ -1,5 +1,6 @@ require 'redcarpet' require 'active_support/core_ext/string/filters.rb' +require 'active_support/number_helper.rb' require_relative 'helpers/alert_helpers' require_relative 'numbers' @@ -11,6 +12,7 @@ module AppOptics module Services class Output include Helpers::AlertHelpers + include ActiveSupport::NumberHelper attr_reader :violations, :conditions, :alert, :clear, :trigger_time, :alert_url def initialize(payload, add_test_notice=true) @@ -102,7 +104,7 @@ def generate_alert_cleared lines.join("\n") end - def format_measurement(measurement, source = nil) + def format_measurement(measurement, source = nil, service = nil) condition = @conditions[measurement[:condition_violated]] if source metric = "`#{measurement[:metric]}` from `#{source}`" @@ -110,17 +112,20 @@ def format_measurement(measurement, source = nil) metric = "`#{measurement[:metric]}`" end violation_time = measurement[:end] || measurement[:recorded_at] - "metric #{metric} was #{format_violation_type(condition, measurement)} recorded at #{format_time(violation_time)}" + "metric #{metric} was #{format_violation_type(condition, measurement, service)} recorded at #{format_time(violation_time)}" end - def format_violation_type(condition, measurement) + def format_violation_type(condition, measurement, service) if condition[:type] == "absent" "absent for #{condition[:duration]} seconds" else threshold_value = condition[:threshold] actual_value = measurement[:value] formatted_value = AppOptics::Services::Numbers.format_for_threshold(threshold_value, actual_value) - "#{condition[:type]} threshold #{threshold(condition,measurement)} with value #{formatted_value}" + if service == AppOptics::Services::Service::Slack::SERVICE_NAME + formatted_value = number_to_delimited(formatted_value) + end + "#{condition[:type]} threshold #{threshold(condition, measurement, service)} with value #{formatted_value}" end end @@ -130,8 +135,14 @@ def format_time(time) strftime("%a, %b %e %Y at %H:%M:%S UTC") end - def threshold(condition, measurement) - thresh_str = condition[:threshold].to_s + def threshold(condition, measurement, service) + thresh_str = nil + threshold = condition[:threshold] + if service == AppOptics::Services::Service::Slack::SERVICE_NAME + thresh_str = number_to_delimited(threshold) + else + thresh_str = threshold.to_s + end duration = calculate_duration(measurement) if duration thresh_str += " over #{duration} seconds" diff --git a/lib/appoptics-services/service.rb b/lib/appoptics-services/service.rb index 867c836..32afb92 100644 --- a/lib/appoptics-services/service.rb +++ b/lib/appoptics-services/service.rb @@ -179,5 +179,3 @@ class ConfigurationError < StandardError; end Dir[File.join(File.dirname(__FILE__), '../../services/*.rb')].each { |service| load service } - - diff --git a/services/slack.rb b/services/slack.rb index b1ce0de..0df8d6d 100644 --- a/services/slack.rb +++ b/services/slack.rb @@ -7,6 +7,7 @@ module AppOptics::Services class Service::Slack < AppOptics::Services::Service VERTICAL_LINE_COLOR = "#0880ad" + SERVICE_NAME = "slack" def receive_validate(errors = {}) if settings[:url].blank? @@ -70,7 +71,7 @@ def v2_alert_result { :title => source, :value => measurements.inject([]) do |texts, measurement| - texts << data.format_measurement(measurement) + texts << data.format_measurement(measurement, nil, SERVICE_NAME) end.join("\n") } end,