class PasswordExpirationNotifier::Slack

Public Class Methods

new(conf) click to toggle source
# File lib/password_expiration_notifier/slack.rb, line 6
def initialize(conf)
  @conf = conf
end

Public Instance Methods

notify_to(user) click to toggle source
# 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