chef-handler-status_notifier 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/chef-handler-status_notifier.gemspec +1 -1
- data/lib/chef/handler/status_notifier.rb +17 -3
- data/spec/chef/handler.rb +1 -1
- data/spec/status_notifier_spec.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f46ac6b803396196b68b6c4189fbfe5a558f610d
|
4
|
+
data.tar.gz: 2ef29efee61530660cfcf296896b690e06e18988
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c08b20496949c92206042d3104e5aabca5afa04952022e5466431dacfe8ba617f6a0884fc29bfbc8078d5a2deae44a1a529c8e0545af3c0987792a18a9771499
|
7
|
+
data.tar.gz: f3543c490274eb01ca9267a6c6fdd2536a8ebd8a4bdff2c89cc82739bbd882c8738424375f3aec8ae57f74f3ae644538668ffd76032e0baf13f81dd4446df054
|
@@ -3,7 +3,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
3
3
|
|
4
4
|
Gem::Specification.new do |spec|
|
5
5
|
spec.name = "chef-handler-status_notifier"
|
6
|
-
spec.version = "0.
|
6
|
+
spec.version = "0.4.0"
|
7
7
|
spec.authors = ["Faizal Zakaria"]
|
8
8
|
spec.email = ["phaibusiness@gmail.com"]
|
9
9
|
spec.summary = %q{Chef status notifier handler}
|
@@ -25,12 +25,15 @@ class StatusNotifierHandler < Chef::Handler
|
|
25
25
|
def report
|
26
26
|
if run_status.failed?
|
27
27
|
msg = "Failure on #{node.name}: #{run_status.formatted_exception}"
|
28
|
+
status = :failed
|
29
|
+
send_to_hipchat(msg)
|
28
30
|
else
|
29
31
|
msg = "Chef run succesfully on #{node.name}"
|
32
|
+
status = :success
|
30
33
|
end
|
31
34
|
|
35
|
+
send_to_slack(status, msg)
|
32
36
|
send_to_hipchat(msg)
|
33
|
-
send_to_slack(msg)
|
34
37
|
end
|
35
38
|
|
36
39
|
private
|
@@ -40,11 +43,11 @@ class StatusNotifierHandler < Chef::Handler
|
|
40
43
|
hipchat[@hipchat_params[:room_name]].send(@hipchat_params[:username], msg, :notify => @hipchat_params[:notify])
|
41
44
|
end
|
42
45
|
|
43
|
-
def send_to_slack(msg)
|
46
|
+
def send_to_slack(status, msg)
|
44
47
|
return unless @slack_params[:enabled]
|
45
48
|
slack.channel = @slack_params[:channel]
|
46
49
|
slack.username = @slack_params[:username]
|
47
|
-
slack.ping msg
|
50
|
+
slack.ping '', attachments: [slack_attachment(status, msg)]
|
48
51
|
end
|
49
52
|
|
50
53
|
def hipchat
|
@@ -54,4 +57,15 @@ class StatusNotifierHandler < Chef::Handler
|
|
54
57
|
def slack
|
55
58
|
@slack ||= Slack::Notifier.new(@slack_params[:webhook_url])
|
56
59
|
end
|
60
|
+
|
61
|
+
def slack_attachment(status, msg)
|
62
|
+
color = (status == :failed)? "#ff0000" : "#36a64f"
|
63
|
+
{
|
64
|
+
fallback: "Opsworks status, #{msg}",
|
65
|
+
color: "#{color}",
|
66
|
+
author_name: "OpsworksBot (",
|
67
|
+
title: "status: #{status}",
|
68
|
+
text: "#{msg}"
|
69
|
+
}
|
70
|
+
end
|
57
71
|
end
|
data/spec/chef/handler.rb
CHANGED
@@ -5,7 +5,7 @@ describe StatusNotifierHandler do
|
|
5
5
|
let(:slack_params) do
|
6
6
|
{
|
7
7
|
enabled: true,
|
8
|
-
webhook_url: "https://
|
8
|
+
webhook_url: "https://hooks.slack.com/services/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",
|
9
9
|
channel: "#test",
|
10
10
|
username: "FaiNow-Test"
|
11
11
|
}
|