Class: PuppetWebhook::Chatops

Inherits:
Object
  • Object
show all
Defined in:
lib/plugins/chatops.rb,
lib/plugins/chatops/slack.rb,
lib/plugins/chatops/rocketchat.rb

Overview

Chatops object for sending webhook notifications to chatops tools

Defined Under Namespace

Classes: Rocketchat, Slack

Instance Method Summary collapse

Constructor Details

#initialize(service, url, channel, user, options = {}) ⇒ Chatops

Returns a new instance of Chatops.



4
5
6
7
8
9
10
# File 'lib/plugins/chatops.rb', line 4

def initialize(service, url, channel, user, options = {})
  @service = service
  @url = url
  @channel = channel
  @user = user
  @args = options
end

Instance Method Details

#notify(message) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/plugins/chatops.rb', line 12

def notify(message)
  case @service
  when 'slack'
    require 'plugins/chatops/slack'
    LOGGER.info("Sending Slack webhook message to #{@url}")
    Chatops::Slack.new(
      @channel,
      @url,
      @user,
      message,
      http_options: @args[:http_options] || {},
      icon_emoji: @args[:icon_emoji]
    ).notify
  when 'rocketchat'
    require 'plugins/chatops/rocketchat'
    LOGGER.info("Sending Rocket.Chat webhook message to #{@url}")
    Chatops::Rocketchat.new(
      @channel,
      @url,
      @user,
      message,
      http_options: @args[:http_options] || {},
      icon_emoji: @args[:icon_emoji]
    ).notify
  else
    LOGGER.error("Service #{@service} is not currently supported")
  end
end