chef-handler-status_notifier 0.4.4 → 0.5.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: 3149f18b65e07619bad10f7b36ce33d0ac29fc42
4
- data.tar.gz: 3c3d034ad1bfac27d916a3cc8f3f2d91bd03bc91
3
+ metadata.gz: 9670852bd3a1ce613f503a1fd9af77f9207930b9
4
+ data.tar.gz: 928ae559401567ddda68fd9c967ab90f8510a36e
5
5
  SHA512:
6
- metadata.gz: 88e108cd32ecd04df1b2f441ee75cd9cfe71a0de5a0eeae6ddb15f37a4f006c6a7c1f587dac2179fe06037d0430308de8c9415e8941a4e3564f1e0f3a8da35ec
7
- data.tar.gz: 5b0ede03e06aa9d39b8490b096157e4a3b4c00de5cc73807fcb129c993993c022758d69a9dbb5b22dc7a67180b147c2618f6651d5aa4e4bd3e7cee496149bb8d
6
+ metadata.gz: c3695b1f6a72527354b6d8dd9790f4cbf2a22581704397fe3dc1492995bbd1e2959a52f5a451a8dc9e8ce5ca19f9dfc57095c070aea87a19525ab0232198af50
7
+ data.tar.gz: f507dcb17b76396e5115a71b63508e5420583dea846e6db7a1b4b7eacaa0f0f01f0a26c3d4f02184656240f8a1d799450ad0f66ba71d84644141b44c10b1cfc7
data/README.md CHANGED
@@ -1,10 +1,23 @@
1
1
  # Chef::Handler::StatusNotifier
2
2
 
3
- Chef Handler for Status Notifier
3
+ Chef Handler for Status Notifier. This is being used here, https://github.com/faizalzakaria/chef-run-notifier .
4
4
 
5
5
  ## Usage
6
6
 
7
- TODO:
7
+ In your Chef recipe,
8
+
9
+ ```ruby
10
+ chef_gem 'chef-handler-status_notifier' do
11
+ compile_time true if respond_to?(:compile_time)
12
+ action :upgrade
13
+ end
14
+
15
+ chef_handler 'StatusNotifierHandler' do
16
+ source 'chef/handler/status_notifier'
17
+ arguments [node['run_notifier']['slack'], node['run_notifier']['hipchat']]
18
+ action :nothing
19
+ end.run_action(:enable)
20
+ ```
8
21
 
9
22
  ## Contributing
10
23
 
@@ -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.4.4"
6
+ spec.version = "0.5.0"
7
7
  spec.authors = ["Faizal Zakaria"]
8
8
  spec.email = ["phaibusiness@gmail.com"]
9
9
  spec.summary = %q{Chef status notifier handler}
@@ -9,26 +9,22 @@ require 'slack-notifier'
9
9
 
10
10
  class StatusNotifierHandler < Chef::Handler
11
11
 
12
- def initialize(slack_params, hipchat_params)
13
- initialize_hipchat(hipchat_params)
14
- initialize_slack(slack_params)
15
- end
16
-
17
- def initialize_hipchat(params)
18
- @hipchat_params = params
19
- end
12
+ DEFAULT_FAILED_MESSAGE = '"Failure on #{node.name}: #{run_status.formatted_exception}"'.freeze
13
+ DEFAULT_SUCCESS_MESSAGE = '"Chef run succesfully on #{node.name}"'.freeze
20
14
 
21
- def initialize_slack(params)
22
- @slack_params = params
15
+ def initialize(slack_params, hipchat_params, custom_message_params = {})
16
+ @slack_params = slack_params
17
+ @hipchat_params = hipchat_params
18
+ @custom_message_params = custom_message_params
23
19
  end
24
20
 
25
21
  def report
26
22
  if run_status.failed?
27
- msg = "Failure on #{node.name}: #{run_status.formatted_exception}"
23
+ msg = failed_message
28
24
  status = :failed
29
25
  send_to_hipchat(msg)
30
26
  else
31
- msg = "Chef run succesfully on #{node.name}"
27
+ msg = success_message
32
28
  status = :success
33
29
  end
34
30
 
@@ -38,6 +34,19 @@ class StatusNotifierHandler < Chef::Handler
38
34
 
39
35
  private
40
36
 
37
+ def eval_message_for(message)
38
+ return nil if message.nil?
39
+ eval(message)
40
+ end
41
+
42
+ def failed_message
43
+ eval_message_for(@custom_message_params[:failed_message] || DEFAULT_FAILED_MESSAGE)
44
+ end
45
+
46
+ def success_message
47
+ eval_message_for(@custom_message_params[:success_message] || DEFAULT_SUCCESS_MESSAGE)
48
+ end
49
+
41
50
  def send_to_hipchat(msg)
42
51
  return unless @hipchat_params[:enabled]
43
52
  hipchat[@hipchat_params[:room_name]].send(@hipchat_params[:username], msg, :notify => @hipchat_params[:notify])
@@ -17,10 +17,26 @@ describe StatusNotifierHandler do
17
17
  }
18
18
  end
19
19
 
20
- it 'should run without error' do
21
- allow_any_instance_of(StatusNotifierHandler).to receive(:send_to_slack).and_return(true)
22
- allow_any_instance_of(StatusNotifierHandler).to receive(:send_to_hipchat).and_return(true)
23
- expect{StatusNotifierHandler.new(slack_params, hipchat_params).report}.to_not raise_error
20
+ context 'without custom message' do
21
+ it 'should run without error' do
22
+ allow_any_instance_of(StatusNotifierHandler).to receive(:send_to_slack).and_return(true)
23
+ allow_any_instance_of(StatusNotifierHandler).to receive(:send_to_hipchat).and_return(true)
24
+ expect{StatusNotifierHandler.new(slack_params, hipchat_params).report}.to_not raise_error
25
+ end
24
26
  end
25
27
 
28
+ context 'with custom message' do
29
+ let(:custom_message_params) do
30
+ {
31
+ success_message: '"Success on #{node.name}"',
32
+ failed_message: '"Failed on #{node.name}"'
33
+ }
34
+ end
35
+
36
+ it 'should run without error' do
37
+ allow_any_instance_of(StatusNotifierHandler).to receive(:send_to_slack).and_return(true)
38
+ allow_any_instance_of(StatusNotifierHandler).to receive(:send_to_hipchat).and_return(true)
39
+ expect{StatusNotifierHandler.new(slack_params, hipchat_params, custom_message_params).report}.to_not raise_error
40
+ end
41
+ end
26
42
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-handler-status_notifier
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.4
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Faizal Zakaria
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-01-05 00:00:00.000000000 Z
11
+ date: 2017-12-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: hipchat
@@ -91,7 +91,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.5.1
94
+ rubygems_version: 2.6.11
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Chef status notifier handler