sql-jarvis 2.1.5 → 2.1.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/controllers/blazer/checks_controller.rb +23 -2
- data/app/controllers/blazer/queries_controller.rb +9 -1
- data/app/mailers/blazer/slack_notifier.rb +27 -9
- data/app/models/blazer/check.rb +22 -0
- data/app/views/blazer/checks/_form.html.haml +10 -0
- data/lib/blazer/engine.rb +1 -0
- data/lib/blazer/version.rb +1 -1
- data/lib/blazer.rb +2 -0
- data/lib/generators/blazer/templates/config.yml.tt +3 -0
- data/lib/generators/blazer/templates/install.rb.tt +1 -0
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cfb54328ee2d275f1aab831bdc7d52fddff2b7f52231774a1723aa25fcac8a82
|
4
|
+
data.tar.gz: a7dd3acceb9459afcaaf946336fb23c4299e5b341aad2e169ba0cc074039e38c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 602a0748fcb3f50223cb5450d10dce80e03fd10f3e1d52451880b5fa3040f24f7114fa3b5debce7ee76cf47f6f9f6f10ec24e4257b7f098adb534ecc0d004e19
|
7
|
+
data.tar.gz: 649a9f8b5cedbcde958436a7694a4ede682dab551416ed7646456787d4122af780250ac465c9d31a0f8d3253c63bc454948e47a3e7d352d686d46ff9707e8ae7
|
@@ -1,6 +1,8 @@
|
|
1
1
|
module Blazer
|
2
2
|
class ChecksController < BaseController
|
3
3
|
before_action :set_check, only: [:edit, :update, :destroy, :run]
|
4
|
+
before_action :set_new_check, only: [:new]
|
5
|
+
before_action :set_accessible, only: [:new, :edit]
|
4
6
|
|
5
7
|
def index
|
6
8
|
state_order = [nil, "disabled", "error", "timed out", "failing", "passing"]
|
@@ -9,7 +11,6 @@ module Blazer
|
|
9
11
|
end
|
10
12
|
|
11
13
|
def new
|
12
|
-
@check = Blazer::Check.new(query_id: params[:query_id])
|
13
14
|
end
|
14
15
|
|
15
16
|
def create
|
@@ -46,11 +47,31 @@ module Blazer
|
|
46
47
|
private
|
47
48
|
|
48
49
|
def check_params
|
49
|
-
params.require(:check).permit(:query_id, :emails, :slack_channels, :invert, :check_type, :schedule)
|
50
|
+
params.require(:check).permit(:query_id, :emails, :slack_channels, :invert, :check_type, :schedule, slack_members: [])
|
50
51
|
end
|
51
52
|
|
52
53
|
def set_check
|
53
54
|
@check = Blazer::Check.find(params[:id])
|
54
55
|
end
|
56
|
+
|
57
|
+
def set_new_check
|
58
|
+
@check = Blazer::Check.new(query_id: params[:query_id])
|
59
|
+
end
|
60
|
+
|
61
|
+
def set_accessible
|
62
|
+
existed_members = @check&.slack_members.presence || []
|
63
|
+
@slack_mentions ||= get_slack_mentions + existed_members.each_with_object([]) { |m, list| list << [m, m] if m.present? }
|
64
|
+
ensure
|
65
|
+
@slack_mentions ||= []
|
66
|
+
end
|
67
|
+
|
68
|
+
def get_slack_mentions
|
69
|
+
return [] unless Blazer.settings.key?('slack_mentions')
|
70
|
+
Blazer::RunStatement.new.perform(Blazer.data_sources[@check.query&.data_source], Blazer.settings['slack_mentions'], {}).rows.map do |row|
|
71
|
+
[row.last, "[#{row.first}] #{row.second} - ##{row.last}"]
|
72
|
+
end
|
73
|
+
rescue
|
74
|
+
[]
|
75
|
+
end
|
55
76
|
end
|
56
77
|
end
|
@@ -362,8 +362,16 @@ module Blazer
|
|
362
362
|
|
363
363
|
def get_assignees
|
364
364
|
return [] unless Blazer.settings.key?('assignees')
|
365
|
+
|
365
366
|
Blazer::RunStatement.new.perform(@data_source, Blazer.settings['assignees'], {}).rows.map do |row|
|
366
|
-
|
367
|
+
case row.size
|
368
|
+
when 2
|
369
|
+
[row.first, row.last.to_s.titleize]
|
370
|
+
when 3
|
371
|
+
[row.first, "#{row.second.to_s.titleize} - #{row.last}"]
|
372
|
+
else
|
373
|
+
[row.first, row.first]
|
374
|
+
end
|
367
375
|
end
|
368
376
|
rescue
|
369
377
|
[]
|
@@ -28,20 +28,38 @@ module Blazer
|
|
28
28
|
end
|
29
29
|
|
30
30
|
def self.failing_checks(channel, checks)
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
31
|
+
all_mentions = []
|
32
|
+
attachments = checks.map do |check|
|
33
|
+
mentions = check.slack_mention_tags
|
34
|
+
all_mentions << mentions
|
35
|
+
result = Blazer.data_sources[check.query.data_source].run_statement(check.query.statement)
|
36
|
+
{
|
37
|
+
mrkdwn_in: %w[title text],
|
38
|
+
title: "<#{query_url(check.query_id)}|#{escape(check.query.name)}> #{escape(check.state)} #{mentions.join(' ')}",
|
39
|
+
text: "#{Blazer.slack_preview_items_number} first rows `#{result.columns.first}: #{result.rows.first(Blazer.slack_preview_items_number).map(&:first).join(', ')}`",
|
40
|
+
color: 'warning'
|
41
|
+
}
|
42
|
+
end
|
35
43
|
|
36
44
|
payload = {
|
37
45
|
channel: channel,
|
38
|
-
|
46
|
+
blocks: [
|
39
47
|
{
|
40
|
-
|
41
|
-
text:
|
42
|
-
|
48
|
+
type: 'header',
|
49
|
+
text: {
|
50
|
+
type: 'plain_text',
|
51
|
+
text: escape("#{pluralize(checks.size, 'Check')} Failing")
|
52
|
+
}
|
53
|
+
},
|
54
|
+
{
|
55
|
+
type: 'section',
|
56
|
+
text: {
|
57
|
+
type: 'mrkdwn',
|
58
|
+
text: "Hey #{all_mentions.uniq.join(' ')}, there are some failing checks:"
|
59
|
+
}
|
43
60
|
}
|
44
|
-
]
|
61
|
+
],
|
62
|
+
attachments: attachments
|
45
63
|
}
|
46
64
|
|
47
65
|
post(Blazer.slack_webhook_url, payload)
|
data/app/models/blazer/check.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Blazer
|
2
2
|
class Check < Record
|
3
|
+
serialize :slack_members, Array
|
4
|
+
|
3
5
|
belongs_to :creator, Blazer::BELONGS_TO_OPTIONAL.merge(class_name: Blazer.user_class.to_s) if Blazer.user_class
|
4
6
|
belongs_to :query
|
5
7
|
|
@@ -22,6 +24,26 @@ module Blazer
|
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
27
|
+
def slack_mention_tags
|
28
|
+
tags = []
|
29
|
+
slack_members.each do |code|
|
30
|
+
case code
|
31
|
+
when /^U/
|
32
|
+
tags << "<@#{code.strip}>"
|
33
|
+
when /^S/
|
34
|
+
tags << "<!subteam^#{code.strip}>"
|
35
|
+
when 'here'
|
36
|
+
tags << '<!here|here>'
|
37
|
+
when 'channel'
|
38
|
+
tags << '<!channel>'
|
39
|
+
when 'everyone'
|
40
|
+
tags << '<!everyone>'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
tags.uniq
|
45
|
+
end
|
46
|
+
|
25
47
|
def update_state(result)
|
26
48
|
check_type =
|
27
49
|
if respond_to?(:check_type)
|
@@ -42,6 +42,10 @@
|
|
42
42
|
.form-group
|
43
43
|
= f.label :slack_channels
|
44
44
|
= f.text_field :slack_channels, placeholder: "Optional, comma separated", class: "form-control"
|
45
|
+
.form-group
|
46
|
+
= f.label :slack_members
|
47
|
+
= f.collection_select :slack_members, @slack_mentions, :first, :last, {}, { placeholder: "User, Users group Slack ID", class: "form-control", multiple: true }
|
48
|
+
%p.text-muted Slack members: can select or enter new user/user_group Slack ID. It also supports special mentions: channel, everyone, here.
|
45
49
|
%p.text-muted
|
46
50
|
Emails #{Blazer.slack? ? "and Slack notifications " : nil}are sent when a check starts failing, and when it starts passing again.
|
47
51
|
%p
|
@@ -49,3 +53,9 @@
|
|
49
53
|
= link_to "Delete", check_path(@check), method: :delete, "data-confirm" => "Are you sure?", class: "btn btn-danger"
|
50
54
|
= f.submit "Save", class: "btn btn-success"
|
51
55
|
= link_to "Back", :back, class: "btn btn-link"
|
56
|
+
:javascript
|
57
|
+
$(document).ready(function() {
|
58
|
+
$('#check_slack_members').select2({
|
59
|
+
tags: true,
|
60
|
+
});
|
61
|
+
});
|
data/lib/blazer/engine.rb
CHANGED
@@ -41,6 +41,7 @@ module Blazer
|
|
41
41
|
Blazer.images = Blazer.settings["images"] || false
|
42
42
|
Blazer.override_csp = Blazer.settings["override_csp"] || false
|
43
43
|
Blazer.slack_webhook_url = Blazer.settings["slack_webhook_url"] || ENV["BLAZER_SLACK_WEBHOOK_URL"]
|
44
|
+
Blazer.slack_preview_items_number = Blazer.settings["slack_preview_items_number"] || 25
|
44
45
|
end
|
45
46
|
end
|
46
47
|
end
|
data/lib/blazer/version.rb
CHANGED
data/lib/blazer.rb
CHANGED
@@ -61,8 +61,11 @@ audit: true
|
|
61
61
|
# mapbox_access_token: <%= ENV["MAPBOX_ACCESS_TOKEN"] %>
|
62
62
|
|
63
63
|
# assignees: 'SELECT id, name FROM users ORDER BY id ASC'
|
64
|
+
# slack_mentions: 'SELECT 'User' as type, name as title, ext_code as code FROM users ORDER BY id ASC'
|
64
65
|
# teams: 'SELECT id, name FROM teams'
|
65
66
|
|
67
|
+
slack_preview_items_number: 25
|
68
|
+
|
66
69
|
check_schedules:
|
67
70
|
- "1 day"
|
68
71
|
- "1 hour"
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sql-jarvis
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrew Kane
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-06-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: railties
|
@@ -150,7 +150,7 @@ dependencies:
|
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '0'
|
153
|
-
description:
|
153
|
+
description:
|
154
154
|
email: andrew@chartkick.com
|
155
155
|
executables: []
|
156
156
|
extensions: []
|
@@ -270,7 +270,7 @@ homepage: https://github.com/ThanhKhoaIT/blazer
|
|
270
270
|
licenses:
|
271
271
|
- MIT
|
272
272
|
metadata: {}
|
273
|
-
post_install_message:
|
273
|
+
post_install_message:
|
274
274
|
rdoc_options: []
|
275
275
|
require_paths:
|
276
276
|
- lib
|
@@ -285,8 +285,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
285
285
|
- !ruby/object:Gem::Version
|
286
286
|
version: '0'
|
287
287
|
requirements: []
|
288
|
-
rubygems_version: 3.
|
289
|
-
signing_key:
|
288
|
+
rubygems_version: 3.2.3
|
289
|
+
signing_key:
|
290
290
|
specification_version: 4
|
291
291
|
summary: Fork from ankane! Explore your data with SQL. Easily create charts and dashboards,
|
292
292
|
and share them with your team.
|