Class: PasswordExpirationNotifier::Slack

Inherits:
Object
  • Object
show all
Defined in:
lib/password_expiration_notifier/slack.rb

Instance Method Summary collapse

Constructor Details

#initialize(conf) ⇒ Slack

Returns a new instance of Slack.



6
7
8
# File 'lib/password_expiration_notifier/slack.rb', line 6

def initialize(conf)
  @conf = conf
end

Instance Method Details

#notify_to(user) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/password_expiration_notifier/slack.rb', line 10

def notify_to(user)
  attr = user.last
  client = SlackNotify::Client.new(
    webhook_url: @conf.slack.webhook_url,
    channel: "@#{attr[:samaccountname]}",
    icon_url: @conf.slack.icon_url,
    icon_emoji: @conf.slack.icon_emoji,
    link_names: @conf.slack.link_names
  )
  message = "Your domain account #{attr[:samaccountname]}'s password expire at #{attr[:expire_at]}. Please update your password."
  unless @conf.dry_run
    begin
      client.notify(message)
    rescue SlackNotify::Error => e
      return "SlackNotify::Error: #{message} #{e}"
    end
  end
  return message
end