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 +4 -4
- data/lib/kennel/tasks.rb +36 -6
- data/lib/kennel/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 424978ab5e025d68c1b30adee8dcf9bbae531c34da1ce02abcc1a97165accb2f
|
4
|
+
data.tar.gz: 762d7b47d15937d0ea9b2bb7d9bb1c79d88b34828a0b455c05aa4d7498fd8f04
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
-
|
108
|
-
|
109
|
-
|
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
|
|
data/lib/kennel/version.rb
CHANGED