slack_webhook_logger 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/Gemfile +2 -0
- data/Gemfile.lock +39 -27
- data/README.md +1 -1
- data/lib/generators/templates/slack_webhook_logger.rb +4 -0
- data/lib/slack_webhook_logger.rb +3 -0
- data/lib/slack_webhook_logger/formatter.rb +28 -24
- data/lib/slack_webhook_logger/request_io.rb +7 -3
- data/lib/slack_webhook_logger/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3a67f82f3cd336bb5ca39f8bb7fd51f97a90f96969eee3cb8cc11df2b63cd8d4
|
|
4
|
+
data.tar.gz: 5e014b2630c44cc5766e6c6aff899bd9718d5a8ca5491e2ea1c9b54d80d94bf9
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9fa33bcbf3d67ccaff05cb250621bed1be5bc9de00b5e8df75b3670e043f9b0acf5a5dc660d1089b378a2019ae50040e65c19e20139ccf98e8db46cc18e95207
|
|
7
|
+
data.tar.gz: 26086426ca61764a6d004e513a6a5e83aec73e7a08467c57d1d9866d330bafb25473fee650a5363ee73d745bdb0aea68ea3e62ef9fc819b4e85d7038984a55db
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
|
@@ -1,37 +1,43 @@
|
|
|
1
1
|
PATH
|
|
2
2
|
remote: .
|
|
3
3
|
specs:
|
|
4
|
-
slack_webhook_logger (0.
|
|
4
|
+
slack_webhook_logger (0.2.0)
|
|
5
5
|
activesupport (>= 5.0, < 7.0)
|
|
6
6
|
railties (>= 5.0, < 7.0)
|
|
7
7
|
|
|
8
8
|
GEM
|
|
9
9
|
remote: https://rubygems.org/
|
|
10
10
|
specs:
|
|
11
|
-
actionpack (
|
|
12
|
-
actionview (=
|
|
13
|
-
activesupport (=
|
|
14
|
-
rack (~> 2.0, >= 2.0.
|
|
11
|
+
actionpack (6.1.0)
|
|
12
|
+
actionview (= 6.1.0)
|
|
13
|
+
activesupport (= 6.1.0)
|
|
14
|
+
rack (~> 2.0, >= 2.0.9)
|
|
15
15
|
rack-test (>= 0.6.3)
|
|
16
16
|
rails-dom-testing (~> 2.0)
|
|
17
|
-
rails-html-sanitizer (~> 1.0, >= 1.0
|
|
18
|
-
actionview (
|
|
19
|
-
activesupport (=
|
|
17
|
+
rails-html-sanitizer (~> 1.0, >= 1.2.0)
|
|
18
|
+
actionview (6.1.0)
|
|
19
|
+
activesupport (= 6.1.0)
|
|
20
20
|
builder (~> 3.1)
|
|
21
21
|
erubi (~> 1.4)
|
|
22
22
|
rails-dom-testing (~> 2.0)
|
|
23
|
-
rails-html-sanitizer (~> 1.
|
|
24
|
-
activesupport (
|
|
23
|
+
rails-html-sanitizer (~> 1.1, >= 1.2.0)
|
|
24
|
+
activesupport (6.1.0)
|
|
25
25
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
|
26
|
-
i18n (>=
|
|
27
|
-
minitest (
|
|
28
|
-
tzinfo (~>
|
|
26
|
+
i18n (>= 1.6, < 2)
|
|
27
|
+
minitest (>= 5.1)
|
|
28
|
+
tzinfo (~> 2.0)
|
|
29
|
+
zeitwerk (~> 2.3)
|
|
30
|
+
addressable (2.7.0)
|
|
31
|
+
public_suffix (>= 2.0.2, < 5.0)
|
|
29
32
|
ast (2.4.1)
|
|
30
33
|
awesome_print (1.8.0)
|
|
31
34
|
builder (3.2.4)
|
|
32
35
|
concurrent-ruby (1.1.7)
|
|
36
|
+
crack (0.4.5)
|
|
37
|
+
rexml
|
|
33
38
|
crass (1.0.6)
|
|
34
39
|
erubi (1.10.0)
|
|
40
|
+
hashdiff (1.0.1)
|
|
35
41
|
i18n (1.8.5)
|
|
36
42
|
concurrent-ruby (~> 1.0)
|
|
37
43
|
loofah (2.8.0)
|
|
@@ -43,8 +49,9 @@ GEM
|
|
|
43
49
|
nokogiri (1.10.10)
|
|
44
50
|
mini_portile2 (~> 2.4.0)
|
|
45
51
|
parallel (1.20.1)
|
|
46
|
-
parser (
|
|
52
|
+
parser (3.0.0.0)
|
|
47
53
|
ast (~> 2.4.1)
|
|
54
|
+
public_suffix (4.0.6)
|
|
48
55
|
rack (2.2.3)
|
|
49
56
|
rack-test (1.1.0)
|
|
50
57
|
rack (>= 1.0, < 3)
|
|
@@ -53,17 +60,17 @@ GEM
|
|
|
53
60
|
nokogiri (>= 1.6)
|
|
54
61
|
rails-html-sanitizer (1.3.0)
|
|
55
62
|
loofah (~> 2.3)
|
|
56
|
-
railties (
|
|
57
|
-
actionpack (=
|
|
58
|
-
activesupport (=
|
|
63
|
+
railties (6.1.0)
|
|
64
|
+
actionpack (= 6.1.0)
|
|
65
|
+
activesupport (= 6.1.0)
|
|
59
66
|
method_source
|
|
60
67
|
rake (>= 0.8.7)
|
|
61
|
-
thor (
|
|
68
|
+
thor (~> 1.0)
|
|
62
69
|
rainbow (3.0.0)
|
|
63
70
|
rake (12.3.3)
|
|
64
|
-
regexp_parser (2.0.
|
|
71
|
+
regexp_parser (2.0.3)
|
|
65
72
|
rexml (3.2.4)
|
|
66
|
-
rubocop (1.
|
|
73
|
+
rubocop (1.7.0)
|
|
67
74
|
parallel (~> 1.10)
|
|
68
75
|
parser (>= 2.7.1.5)
|
|
69
76
|
rainbow (>= 2.2.2, < 4.0)
|
|
@@ -74,12 +81,12 @@ GEM
|
|
|
74
81
|
unicode-display_width (>= 1.4.0, < 2.0)
|
|
75
82
|
rubocop-ast (1.3.0)
|
|
76
83
|
parser (>= 2.7.1.5)
|
|
77
|
-
rubocop-minitest (0.10.
|
|
78
|
-
rubocop (>= 0.87)
|
|
84
|
+
rubocop-minitest (0.10.2)
|
|
85
|
+
rubocop (>= 0.87, < 2.0)
|
|
79
86
|
rubocop-performance (1.9.1)
|
|
80
87
|
rubocop (>= 0.90.0, < 2.0)
|
|
81
88
|
rubocop-ast (>= 0.4.0)
|
|
82
|
-
rubocop-rails (2.9.
|
|
89
|
+
rubocop-rails (2.9.1)
|
|
83
90
|
activesupport (>= 4.2.0)
|
|
84
91
|
rack (>= 1.1)
|
|
85
92
|
rubocop (>= 0.90.0, < 2.0)
|
|
@@ -91,12 +98,16 @@ GEM
|
|
|
91
98
|
rubocop-performance
|
|
92
99
|
rubocop-rails
|
|
93
100
|
rubocop-rake
|
|
94
|
-
ruby-progressbar (1.
|
|
101
|
+
ruby-progressbar (1.11.0)
|
|
95
102
|
thor (1.0.1)
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
thread_safe (~> 0.1)
|
|
103
|
+
tzinfo (2.0.4)
|
|
104
|
+
concurrent-ruby (~> 1.0)
|
|
99
105
|
unicode-display_width (1.7.0)
|
|
106
|
+
webmock (3.11.0)
|
|
107
|
+
addressable (>= 2.3.6)
|
|
108
|
+
crack (>= 0.3.2)
|
|
109
|
+
hashdiff (>= 0.4.0, < 2.0.0)
|
|
110
|
+
zeitwerk (2.4.2)
|
|
100
111
|
|
|
101
112
|
PLATFORMS
|
|
102
113
|
ruby
|
|
@@ -109,6 +120,7 @@ DEPENDENCIES
|
|
|
109
120
|
rubocop-performance (~> 1.9)
|
|
110
121
|
rubocop-standard (~> 5.1)
|
|
111
122
|
slack_webhook_logger!
|
|
123
|
+
webmock (~> 3.11)
|
|
112
124
|
|
|
113
125
|
BUNDLED WITH
|
|
114
126
|
2.1.4
|
data/README.md
CHANGED
|
@@ -38,4 +38,4 @@ end
|
|
|
38
38
|
|
|
39
39
|
## Configuration
|
|
40
40
|
|
|
41
|
-
You can change the log level or the format of the logging text if you wish. See the generated slack_webhook_logger.rb file for more
|
|
41
|
+
You can change the log level or the format of the logging text if you wish. See the generated slack_webhook_logger.rb file for more information on that.
|
|
@@ -14,4 +14,8 @@ SlackWebhookLogger.setup do |config|
|
|
|
14
14
|
# The formatter must construct a JSON blob that adheres to Slack's expected
|
|
15
15
|
# POST payload for `chat.postMessage`: https://api.slack.com/methods/chat.postMessage
|
|
16
16
|
# config.formatter = SomeOtherFormatter.new
|
|
17
|
+
|
|
18
|
+
# You can provide an array of regular expressions to ignore certain messages
|
|
19
|
+
# from being sent to Slack. This is optional.
|
|
20
|
+
# config.ignore_patterns = []
|
|
17
21
|
end
|
data/lib/slack_webhook_logger.rb
CHANGED
|
@@ -16,6 +16,7 @@ module SlackWebhookLogger
|
|
|
16
16
|
mattr_accessor :webhook_url
|
|
17
17
|
mattr_accessor :level
|
|
18
18
|
mattr_accessor :formatter
|
|
19
|
+
mattr_accessor :ignore_patterns
|
|
19
20
|
|
|
20
21
|
# Used internally
|
|
21
22
|
mattr_reader :webhook_uri
|
|
@@ -37,6 +38,8 @@ module SlackWebhookLogger
|
|
|
37
38
|
https.verify_mode = OpenSSL::SSL::VERIFY_PEER
|
|
38
39
|
|
|
39
40
|
@@https = https
|
|
41
|
+
|
|
42
|
+
@@ignore_patterns ||= []
|
|
40
43
|
end
|
|
41
44
|
# rubocop:enable Style/ClassVars
|
|
42
45
|
end
|
|
@@ -5,7 +5,7 @@ module SlackWebhookLogger
|
|
|
5
5
|
attr_writer :format
|
|
6
6
|
|
|
7
7
|
def format
|
|
8
|
-
@format ||= proc
|
|
8
|
+
@format ||= proc do |severity, time, _progname, msg|
|
|
9
9
|
heading = case severity
|
|
10
10
|
when 'FATAL'
|
|
11
11
|
"📛 *#{severity}*"
|
|
@@ -27,35 +27,39 @@ module SlackWebhookLogger
|
|
|
27
27
|
#{msg2str(msg)}
|
|
28
28
|
MSG
|
|
29
29
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
blocks: [
|
|
33
|
-
{
|
|
34
|
-
type: 'section',
|
|
35
|
-
text: {
|
|
36
|
-
type: 'mrkdwn',
|
|
37
|
-
text: title
|
|
38
|
-
}
|
|
39
|
-
},
|
|
40
|
-
{
|
|
41
|
-
type: 'divider'
|
|
42
|
-
},
|
|
43
|
-
{
|
|
44
|
-
type: 'section',
|
|
45
|
-
text: {
|
|
46
|
-
"type": 'plain_text',
|
|
47
|
-
"text": text
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
]
|
|
51
|
-
}
|
|
52
|
-
}
|
|
30
|
+
slackify(title, text)
|
|
31
|
+
end
|
|
53
32
|
end
|
|
54
33
|
|
|
55
34
|
def call(severity, time, progname, msg)
|
|
56
35
|
format.call(severity, time, progname, msg)
|
|
57
36
|
end
|
|
58
37
|
|
|
38
|
+
def slackify(title, text)
|
|
39
|
+
{
|
|
40
|
+
text: [title, text].join("\n").to_s,
|
|
41
|
+
blocks: [
|
|
42
|
+
{
|
|
43
|
+
type: 'section',
|
|
44
|
+
text: {
|
|
45
|
+
type: 'mrkdwn',
|
|
46
|
+
text: title
|
|
47
|
+
}
|
|
48
|
+
},
|
|
49
|
+
{
|
|
50
|
+
type: 'divider'
|
|
51
|
+
},
|
|
52
|
+
{
|
|
53
|
+
type: 'section',
|
|
54
|
+
text: {
|
|
55
|
+
"type": 'plain_text',
|
|
56
|
+
"text": text
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
]
|
|
60
|
+
}
|
|
61
|
+
end
|
|
62
|
+
|
|
59
63
|
private def msg2str(msg)
|
|
60
64
|
case msg
|
|
61
65
|
when ::String
|
|
@@ -9,11 +9,15 @@ module SlackWebhookLogger
|
|
|
9
9
|
true
|
|
10
10
|
end
|
|
11
11
|
|
|
12
|
-
def self.write(
|
|
13
|
-
return if
|
|
12
|
+
def self.write(hash)
|
|
13
|
+
return if hash.blank?
|
|
14
|
+
|
|
15
|
+
return if SlackWebhookLogger.ignore_patterns.any? { |ignore_pattern| hash[:text].match(ignore_pattern) }
|
|
16
|
+
|
|
17
|
+
payload = hash.to_json
|
|
14
18
|
|
|
15
19
|
req = Net::HTTP::Post.new(SlackWebhookLogger.webhook_uri.path)
|
|
16
|
-
req.set_form_data(payload: payload
|
|
20
|
+
req.set_form_data(payload: payload)
|
|
17
21
|
SlackWebhookLogger.https.request(req)
|
|
18
22
|
end
|
|
19
23
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: slack_webhook_logger
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Garen J. Torikian
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-12-
|
|
11
|
+
date: 2020-12-31 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: activesupport
|