kennel 0.1.1 → 0.2.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.rb +6 -0
- data/lib/kennel/models/dash.rb +4 -1
- data/lib/kennel/models/monitor.rb +1 -0
- data/lib/kennel/models/screen.rb +109 -0
- data/lib/kennel/syncer.rb +7 -6
- data/lib/kennel/tasks.rb +1 -0
- data/lib/kennel/template_variables.rb +17 -0
- data/lib/kennel/utils.rb +12 -0
- data/lib/kennel/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c70c6bd2ed964a4e6abd06968705de5897bdcff5
|
4
|
+
data.tar.gz: a8a3823e0c36250246a806a26579b0e1e1f1417f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c736eb69dec71e163a8f0e7a9bc532a93f8600984d3c56ca20c0b58e81e1d9363ff26fb4276a802d2cbec49a0d7d1ed46da17c72c4a7e53f27599235626dc148
|
7
|
+
data.tar.gz: 4f6566b111f19f0de2244a28ff319fd438dc436e1fba4a532dffba2e6c559c00dee6c06f3235d979c9d332d02a32b9bf7794340512195c993bd4e8f2effd1d1d
|
data/lib/kennel.rb
CHANGED
@@ -10,10 +10,16 @@ require "kennel/api"
|
|
10
10
|
require "kennel/github_reporter"
|
11
11
|
require "kennel/subclass_tracking"
|
12
12
|
require "kennel/file_cache"
|
13
|
+
require "kennel/template_variables"
|
13
14
|
|
14
15
|
require "kennel/models/base"
|
16
|
+
|
17
|
+
# parts
|
15
18
|
require "kennel/models/monitor"
|
16
19
|
require "kennel/models/dash"
|
20
|
+
require "kennel/models/screen"
|
21
|
+
|
22
|
+
# settings
|
17
23
|
require "kennel/models/project"
|
18
24
|
require "kennel/models/team"
|
19
25
|
|
data/lib/kennel/models/dash.rb
CHANGED
@@ -2,7 +2,10 @@
|
|
2
2
|
module Kennel
|
3
3
|
module Models
|
4
4
|
class Dash < Base
|
5
|
-
|
5
|
+
include TemplateVariables
|
6
|
+
|
7
|
+
API_LIST_INCOMPLETE = true
|
8
|
+
settings :id, :title, :description, :graphs, :kennel_id, :graphs, :definitions
|
6
9
|
|
7
10
|
defaults(
|
8
11
|
id: -> { nil },
|
@@ -2,6 +2,7 @@
|
|
2
2
|
module Kennel
|
3
3
|
module Models
|
4
4
|
class Monitor < Base
|
5
|
+
API_LIST_INCOMPLETE = false
|
5
6
|
RENOTIFY_INTERVALS = [0, 10, 20, 30, 40, 50, 60, 90, 120, 180, 240, 300, 360, 720, 1440].freeze # minutes
|
6
7
|
QUERY_INTERVALS = ["1m", "5m", "10m", "15m", "30m", "1h", "2h", "4h", "24h"].freeze
|
7
8
|
METRIC_TYPES = ["query alert", "metric alert"].freeze
|
@@ -0,0 +1,109 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Kennel
|
3
|
+
module Models
|
4
|
+
class Screen < Base
|
5
|
+
include TemplateVariables
|
6
|
+
|
7
|
+
API_LIST_INCOMPLETE = true
|
8
|
+
|
9
|
+
settings :id, :board_title, :description, :widgets, :kennel_id
|
10
|
+
|
11
|
+
defaults(
|
12
|
+
description: -> { "" },
|
13
|
+
widgets: -> { [] },
|
14
|
+
id: -> { nil }
|
15
|
+
)
|
16
|
+
|
17
|
+
attr_reader :project
|
18
|
+
|
19
|
+
def initialize(project, *args)
|
20
|
+
@project = project
|
21
|
+
super(*args)
|
22
|
+
end
|
23
|
+
|
24
|
+
def self.api_resource
|
25
|
+
"screen"
|
26
|
+
end
|
27
|
+
|
28
|
+
def as_json
|
29
|
+
return @json if @json
|
30
|
+
@json = {
|
31
|
+
id: id,
|
32
|
+
board_title: "#{board_title}#{LOCK}",
|
33
|
+
description: description,
|
34
|
+
widgets: render_widgets,
|
35
|
+
template_variables: render_template_variables
|
36
|
+
}
|
37
|
+
@json
|
38
|
+
end
|
39
|
+
|
40
|
+
def diff(actual)
|
41
|
+
actual.delete(:disableCog)
|
42
|
+
actual.delete(:disableEditing)
|
43
|
+
actual.delete(:isIntegration)
|
44
|
+
actual.delete(:isShared)
|
45
|
+
actual.delete(:original_title)
|
46
|
+
actual.delete(:read_only)
|
47
|
+
actual.delete(:resource)
|
48
|
+
actual.delete(:title)
|
49
|
+
actual.delete(:title_edited)
|
50
|
+
actual.delete(:created_by)
|
51
|
+
actual.delete(:board_bgtype)
|
52
|
+
actual.delete(:height)
|
53
|
+
actual.delete(:width)
|
54
|
+
actual[:template_variables] ||= []
|
55
|
+
actual[:widgets].each { |w| w.delete :board_id }
|
56
|
+
super
|
57
|
+
end
|
58
|
+
|
59
|
+
def url(id)
|
60
|
+
Utils.path_to_url "/screen/#{id}"
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def render_widgets
|
66
|
+
widgets.map do |widget|
|
67
|
+
widget = widget_defaults(widget[:type]).merge(widget)
|
68
|
+
if tile = widget[:tile_def]
|
69
|
+
tile[:requests].each { |r| r[:conditional_formats] ||= [] }
|
70
|
+
tile[:autoscale] = true unless widget[:tile_def].key?(:autoscale)
|
71
|
+
end
|
72
|
+
widget
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
def widget_defaults(type)
|
77
|
+
basics = {
|
78
|
+
title_size: 16,
|
79
|
+
title_align: "left",
|
80
|
+
height: 20,
|
81
|
+
width: 30
|
82
|
+
}
|
83
|
+
|
84
|
+
custom =
|
85
|
+
case type
|
86
|
+
when "free_text"
|
87
|
+
{
|
88
|
+
font_size: "auto",
|
89
|
+
text_align: "left",
|
90
|
+
title_text: "",
|
91
|
+
title: true,
|
92
|
+
color: "#4d4d4d"
|
93
|
+
}
|
94
|
+
when "timeseries"
|
95
|
+
{
|
96
|
+
title: true,
|
97
|
+
legend: false,
|
98
|
+
legend_size: "0",
|
99
|
+
timeframe: "1h"
|
100
|
+
}
|
101
|
+
else
|
102
|
+
{}
|
103
|
+
end
|
104
|
+
|
105
|
+
basics.merge(custom)
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
109
|
+
end
|
data/lib/kennel/syncer.rb
CHANGED
@@ -62,7 +62,7 @@ module Kennel
|
|
62
62
|
id = a.fetch(:id)
|
63
63
|
|
64
64
|
if e = delete_matching_expected(a)
|
65
|
-
fill_details(a, cache) if
|
65
|
+
fill_details(a, cache) if e.class::API_LIST_INCOMPLETE
|
66
66
|
if diff = e.diff(a)
|
67
67
|
@update << [id, e, a, diff]
|
68
68
|
end
|
@@ -81,7 +81,8 @@ module Kennel
|
|
81
81
|
def fill_details(a, cache)
|
82
82
|
args = [a.fetch(:api_resource), a.fetch(:id)]
|
83
83
|
full = cache.fetch(args, a.fetch(:modified)) do
|
84
|
-
@api.show(*args)
|
84
|
+
result = @api.show(*args)
|
85
|
+
result[a.fetch(:api_resource).to_sym] || result # dashes are nested, others are not
|
85
86
|
end
|
86
87
|
a.merge!(full)
|
87
88
|
end
|
@@ -98,15 +99,15 @@ module Kennel
|
|
98
99
|
m.api_resource
|
99
100
|
end
|
100
101
|
|
101
|
-
api_resources.compact.uniq
|
102
|
+
Utils.parallel(api_resources.compact.uniq) do |api_resource|
|
102
103
|
# lookup monitors without adding unnecessary downtime information
|
103
104
|
results = @api.list(api_resource, with_downtimes: false)
|
104
|
-
if results.is_a?(Hash)
|
105
|
-
results = results.
|
105
|
+
if results.is_a?(Hash)
|
106
|
+
results = results[results.keys.first]
|
106
107
|
results.each { |r| r[:id] = Integer(r.fetch(:id)) }
|
107
108
|
end
|
108
109
|
results.each { |c| c[:api_resource] = api_resource }
|
109
|
-
end
|
110
|
+
end.flatten(1)
|
110
111
|
end
|
111
112
|
|
112
113
|
def ensure_all_ids_found
|
data/lib/kennel/tasks.rb
CHANGED
@@ -0,0 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
module Kennel
|
3
|
+
module TemplateVariables
|
4
|
+
def self.included(base)
|
5
|
+
base.settings :template_variables
|
6
|
+
base.defaults(template_variables: -> { [] })
|
7
|
+
end
|
8
|
+
|
9
|
+
private
|
10
|
+
|
11
|
+
def render_template_variables
|
12
|
+
template_variables.map do |v|
|
13
|
+
v.is_a?(String) ? { default: "*", prefix: v, name: v } : v
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/kennel/utils.rb
CHANGED
@@ -53,6 +53,18 @@ module Kennel
|
|
53
53
|
path
|
54
54
|
end
|
55
55
|
end
|
56
|
+
|
57
|
+
def parallel(items)
|
58
|
+
items.map do |item|
|
59
|
+
Thread.new do
|
60
|
+
begin
|
61
|
+
yield item
|
62
|
+
rescue StandardError => e
|
63
|
+
e
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end.map(&:value).each { |i| raise i if i.is_a?(StandardError) }
|
67
|
+
end
|
56
68
|
end
|
57
69
|
end
|
58
70
|
end
|
data/lib/kennel/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: kennel
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michael Grosser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-12-
|
11
|
+
date: 2017-12-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -52,11 +52,13 @@ files:
|
|
52
52
|
- lib/kennel/models/dash.rb
|
53
53
|
- lib/kennel/models/monitor.rb
|
54
54
|
- lib/kennel/models/project.rb
|
55
|
+
- lib/kennel/models/screen.rb
|
55
56
|
- lib/kennel/models/team.rb
|
56
57
|
- lib/kennel/progress.rb
|
57
58
|
- lib/kennel/subclass_tracking.rb
|
58
59
|
- lib/kennel/syncer.rb
|
59
60
|
- lib/kennel/tasks.rb
|
61
|
+
- lib/kennel/template_variables.rb
|
60
62
|
- lib/kennel/utils.rb
|
61
63
|
- lib/kennel/version.rb
|
62
64
|
homepage: https://github.com/grosser/kennel
|