Skip to content

Commit

Permalink
Merge pull request #20 from Lytro/make_email_alerts_optional
Browse files Browse the repository at this point in the history
only set email alerts if node[:monit][:notify_email] is not nil (defaults to nil)
  • Loading branch information
yourabi committed Sep 10, 2014
2 parents e0bc91e + 65bf8eb commit 7c0c2d7
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
default["monit"]["notify_email"] = "[email protected]"
default["monit"]["notify_email"] = nil
default["monit"]["alert_blacklist"] = %w( action instance pid ppid )

default["monit"]["logfile"] = 'syslog facility log_daemon'
Expand Down
8 changes: 5 additions & 3 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

describe 'monit::default' do
context "with default attributes" do
let(:chef_run) do
runner = ChefSpec::Runner.new.converge(described_recipe)
end
let(:chef_run) { ChefSpec::Runner.new.converge(described_recipe) }

it 'creates /etc/monit/conf.d/' do
expect(chef_run).to create_directory('/etc/monit/conf.d/').with(user: 'root', group: 'root', mode: 0755)
Expand All @@ -27,6 +25,10 @@
it 'start the service' do
expect(chef_run).to start_service('monit')
end

it 'does not email notifications' do
expect(chef_run).not_to render_file('/etc/monit/monitrc').with_content(/set alert /)
end
end

context "with configuration" do
Expand Down
4 changes: 3 additions & 1 deletion templates/default/monitrc.erb
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ set mail-format {
message: <%= @node["monit"]["mail_format"]["message"] %>
}

set alert <%= @node["monit"]["notify_email"] %><%= " NOT ON { #{@node["monit"]["alert_blacklist"].join(", ")} }" unless @node["monit"]["alert_blacklist"].empty? %>
<% unless @node[:monit][:notify_email].nil? %>
set alert <%= @node["monit"]["notify_email"] %><%= " NOT ON { #{@node["monit"]["alert_blacklist"].join(", ")} }" unless @node["monit"]["alert_blacklist"].empty? %>
<% end %>

set httpd port <%= @node["monit"]["port"] %>
<%= "use address #{@node["monit"]["address"]}" if @node["monit"]["address"] %>
Expand Down

0 comments on commit 7c0c2d7

Please sign in to comment.