Module: RailsInformant::Notifiers::NotificationPolicy

Included in:
Slack, Webhook
Defined in:
lib/rails_informant/notifiers/notification_policy.rb

Constant Summary collapse

COOLDOWN =
1.hour
MILESTONE_COUNTS =
[ 10, 100, 1000 ].freeze
SILENT_STATUSES =
%w[duplicate ignored].freeze
PRIVATE_NETWORKS =
[
  IPAddr.new("0.0.0.0/8"),       # "This" network
  IPAddr.new("10.0.0.0/8"),       # RFC 1918
  IPAddr.new("100.64.0.0/10"),    # Carrier-grade NAT
  IPAddr.new("127.0.0.0/8"),      # Loopback
  IPAddr.new("169.254.0.0/16"),   # Link-local
  IPAddr.new("172.16.0.0/12"),    # RFC 1918
  IPAddr.new("192.0.0.0/24"),     # IETF protocol assignments
  IPAddr.new("192.0.2.0/24"),     # TEST-NET-1
  IPAddr.new("192.168.0.0/16"),   # RFC 1918
  IPAddr.new("198.18.0.0/15"),    # Benchmarking
  IPAddr.new("198.51.100.0/24"),  # TEST-NET-2
  IPAddr.new("203.0.113.0/24"),   # TEST-NET-3
  IPAddr.new("240.0.0.0/4"),      # Reserved
  IPAddr.new("::1/128"),          # IPv6 loopback
  IPAddr.new("fc00::/7"),         # IPv6 unique local
  IPAddr.new("fe80::/10")         # IPv6 link-local
].freeze

Instance Method Summary collapse

Instance Method Details

#should_notify?(error_group) ⇒ Boolean

Returns:

  • (Boolean)


33
34
35
36
37
38
39
40
41
# File 'lib/rails_informant/notifiers/notification_policy.rb', line 33

def should_notify?(error_group)
  return false if error_group.status.in?(SILENT_STATUSES)
  return true if error_group.total_occurrences == 1
  return true if error_group.total_occurrences.in?(MILESTONE_COUNTS)
  return true if error_group.last_notified_at.nil?
  return true if error_group.last_notified_at < COOLDOWN.ago

  false
end