Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

No email configuration if node[:monit][:notify_email] is nil or blank. #46

Closed
wants to merge 1 commit into from

2 participants

@yyamano

The change is based on @anujbiyani work on issue #20 for HEAD.

@yourabi
Collaborator

I think it would be best to get #20 rebased/merged and then merge this.

Once #20 is closed - Could you please rebase then and I'll merge the expanded tests.

@yourabi
Collaborator

Hi @yyamano - #20 is merged now. Could you please rebase your changes? I'll help get this in.

@yourabi yourabi closed this
@yourabi
Collaborator

Closing this PR build-fails - merged d1af7b3 which does the same thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 9, 2013
  1. @yyamano
This page is out of date. Refresh to see the latest.
View
2  attributes/default.rb
@@ -1,4 +1,4 @@
-default[:monit][:notify_email] = "notify@example.com"
+default[:monit][:notify_email] = nil
default[:monit][:logfile] = 'syslog facility log_daemon'
View
22 spec/unit/recipes/default_spec.rb
@@ -16,7 +16,9 @@
expect(file).to notify('service[monit]').to(:restart)
expect(chef_run).to render_file('/etc/monit/monitrc').with_content(/set daemon 60\n\s*with start delay 120$/)
- expect(chef_run).to render_file('/etc/monit/monitrc').with_content(/set mailserver localhost\n\s*with timeout 60 seconds$/)
+ expect(chef_run).not_to render_file('/etc/monit/monitrc').with_content(/set mailserver/)
+ expect(chef_run).not_to render_file('/etc/monit/monitrc').with_content(/set mail-format/)
+ expect(chef_run).not_to render_file('/etc/monit/monitrc').with_content(/set alert/)
expect(chef_run).to render_file('/etc/monit/monitrc').with_content(/set httpd port 3737\n\s*use address localhost\n\s*allow localhost$/)
end
@@ -32,7 +34,7 @@
context "with configuration" do
let(:chef_run) do
runner = ChefSpec::Runner.new do |node|
- node.set[:monit][:notify_email] = 'johndoe@example.com'
+ node.set[:monit][:notify_email] = 'johndoe@example.com'
node.set[:monit][:logfile] = '/var/log/monit.log'
node.set[:monit][:poll_period] = 30
node.set[:monit][:poll_start_delay] = 90
@@ -65,6 +67,22 @@
expect(chef_run).to render_file('/etc/monit/monitrc').with_content(/allow johndoe:secret$/)
expect(chef_run).to render_file('/etc/monit/monitrc').with_content(%r|ssl enable\n\s*pemfile /etc/monit/monit.pem$|)
end
+
+ describe 'mail alerts' do
+ let(:chef_run) do
+ runner = ChefSpec::Runner.new do |node|
+ node.set[:monit][:notify_email] = ''
+ end.converge(described_recipe)
+ end
+
+ it 'when notify_email is blank, it doesn not sets alerts' do
+ expect(chef_run).not_to render_file('/etc/monit/monitrc').with_content(/set mailserver/)
+ expect(chef_run).not_to render_file('/etc/monit/monitrc').with_content(/set mail-format/)
+ expect(chef_run).not_to render_file('/etc/monit/monitrc').with_content(/set alert/)
+ end
+
+ end
+
end
context "on ubuntu" do
View
10 templates/default/monitrc.erb
@@ -5,6 +5,11 @@ set daemon <%= @node[:monit][:poll_period] %>
set logfile <%= @node[:monit][:logfile] %>
+set eventqueue
+ basedir /var/monit # set the base directory where events will be stored
+# slots 1000 # optionaly limit the queue size
+
+<% unless @node[:monit][:notify_email].nil? || @node[:monit][:notify_email] == '' %>
set mailserver <%= @node[:monit][:mailserver][:host] %><%= " port #{@node[:monit][:mailserver][:port]}" if @node[:monit][:mailserver][:port] %>
<% if @node[:monit][:mailserver][:username] %>
username "<%= @node[:monit][:mailserver][:username] %>"
@@ -19,10 +24,6 @@ set mailserver <%= @node[:monit][:mailserver][:host] %><%= " port #{@node[:monit
with timeout <%= @node[:monit][:mailserver][:timeout] %> seconds
<% end %>
-set eventqueue
- basedir /var/monit # set the base directory where events will be stored
-# slots 1000 # optionaly limit the queue size
-
set mail-format {
from: <%= @node[:monit][:mail_format][:from] %>
subject: <%= @node[:monit][:mail_format][:subject] %>
@@ -30,6 +31,7 @@ set mail-format {
}
set alert <%= @node[:monit][:notify_email] %> NOT ON { action, instance, pid, ppid }
+<% end %>
set httpd port <%= @node[:monit][:port] %>
<%= "use address #{@node[:monit][:address]}" if @node[:monit][:address] %>
Something went wrong with that request. Please try again.