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: []) ⇒ Object
126
127
128
129
130
131
132
133
|
# File 'lib/mihari/emitters/slack.rb', line 126
def emit(title:, description:, artifacts:, tags: [])
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
102
103
104
|
# File 'lib/mihari/emitters/slack.rb', line 102
def notifier
@notifier ||= Notifiers::Slack.new
end
|
#to_attachments(artifacts) ⇒ Object
110
111
112
113
114
|
# File 'lib/mihari/emitters/slack.rb', line 110
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
116
117
118
119
120
121
122
123
124
|
# File 'lib/mihari/emitters/slack.rb', line 116
def to_text(title:, description:, tags: [])
tags = ["N/A"] if tags.empty?
[
"*#{title}*",
"*Desc.*: #{description}",
"*Tags*: #{tags.join(', ')}",
].join("\n")
end
|
#valid? ⇒ Boolean
106
107
108
|
# File 'lib/mihari/emitters/slack.rb', line 106
def valid?
notifier.valid?
end
|