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_values, #configured?
Instance Method Details
#emit(title:, description:, artifacts:, tags: [], **_options) ⇒ Object
139
140
141
142
143
144
145
146
|
# File 'lib/mihari/emitters/slack.rb', line 139
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
115
116
117
|
# File 'lib/mihari/emitters/slack.rb', line 115
def notifier
@notifier ||= Notifiers::Slack.new
end
|
#to_attachments(artifacts) ⇒ Object
123
124
125
126
127
|
# File 'lib/mihari/emitters/slack.rb', line 123
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
129
130
131
132
133
134
135
136
137
|
# File 'lib/mihari/emitters/slack.rb', line 129
def to_text(title:, description:, tags: [])
tags = ["N/A"] if tags.empty?
[
"*#{title}*",
"*Desc.*: #{description}",
"*Tags*: #{tags.join(", ")}"
].join("\n")
end
|
#valid? ⇒ Boolean
119
120
121
|
# File 'lib/mihari/emitters/slack.rb', line 119
def valid?
notifier.valid?
end
|