Class: Mihari::Emitters::Slack
- Inherits:
-
Base
show all
- Defined in:
- lib/mihari/emitters/slack.rb
Constant Summary
collapse
- DEFAULT_CHANNEL =
"#general"
- DEFAULT_USERNAME =
"Mihari"
Concerns::Retriable::DEFAULT_CONDITION, Concerns::Retriable::RETRIABLE_ERRORS
Instance Attribute Summary collapse
Attributes inherited from Base
#rule
Attributes inherited from Actor
#options
Instance Method Summary
collapse
Methods inherited from Base
inherited, #parallel?, #result
Methods inherited from Actor
configuration_keys, key, key_aliases, keys, #result, #retry_exponential_backoff, #retry_interval, #retry_times, #timeout, type, #validate_configuration!
#retry_on_error
#configuration_keys?
Constructor Details
#initialize(rule:, options: nil, **params) ⇒ Slack
Returns a new instance of Slack.
Instance Attribute Details
135
136
137
|
# File 'lib/mihari/emitters/slack.rb', line 135
def artifacts
@artifacts
end
|
#channel ⇒ String
129
130
131
|
# File 'lib/mihari/emitters/slack.rb', line 129
def channel
@channel
end
|
#username ⇒ String
132
133
134
|
# File 'lib/mihari/emitters/slack.rb', line 132
def username
@username
end
|
#webhook_url ⇒ String?
126
127
128
|
# File 'lib/mihari/emitters/slack.rb', line 126
def webhook_url
@webhook_url
end
|
Instance Method Details
191
192
193
|
# File 'lib/mihari/emitters/slack.rb', line 191
def attachments
artifacts.map { |artifact| Attachment.new(data: artifact.data, data_type: artifact.data_type).to_a }.flatten
end
|
#call(artifacts) ⇒ Object
213
214
215
216
217
218
219
|
# File 'lib/mihari/emitters/slack.rb', line 213
def call(artifacts)
return if artifacts.empty?
@artifacts = artifacts
notifier.post(text:, attachments:, mrkdwn: true)
end
|
164
165
166
|
# File 'lib/mihari/emitters/slack.rb', line 164
def configured?
webhook_url?
end
|
#notifier ⇒ ::Slack::Notifier
178
179
180
181
182
183
184
|
# File 'lib/mihari/emitters/slack.rb', line 178
def notifier
@notifier ||= lambda do
return ::Slack::Notifier.new(webhook_url, channel:, username:) if timeout.nil?
::Slack::Notifier.new(webhook_url, channel:, username:, http_options: {timeout:})
end.call
end
|
#target ⇒ String
171
172
173
|
# File 'lib/mihari/emitters/slack.rb', line 171
def target
channel
end
|
#text ⇒ String
200
201
202
203
204
205
206
207
208
|
# File 'lib/mihari/emitters/slack.rb', line 200
def text
tags = rule.tags.map(&:name)
tags = ["N/A"] if tags.empty?
[
"*#{rule.title}*",
"*Desc.*: #{rule.description}",
"*Tags*: #{tags.join(", ")}"
].join("\n")
end
|
#webhook_url? ⇒ Boolean
157
158
159
|
# File 'lib/mihari/emitters/slack.rb', line 157
def webhook_url?
!webhook_url.nil?
end
|