Class: Mihari::Emitters::Slack
- Inherits:
-
Base
- Object
- Base
- Mihari::Emitters::Slack
show all
- Defined in:
- lib/mihari/emitters/slack.rb
Instance Method Summary
collapse
Methods inherited from Base
inherited, #run
Methods included from Retriable
#retry_on_error
#configuration_status, #configured?
Instance Method Details
#emit(title:, description:, artifacts:, tags: [], **_options) ⇒ Object
128
129
130
131
132
133
134
135
|
# File 'lib/mihari/emitters/slack.rb', line 128
def emit(title:, description:, artifacts:, tags: [], **_options)
return if artifacts.empty?
attachments = to_attachments(artifacts)
text = to_text(title: title, description: description, tags: tags)
notifier.notify(text: text, attachments: attachments)
end
|
#notifier ⇒ Object
104
105
106
|
# File 'lib/mihari/emitters/slack.rb', line 104
def notifier
@notifier ||= Notifiers::Slack.new
end
|
#to_attachments(artifacts) ⇒ Object
112
113
114
115
116
|
# File 'lib/mihari/emitters/slack.rb', line 112
def to_attachments(artifacts)
artifacts.map do |artifact|
Attachment.new(data: artifact.data, data_type: artifact.data_type).to_a
end.flatten
end
|
#to_text(title:, description:, tags: []) ⇒ Object
118
119
120
121
122
123
124
125
126
|
# File 'lib/mihari/emitters/slack.rb', line 118
def to_text(title:, description:, tags: [])
tags = ["N/A"] if tags.empty?
[
"*#{title}*",
"*Desc.*: #{description}",
"*Tags*: #{tags.join(', ')}",
].join("\n")
end
|
#valid? ⇒ Boolean
108
109
110
|
# File 'lib/mihari/emitters/slack.rb', line 108
def valid?
notifier.valid?
end
|