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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 25b94d5fb43b033b90f22b3172eea91b5c6a355e
4
- data.tar.gz: 1ad7aa9146a72435bcf24e7d1ca99386138b8449
3
+ metadata.gz: f46ac6b803396196b68b6c4189fbfe5a558f610d
4
+ data.tar.gz: 2ef29efee61530660cfcf296896b690e06e18988
5
5
  SHA512:
6
- metadata.gz: d6fc054b86f2cd59f33e7403e46ffb7da65dc45c576a787a9b4d55c338249c718b5a50e6261d7dce327fa3b9ba668a2698db5231904f23c7c67f2fa71c926751
7
- data.tar.gz: 3d370da722ce30f628fce809b6e75f37d06524322859fce88274b22101720cb8f965a91ed3f066f67b00e51bfc345dfb77ea370951aeb2de2899eb36dcab942a
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.3.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
@@ -1,7 +1,7 @@
1
1
  class Chef::Handler
2
2
  class RunStatus
3
3
  def failed?
4
- true
4
+ false
5
5
  end
6
6
 
7
7
  def formatted_exception
@@ -5,7 +5,7 @@ describe StatusNotifierHandler do
5
5
  let(:slack_params) do
6
6
  {
7
7
  enabled: true,
8
- webhook_url: "https://slacktest.com",
8
+ webhook_url: "https://hooks.slack.com/services/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",
9
9
  channel: "#test",
10
10
  username: "FaiNow-Test"
11
11
  }
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-handler-status_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faizal Zakaria