Class: Mihari::Notifiers::Slack

Inherits:
Base
  • Object
show all
Defined in:
lib/mihari/notifiers/slack.rb

Constant Summary collapse

SLACK_WEBHOOK_URL_KEY =
"SLACK_WEBHOOK_URL"
SLACK_CHANNEL_KEY =
"SLACK_CHANNEL"

Instance Method Summary collapse

Instance Method Details

#notify(text:, attachments: []) ⇒ Object



25
26
27
28
# File 'lib/mihari/notifiers/slack.rb', line 25

def notify(text:, attachments: [])
  notifier = ::Slack::Notifier.new(slack_webhook_url, channel: slack_channel)
  notifier.post(text: text, attachments: attachments)
end

#slack_channelObject



9
10
11
# File 'lib/mihari/notifiers/slack.rb', line 9

def slack_channel
  ENV.fetch SLACK_CHANNEL_KEY, "#general"
end

#slack_webhook_urlObject



13
14
15
# File 'lib/mihari/notifiers/slack.rb', line 13

def slack_webhook_url
  ENV.fetch SLACK_WEBHOOK_URL_KEY
end

#slack_webhook_url?Boolean

Returns:

  • (Boolean)


17
18
19
# File 'lib/mihari/notifiers/slack.rb', line 17

def slack_webhook_url?
  ENV.key? SLACK_WEBHOOK_URL_KEY
end

#valid?Boolean

Returns:

  • (Boolean)


21
22
23
# File 'lib/mihari/notifiers/slack.rb', line 21

def valid?
  slack_webhook_url?
end