puppet_webhook 1.3.0 → 1.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +9 -1
- data/README.md +124 -0
- data/config/app.yml +7 -2
- data/lib/helpers/deployments.rb +8 -7
- data/lib/helpers/tasks.rb +40 -53
- data/lib/plugins/chatops/rocketchat.rb +60 -0
- data/lib/plugins/chatops/slack.rb +60 -0
- data/lib/plugins/chatops.rb +41 -0
- data/lib/puppet_webhook.rb +13 -5
- metadata +19 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 906dfa13bf22e727fd153eff673db49f0122e7fa5417ef213177f9bb5e210abc
|
4
|
+
data.tar.gz: db34a880e6a705920606229f35f5f9e48eeec57b64f583335ac3253d1041f042
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bd6610589cdd23e673ae70ad39cdea36c042bf64dc73c785bebfdc550b792be616f431a451f425c7a21e6acae7ebb2b6c6c9847d251dec6d7d7266a6922d6b17
|
7
|
+
data.tar.gz: 79860c041ffe00bbca6b39e2a025a3818805b8fb960143e7a262dfe665feeaf2c0d0cfad42384f25c3111f0f9ea3e3202137b157bd3ce81ea0f2a6b241165b95
|
data/CHANGELOG.md
CHANGED
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
|
|
4
4
|
Each new release typically also includes the latest modulesync defaults.
|
5
5
|
These should not affect the functionality of the module.
|
6
6
|
|
7
|
+
## [v1.4.0](https://github.com/voxpupuli/puppet_webhook/tree/v1.4.0) (2018-05-02)
|
8
|
+
[Full Changelog](https://github.com/voxpupuli/puppet_webhook/compare/v1.3.0...v1.4.0)
|
9
|
+
|
10
|
+
**Implemented enhancements:**
|
11
|
+
|
12
|
+
- Rocketchat plugin [\#53](https://github.com/voxpupuli/puppet_webhook/pull/53) ([dhollinger](https://github.com/dhollinger))
|
13
|
+
- ChatOps Plugin Support [\#52](https://github.com/voxpupuli/puppet_webhook/pull/52) ([dhollinger](https://github.com/dhollinger))
|
14
|
+
|
7
15
|
## [v1.3.0](https://github.com/voxpupuli/puppet_webhook/tree/v1.3.0) (2018-04-24)
|
8
16
|
[Full Changelog](https://github.com/voxpupuli/puppet_webhook/compare/v1.2.0...v1.3.0)
|
9
17
|
|
@@ -90,4 +98,4 @@ These should not affect the functionality of the module.
|
|
90
98
|
|
91
99
|
|
92
100
|
|
93
|
-
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
101
|
+
\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
|
data/README.md
CHANGED
@@ -80,6 +80,77 @@ Any configuration option is placed in `/etc/puppet_webhook/server.yml` or `/etc/
|
|
80
80
|
* `--ssl-key FILE`: Specify the SSL Private key to use. Pair with `--ssl-cert`. Requires `--ssl` or `ssl_enable: true` in config file.
|
81
81
|
* `-c FILE, --configfile FILE`: Specifies a config file to use. Must be a `.yml` file in YAML format.
|
82
82
|
|
83
|
+
#### Chatops Configuration
|
84
|
+
|
85
|
+
Puppet_webhook can post to chatops tools via various APIs and Clients. At this time, only `Slack` is supported.
|
86
|
+
|
87
|
+
To enable ChatOps support simply add the following to your `/etc/puppet_webhook/app.yml` file:
|
88
|
+
``` yaml
|
89
|
+
chatops: true
|
90
|
+
```
|
91
|
+
|
92
|
+
##### Slack Configuration
|
93
|
+
|
94
|
+
You can enable Slack notifications for the webhook. You will need a Slack webhook URL and the `slack-notifier` gem installed.
|
95
|
+
|
96
|
+
The `slack-notifier` gem is installed as a dependency to `puppet_webhook`
|
97
|
+
|
98
|
+
To get the Slack webhook URL you need to:
|
99
|
+
|
100
|
+
Go to https://slack.com/apps/A0F7XDUAZ-incoming-webhooks.
|
101
|
+
Choose your team, press Configure.
|
102
|
+
In configurations press Add configuration.
|
103
|
+
Choose channel, press Add Incoming WebHooks integration.
|
104
|
+
Then configure the webhook to add your Slack Webhook URL:
|
105
|
+
|
106
|
+
``` yaml
|
107
|
+
chatops: true
|
108
|
+
chatops_service: 'slack' # Required so the app knows that you're sending to Slack.
|
109
|
+
chatops_url: 'http://hooks.slack.com/services/path/to/your/webhook' # mandatory for usage
|
110
|
+
chatops_channel: '#channel' # defaults to #general
|
111
|
+
chatops_user: 'r10k' # defaults to puppet_webhook
|
112
|
+
chatops_options:
|
113
|
+
icon_emoji: ':ocean:'
|
114
|
+
http_options:
|
115
|
+
proxy_address: 'http://proxy.example.com'
|
116
|
+
proxy_port: '3128'
|
117
|
+
proxy_from_env: false
|
118
|
+
```
|
119
|
+
|
120
|
+
**NOTE: The legacy `slack_webhook`, `slack_user`, `slack_channel`, `slack_emoji`, and `slack_proxy_url` still work, but will be removed in 3.0.0**
|
121
|
+
|
122
|
+
##### Rocket.Chat Configuration
|
123
|
+
|
124
|
+
You can enable Rocket.Chat notifications for the webhook. You will need a
|
125
|
+
Rocket.Chat incoming webhook URL and the `rocket-chat-notifier` gem installed.
|
126
|
+
|
127
|
+
The `rocket-chat-notifier` gem is installed as a dependency to `puppet_webhook`
|
128
|
+
|
129
|
+
To get the Rocket.Chat incoming webhook URL you need to:
|
130
|
+
|
131
|
+
1. Go to your Rocket.Chat and then select `Administration-Integrations`.
|
132
|
+
2. Choose `New integration`.
|
133
|
+
3. Choose `Incoming WebHook`. In the webhook form configure:
|
134
|
+
* `Enabled`: `True`.
|
135
|
+
* `Name`: A name for your webhook.
|
136
|
+
* `Post to Channel`: The channel to post to by default.
|
137
|
+
4. Save changes with `Save Changes` bottom.
|
138
|
+
|
139
|
+
Then configure the webhook to add your Rocket.Chat Webhook URL:
|
140
|
+
|
141
|
+
``` yaml
|
142
|
+
chatops: true
|
143
|
+
chatops_service: 'rocketchat' # Required so the app knows that you're sending to Rocket.Chat
|
144
|
+
chatops_url: <your incoming webhook URL> # mandatory for usage
|
145
|
+
chatops_channel: '#channel' # defaults to #general
|
146
|
+
chatops_user: 'r10k' # defaults to puppet_webhook
|
147
|
+
chatops_options:
|
148
|
+
icon_emoji: ':ocean:'
|
149
|
+
http_options:
|
150
|
+
open_timeout: 10
|
151
|
+
```
|
152
|
+
|
153
|
+
### Reference
|
83
154
|
|
84
155
|
#### Server Configuration File
|
85
156
|
|
@@ -190,28 +261,81 @@ Whether or not to use MCollective CLI command. REQUIRES MCOLLECTIVE AND MCOLLECT
|
|
190
261
|
MCollective Ruby discovery timeout. REQUIRES `use_mco_ruby` TO BE `true`.
|
191
262
|
* Default: `'10'`
|
192
263
|
|
264
|
+
##### chatops
|
265
|
+
|
266
|
+
Enable the use of notifications to Slack or other ChatOps tool.
|
267
|
+
* Valid options: [ `true`, `false` ]
|
268
|
+
* Default: `false`
|
269
|
+
|
270
|
+
##### chatops_service
|
271
|
+
|
272
|
+
Name of ChatOps tool to send notifications to.
|
273
|
+
* Valid options: [ `slack` ]
|
274
|
+
* Default: `slack`
|
275
|
+
|
276
|
+
##### chatops_url
|
277
|
+
*Replaces `slack_webhook`*
|
278
|
+
|
279
|
+
URL of the API or Webhook to send notifications to. See Documentation of your tool for details.
|
280
|
+
* Default: `''`
|
281
|
+
|
282
|
+
##### chatops_user
|
283
|
+
*Replaces `slack_user`*
|
284
|
+
|
285
|
+
User to post notification as.
|
286
|
+
* Default: `puppet_webhook`
|
287
|
+
|
288
|
+
##### chatops_channel
|
289
|
+
*Replaces `slack_channel`*
|
290
|
+
|
291
|
+
Channel/Team/Area to post to.
|
292
|
+
* Default: `#general`
|
293
|
+
|
294
|
+
##### chatops_options
|
295
|
+
|
296
|
+
Hash of options to pass to the Chatops plugin. Each set of options are unique to each tool, so please see your tool's documentation for more information.
|
297
|
+
* Default: `{}`
|
298
|
+
|
193
299
|
##### slack_webhook
|
300
|
+
***DEPRECATED* - Please use `chatops_url` instead**
|
194
301
|
|
195
302
|
URL of your Slack Webhook receiver, if you wish not to use a Slack Webhook, then simply leave the option on `false`, otherwise use the full Wwebhook URL for your community as per https://api.slack.com/incoming-webhooks.
|
196
303
|
* Valid options: [ `https://hooks.slack.com/services/<generated_hash>`, `false` ]
|
197
304
|
* Default: `false`
|
198
305
|
|
199
306
|
##### slack_channel
|
307
|
+
***DEPRECATED* - Please use `chatops_channel` instead**
|
200
308
|
|
201
309
|
Name of the Slack channel to post to. Ignored if `slack_webhook` is disabled.
|
202
310
|
Default: `#general`
|
203
311
|
|
204
312
|
##### slack_user
|
313
|
+
***DEPRECATED* - Please use `chatops_user` instead**
|
205
314
|
|
206
315
|
Name of the Slack user to post as. Ignored if `slack_webhook` is disabled.
|
207
316
|
Default: `puppet_webhook`
|
208
317
|
|
209
318
|
##### slack_emoji
|
319
|
+
***DEPRECATED* - Please use `chatops_options` instead.**
|
320
|
+
**Example for new config ONLY:**
|
321
|
+
``` yaml
|
322
|
+
chatops_options:
|
323
|
+
icon_emoji: ':ocean:'
|
324
|
+
```
|
210
325
|
|
211
326
|
Icon emoji for the Webhook to use when posting. Ignored if `slack_webhook` is disabled.
|
212
327
|
Default: `:ocean:`
|
213
328
|
|
214
329
|
##### slack_proxy_url
|
330
|
+
***DEPRECATED* - Please use `chatops_options` instead.**
|
331
|
+
**Example for new config ONLY:**
|
332
|
+
``` yaml
|
333
|
+
chatops_options:
|
334
|
+
http_options:
|
335
|
+
proxy_address: 'http://proxy.example.com'
|
336
|
+
proxy_port: '3128'
|
337
|
+
proxy_from_env: false
|
338
|
+
```
|
215
339
|
|
216
340
|
The proxy URL for Slack if used.
|
217
341
|
* MUST BE A VALID URL.
|
data/config/app.yml
CHANGED
@@ -10,8 +10,13 @@ use_mco_ruby: false
|
|
10
10
|
use_mcollective: false
|
11
11
|
discovery_timeout: '10'
|
12
12
|
|
13
|
-
#
|
14
|
-
|
13
|
+
# Chatops Notification
|
14
|
+
chatops: false
|
15
|
+
# Slack Example
|
16
|
+
# chatops_service: 'slack'
|
17
|
+
# chatops_channel: '#general'
|
18
|
+
# chatops_user: 'r10k'
|
19
|
+
# chatops_url: 'https://hooks.slack.com/services/<hash>/<hash>/<hash>'
|
15
20
|
|
16
21
|
# R10k
|
17
22
|
default_branch: production
|
data/lib/helpers/deployments.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'plugins/mcollective'
|
2
|
+
require 'plugins/chatops'
|
2
3
|
|
3
4
|
module Deployments # rubocop:disable Style/Documentation
|
4
5
|
def deploy(branch, deleted)
|
@@ -23,18 +24,18 @@ module Deployments # rubocop:disable Style/Documentation
|
|
23
24
|
command = "#{settings.command_prefix} r10k deploy environment #{branch} #{settings.r10k_deploy_arguments}"
|
24
25
|
message = run_command(command)
|
25
26
|
end
|
26
|
-
status_message = { status: :success, message: message.to_s, branch: branch, status_code:
|
27
|
+
status_message = { status: :success, message: message.to_s, branch: branch, status_code: 202 }
|
27
28
|
LOGGER.info("message: #{message} branch: #{branch}")
|
28
29
|
unless deleted
|
29
30
|
generate_types(branch) if types?
|
30
31
|
end
|
31
|
-
|
32
|
+
notification(status_message)
|
32
33
|
[status_message[:status_code], status_message.to_json]
|
33
34
|
rescue StandardError => e
|
34
35
|
status_message = { status: :fail, message: e.message, trace: e.backtrace, branch: branch, status_code: 500 }
|
35
36
|
LOGGER.error("message: #{e.message} trace: #{e.backtrace}")
|
36
37
|
status 500
|
37
|
-
|
38
|
+
notification(status_message)
|
38
39
|
status_message.to_json
|
39
40
|
end
|
40
41
|
|
@@ -61,14 +62,14 @@ module Deployments # rubocop:disable Style/Documentation
|
|
61
62
|
message = run_command(command)
|
62
63
|
end
|
63
64
|
LOGGER.info("message: #{message} module_name: #{module_name}")
|
64
|
-
status_message = { status: :success, message: message.to_s, module_name: module_name, status_code:
|
65
|
-
|
65
|
+
status_message = { status: :success, message: message.to_s, module_name: module_name, status_code: 202 }
|
66
|
+
notification(status_message)
|
66
67
|
status_message.to_json
|
67
68
|
rescue StandardError => e
|
69
|
+
status_message = { status: :fail, message: e.message, trace: e.backtrace, branch: branch, status_code: 500 }
|
68
70
|
LOGGER.error("message: #{e.message} trace: #{e.backtrace}")
|
69
71
|
status 500
|
70
|
-
status_message
|
71
|
-
notify_slack(status_message) if slack?
|
72
|
+
notification(status_message)
|
72
73
|
status_message.to_json
|
73
74
|
end
|
74
75
|
end
|
data/lib/helpers/tasks.rb
CHANGED
@@ -48,7 +48,7 @@ module Tasks # rubocop:disable Style/Documentation
|
|
48
48
|
|
49
49
|
def run_command(command)
|
50
50
|
message = "forked: #{command}"
|
51
|
-
|
51
|
+
system "#{command} &"
|
52
52
|
message
|
53
53
|
end
|
54
54
|
|
@@ -58,66 +58,53 @@ module Tasks # rubocop:disable Style/Documentation
|
|
58
58
|
message = run_command(command)
|
59
59
|
LOGGER.info("message: #{message} environment: #{environment}")
|
60
60
|
status_message = { status: :success, message: message.to_s, environment: environment, status_code: 200 }
|
61
|
-
|
61
|
+
notification(status_message)
|
62
62
|
rescue StandardError => e
|
63
63
|
LOGGER.error("message: #{e.message} trace: #{e.backtrace}")
|
64
64
|
status_message = { status: :fail, message: e.message, trace: e.backtrace, environment: environment, status_code: 500 }
|
65
|
-
|
65
|
+
notification(status_message)
|
66
66
|
end
|
67
67
|
|
68
|
-
def
|
69
|
-
return unless settings.slack_webhook
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
}
|
78
|
-
else
|
79
|
-
http_options = {}
|
80
|
-
end
|
81
|
-
|
82
|
-
notifier = Slack::Notifier.new settings.slack_webhook do
|
83
|
-
defaults channel: settings.slack_channel,
|
84
|
-
username: settings.slack_user,
|
85
|
-
icon_emoji: settings.slack_emoji,
|
86
|
-
http_options: http_options
|
87
|
-
end
|
88
|
-
|
89
|
-
if status_message[:branch]
|
90
|
-
target = status_message[:branch]
|
91
|
-
elsif status_message[:module]
|
92
|
-
target = status_message[:module]
|
93
|
-
end
|
94
|
-
|
95
|
-
message = {
|
96
|
-
author: 'r10k for Puppet',
|
97
|
-
title: "r10k deployment of Puppet environment #{target}"
|
98
|
-
}
|
99
|
-
|
100
|
-
case status_message[:status_code]
|
101
|
-
when 200
|
102
|
-
message.merge!(
|
103
|
-
color: 'good',
|
104
|
-
text: "Successfully deployed #{target}",
|
105
|
-
fallback: "Successfully deployed #{target}"
|
106
|
-
)
|
107
|
-
when 500
|
108
|
-
message.merge!(
|
109
|
-
color: 'bad',
|
110
|
-
text: "Failed to deploy #{target}",
|
111
|
-
fallback: "Failed to deploy #{target}"
|
112
|
-
)
|
113
|
-
end
|
68
|
+
def notification(message)
|
69
|
+
return unless settings.chatops || settings.slack_webhook
|
70
|
+
slack_settings if settings.chatops == false && settings.slack_webhook != false
|
71
|
+
PuppetWebhook::Chatops.new(settings.chatops_service,
|
72
|
+
settings.chatops_url,
|
73
|
+
settings.chatops_channel,
|
74
|
+
settings.chatops_user,
|
75
|
+
settings.chatops_options).notify(message)
|
76
|
+
end
|
114
77
|
|
115
|
-
|
78
|
+
# Deprecated
|
79
|
+
# TODO: Remove in release 3.0.0
|
80
|
+
def slack_settings
|
81
|
+
settings.chatops_service = 'slack'
|
82
|
+
LOGGER.warn('settings.slack_webhook is deprecated and will be removed in puppet_webhook 3.0.0')
|
83
|
+
settings.chatops_url = settings.slack_webhook
|
84
|
+
LOGGER.warn('settings.slack_user is deprecated and will be removed in puppet_webhook 3.0.0')
|
85
|
+
settings.chatops_user = settings.slack_user
|
86
|
+
LOGGER.warn('settings.slack_channel is deprecated and will be removed in puppet_webhook 3.0.0')
|
87
|
+
settings.chatops_channel = settings.slack_channel
|
88
|
+
LOGGER.warn('settings.slack_emoji is deprecated and will be removed in puppet_webhook 3.0.0')
|
89
|
+
settings.chatops_options[:icon_emoji] = settings.slack_emoji
|
90
|
+
LOGGER.warn('settings.slack_proxy_url is deprecated and will be removed in puppet_webhook 3.0.0')
|
91
|
+
settings.chatops_options[:http_options] = if settings.slack_proxy_url
|
92
|
+
slack_proxy
|
93
|
+
else
|
94
|
+
{}
|
95
|
+
end
|
116
96
|
end
|
117
97
|
|
118
|
-
|
119
|
-
|
120
|
-
|
98
|
+
# Deprecated
|
99
|
+
# TODO: Remove in release 3.0.0
|
100
|
+
def slack_proxy
|
101
|
+
uri = URI(settings.slack_proxy_url)
|
102
|
+
http_options = {
|
103
|
+
proxy_address: uri.hostname,
|
104
|
+
proxy_port: uri.port,
|
105
|
+
proxy_from_env: false
|
106
|
+
}
|
107
|
+
http_options
|
121
108
|
end
|
122
109
|
|
123
110
|
def types?
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'rocket-chat-notifier'
|
2
|
+
|
3
|
+
class PuppetWebhook
|
4
|
+
class Chatops
|
5
|
+
# Sets up Rocketchat object that will send notifications to Slack via a webhook.
|
6
|
+
class Rocketchat
|
7
|
+
def initialize(channel, url, user, message, options = {})
|
8
|
+
@channel = channel
|
9
|
+
@url = url
|
10
|
+
@user = user
|
11
|
+
@message = message
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def notify
|
16
|
+
notifier = RocketChat::Notifier.new @url, http_options: @options[:http_options]
|
17
|
+
notifier.username = @user
|
18
|
+
notifier.channel = @channel
|
19
|
+
|
20
|
+
target = if @message[:branch]
|
21
|
+
@message[:branch]
|
22
|
+
elsif @message[:module]
|
23
|
+
@message[:module]
|
24
|
+
end
|
25
|
+
|
26
|
+
msg = "r10k deployment of Puppet environment/module #{target} started..."
|
27
|
+
|
28
|
+
attachment = format_attachment(target)
|
29
|
+
|
30
|
+
notifier.ping(msg, icon_emoji: @options[:icon_emoji], attachments: [attachment])
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def format_attachment(target)
|
36
|
+
attachment = {
|
37
|
+
author: 'r10k for Puppet',
|
38
|
+
title: "r10k deployment of Puppet environment #{target}"
|
39
|
+
}
|
40
|
+
|
41
|
+
case @message[:status_code]
|
42
|
+
when 200
|
43
|
+
attachment.merge!(
|
44
|
+
color: 'good',
|
45
|
+
text: "Successfully started deployment of #{target}",
|
46
|
+
fallback: "Successfully started deployment of #{target}"
|
47
|
+
)
|
48
|
+
when 500
|
49
|
+
attachment.merge!(
|
50
|
+
color: 'bad',
|
51
|
+
text: "Failed to deploy #{target}",
|
52
|
+
fallback: "Failed to deploy #{target}"
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
attachment
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'slack-notifier'
|
2
|
+
|
3
|
+
class PuppetWebhook
|
4
|
+
class Chatops
|
5
|
+
# Sets up Slack object that will send notifications to Slack via a webhook.
|
6
|
+
class Slack
|
7
|
+
def initialize(channel, url, user, message, options = {})
|
8
|
+
@channel = channel
|
9
|
+
@url = url
|
10
|
+
@user = user
|
11
|
+
@message = message
|
12
|
+
@options = options
|
13
|
+
end
|
14
|
+
|
15
|
+
def notify
|
16
|
+
notifier = ::Slack::Notifier.new @url, http_options: @options[:http_options]
|
17
|
+
|
18
|
+
target = if @message[:branch]
|
19
|
+
@message[:branch]
|
20
|
+
elsif @message[:module]
|
21
|
+
@message[:module]
|
22
|
+
end
|
23
|
+
|
24
|
+
msg = format_message(target)
|
25
|
+
|
26
|
+
notifier.post text: msg[:fallback],
|
27
|
+
channel: @channel,
|
28
|
+
username: @user,
|
29
|
+
icon_emoji: @options[:icon_emoji],
|
30
|
+
attachments: [msg]
|
31
|
+
end
|
32
|
+
|
33
|
+
private
|
34
|
+
|
35
|
+
def format_message(target)
|
36
|
+
message = {
|
37
|
+
author: 'r10k for Puppet',
|
38
|
+
title: "r10k deployment of Puppet environment #{target}"
|
39
|
+
}
|
40
|
+
|
41
|
+
case @message[:status_code]
|
42
|
+
when 202
|
43
|
+
message.merge!(
|
44
|
+
color: 'good',
|
45
|
+
text: "Successfully started deployment of #{target}",
|
46
|
+
fallback: "Successfully started deployment of #{target}"
|
47
|
+
)
|
48
|
+
when 500
|
49
|
+
message.merge!(
|
50
|
+
color: 'bad',
|
51
|
+
text: "Failed to deploy #{target}",
|
52
|
+
fallback: "Failed to deploy #{target}"
|
53
|
+
)
|
54
|
+
end
|
55
|
+
|
56
|
+
message
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
class PuppetWebhook
|
2
|
+
# Chatops object for sending webhook notifications to chatops tools
|
3
|
+
class Chatops
|
4
|
+
def initialize(service, url, channel, user, options = {})
|
5
|
+
@service = service
|
6
|
+
@url = url
|
7
|
+
@channel = channel
|
8
|
+
@user = user
|
9
|
+
@args = options
|
10
|
+
end
|
11
|
+
|
12
|
+
def notify(message)
|
13
|
+
case @service
|
14
|
+
when 'slack'
|
15
|
+
require 'plugins/chatops/slack'
|
16
|
+
LOGGER.info("Sending Slack webhook message to #{@url}")
|
17
|
+
Chatops::Slack.new(
|
18
|
+
@channel,
|
19
|
+
@url,
|
20
|
+
@user,
|
21
|
+
message,
|
22
|
+
http_options: @args[:http_options] || {},
|
23
|
+
icon_emoji: @args[:icon_emoji]
|
24
|
+
).notify
|
25
|
+
when 'rocketchat'
|
26
|
+
require 'plugins/chatops/rocketchat'
|
27
|
+
LOGGER.info("Sending Rocket.Chat webhook message to #{@url}")
|
28
|
+
Chatops::Rocketchat.new(
|
29
|
+
@channel,
|
30
|
+
@url,
|
31
|
+
@user,
|
32
|
+
message,
|
33
|
+
http_options: @args[:http_options] || {},
|
34
|
+
icon_emoji: @args[:icon_emoji]
|
35
|
+
).notify
|
36
|
+
else
|
37
|
+
LOGGER.error("Service #{@service} is not currently supported")
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
data/lib/puppet_webhook.rb
CHANGED
@@ -37,11 +37,12 @@ class PuppetWebhook < Sinatra::Base # rubocop:disable Style/Documentation
|
|
37
37
|
set :use_mco_ruby, false unless settings.respond_to? :use_mco_ruby=
|
38
38
|
set :use_mcollective, false unless settings.respond_to? :use_mcollective=
|
39
39
|
set :discovery_timeout, false unless settings.respond_to? :discovery_timeout=
|
40
|
-
set :
|
41
|
-
set :
|
42
|
-
set :
|
43
|
-
set :
|
44
|
-
set :
|
40
|
+
set :chatops, false unless settings.respond_to? :chatops=
|
41
|
+
set :chatops_service, 'slack' unless settings.respond_to? :chatops_service=
|
42
|
+
set :chatops_url, '' unless settings.respond_to? :chatops_url=
|
43
|
+
set :chatops_channel, '#general' unless settings.respond_to? :chatops_channel=
|
44
|
+
set :chatops_user, 'puppet_webhook' unless settings.respond_to? :chatops_user=
|
45
|
+
set :chatops_options, {} unless settings.respond_to? :chatops_options=
|
45
46
|
set :default_branch, 'production' unless settings.respond_to? :default_branch=
|
46
47
|
set :ignore_environments, [] unless settings.respond_to? :ignore_environments=
|
47
48
|
set :prefix, nil unless settings.respond_to? :prefix=
|
@@ -52,6 +53,13 @@ class PuppetWebhook < Sinatra::Base # rubocop:disable Style/Documentation
|
|
52
53
|
set :github_secret, nil unless settings.respond_to? :github_secret=
|
53
54
|
set :repository_events, nil unless settings.respond_to? :respository_events=
|
54
55
|
|
56
|
+
# Deprecated Settings
|
57
|
+
set :slack_webhook, false unless settings.respond_to? :slack_webhook=
|
58
|
+
set :slack_channel, '#general' unless settings.respond_to? :slack_channel=
|
59
|
+
set :slack_user, 'puppet_webhook' unless settings.respond_to? :slack_user=
|
60
|
+
set :slack_emoji, ':ocean:' unless settings.respond_to? :slack_emoji=
|
61
|
+
set :slack_proxy_url, nil unless settings.respond_to? :slack_proxy_url=
|
62
|
+
|
55
63
|
require 'helpers/init'
|
56
64
|
|
57
65
|
register Sinatra::PuppetWebhookRoutes::Default
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: puppet_webhook
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vox Pupuli
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-05-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rocket-chat-notifier
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: sinatra
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -239,6 +253,9 @@ files:
|
|
239
253
|
- lib/parsers/webhook_json_parser.rb
|
240
254
|
- lib/parsers/webhook_parser.rb
|
241
255
|
- lib/parsers/webhook_www_form_url_encoded_parser.rb
|
256
|
+
- lib/plugins/chatops.rb
|
257
|
+
- lib/plugins/chatops/rocketchat.rb
|
258
|
+
- lib/plugins/chatops/slack.rb
|
242
259
|
- lib/plugins/mcollective.rb
|
243
260
|
- lib/puppet_webhook.rb
|
244
261
|
- lib/routes/default.rb
|