kennel 1.101.0 → 1.102.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 11220aba046ce1fbc63b8b62e5a60f0cbd4b04862ff7394c0ad43a1776bc34a6
4
- data.tar.gz: 257808a3036f97c8b994c35ce0c4c621bafd1a29a43da0cba6c113a9fe8297ff
3
+ metadata.gz: 424978ab5e025d68c1b30adee8dcf9bbae531c34da1ce02abcc1a97165accb2f
4
+ data.tar.gz: 762d7b47d15937d0ea9b2bb7d9bb1c79d88b34828a0b455c05aa4d7498fd8f04
5
5
  SHA512:
6
- metadata.gz: 1bcd69ba301375d93c1c72f9cb1ffcf057e06d4aa3f604baada0ed4dce5cd0d4e7675227d9d4ef8f09a80198bc3e14268fcdb4cd1f3623d3a810818bbbe6d4b2
7
- data.tar.gz: c189ecb33b4800d9d0e382f82fedbcfa8723f3ff0a27bbd2554528de60d50f774309da9d30c27374ae3365863861f81fae438d4843a34519c4d0a044a4d250ce
6
+ metadata.gz: 2079300fb176ffe4a3c363c56dfb2fed0901b4f3cfce7ff6fd1c656f8981e16a94628eaa660ffee6a53cc86c9df2d7b604ca877c6c34c61eeec13cbe4b0484ee
7
+ data.tar.gz: 0113a4f7a4edf4813d66cb15090909e63a47945cfaa4bce22cd9fe40203f3b6dd3705c2f62652df7e09be9e4b7a7d5de1de2092074e2baa524c8392a3bb9b462
data/lib/kennel/tasks.rb CHANGED
@@ -3,6 +3,7 @@ require "English"
3
3
  require "kennel"
4
4
  require "kennel/unmuted_alerts"
5
5
  require "kennel/importer"
6
+ require "json"
6
7
 
7
8
  module Kennel
8
9
  module Tasks
@@ -89,7 +90,7 @@ namespace :kennel do
89
90
  Kennel::UnmutedAlerts.print(Kennel.send(:api), tag)
90
91
  end
91
92
 
92
- desc "show monitors with no data by TAG, for example TAG=team:foo"
93
+ desc "show monitors with no data by TAG, for example TAG=team:foo [THRESHOLD_DAYS=7] [FORMAT=json]"
93
94
  task nodata: :environment do
94
95
  tag = ENV["TAG"] || Kennel::Tasks.abort("Call with TAG=foo:bar")
95
96
  monitors = Kennel.send(:api).list("monitor", monitor_tags: tag, group_states: "no data")
@@ -97,16 +98,45 @@ namespace :kennel do
97
98
  monitors.reject! { |m| m[:tags].include? "nodata:ignore" }
98
99
  if monitors.any?
99
100
  Kennel.err.puts <<~TEXT
100
- This is a useful task to find monitors that have mis-spelled metrics or never received data at any time.
101
- To ignore monitors with nodata, tag the monitor with "nodata:ignore"
101
+ To ignore monitors with expected nodata, tag it with "nodata:ignore"
102
102
 
103
103
  TEXT
104
104
  end
105
105
 
106
+ now = Time.now
106
107
  monitors.each do |m|
107
- Kennel.out.puts m[:name]
108
- Kennel.out.puts Kennel::Utils.path_to_url("/monitors/#{m[:id]}")
109
- Kennel.out.puts
108
+ m[:days_in_no_data] =
109
+ if m[:overall_state_modified]
110
+ since = Date.parse(m[:overall_state_modified]).to_time
111
+ ((now - since) / (24 * 60 * 60)).to_i
112
+ else
113
+ 999
114
+ end
115
+ end
116
+
117
+ if threshold = ENV["THRESHOLD_DAYS"]
118
+ monitors.select! { |m| m[:days_in_no_data] > Integer(threshold) }
119
+ end
120
+
121
+ monitors.each { |m| m[:url] = Kennel::Utils.path_to_url("/monitors/#{m[:id]}") }
122
+
123
+ if ENV["FORMAT"] == "json"
124
+ report = monitors.map do |m|
125
+ match = m[:message].to_s.match(/-- Managed by kennel (\S+:\S+) in (\S+), /) || []
126
+ m.slice(:url, :name, :tags, :days_in_no_data).merge(
127
+ kennel_tracking_id: match[1],
128
+ kennel_source: match[2]
129
+ )
130
+ end
131
+
132
+ Kennel.out.puts JSON.pretty_generate(report)
133
+ else
134
+ monitors.each do |m|
135
+ Kennel.out.puts m[:name]
136
+ Kennel.out.puts Kennel::Utils.path_to_url("/monitors/#{m[:id]}")
137
+ Kennel.out.puts "No data since #{m[:days_in_no_data]}d"
138
+ Kennel.out.puts
139
+ end
110
140
  end
111
141
  end
112
142
 
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Kennel
3
- VERSION = "1.101.0"
3
+ VERSION = "1.102.0"
4
4
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kennel
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.101.0
4
+ version: 1.102.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Grosser