Email notification upon success or failure (with logs)


#1

Looking over various available cookbooks, searching through the wiki and
then good 'ol google - I didn’t find a way to incorporate a mailing
notification that didn’t require additional software to be installed on the
client manually.

What is the typical approach for sending email notification when a
chef-client run is complete?

Are handlers really the only way?


#2

On Tuesday, October 25, 2011 at 7:51 AM, Maven User wrote:

Looking over various available cookbooks, searching through the wiki and then good 'ol google - I didn’t find a way to incorporate a mailing notification that didn’t require additional software to be installed on the client manually.

What is the typical approach for sending email notification when a chef-client run is complete?

Are handlers really the only way?
Yes, handlers are the only way at present. Server side notifications may be added in a future release of Chef, but there’s nothing set in stone at the moment.


Dan DeLeo


#3

On Oct 25, 2011, at 5:44 PM, Daniel DeLeo dan@kallistec.com wrote:

On Tuesday, October 25, 2011 at 7:51 AM, Maven User wrote:

Looking over various available cookbooks, searching through the wiki and then good 'ol google - I didn’t find a way to incorporate a mailing notification that didn’t require additional software to be installed on the client manually.

What is the typical approach for sending email notification when a chef-client run is complete?

Are handlers really the only way?
Yes, handlers are the only way at present. Server side notifications may be added in a future release of Chef, but there’s nothing set in stone at the moment.

That said, it needn’t be manual; look at the handlers recipe in the chef-client cookbook.


#4

Hmmm - I don’t see anything in the chef-client cookbook about handlers:

https://github.com/opscode/cookbooks/tree/master/chef-client/recipes

So if I pull down the chef_handler cookbook and add a new handler - don’t I
just depend on that in my recipe?

On Tue, Oct 25, 2011 at 11:57 AM, Andrea Campi <andrea.campi@zephirworks.com

wrote:

On Oct 25, 2011, at 5:44 PM, Daniel DeLeo dan@kallistec.com wrote:

On Tuesday, October 25, 2011 at 7:51 AM, Maven User wrote:

Looking over various available cookbooks, searching through the wiki and
then good 'ol google - I didn’t find a way to incorporate a mailing
notification that didn’t require additional software to be installed on the
client manually.

What is the typical approach for sending email notification when a
chef-client run is complete?

Are handlers really the only way?
Yes, handlers are the only way at present. Server side notifications may
be added in a future release of Chef, but there’s nothing set in stone at
the moment.

That said, it needn’t be manual; look at the handlers recipe in the
chef-client cookbook.


#5

So I’m following along with the exception and report handler example (
http://wiki.opscode.com/display/chef/Exception+and+Report+Handlers) and I
have a couple of questions.

I’ve got the chef_handler configured in my recipe like this:

chef_handler "MYLibs::Email" do
  source "C:/chef/handlers/Email.rb"
  arguments :from_address => "foo@domain.com", :to_address => "

mavenuser@domain.com"
action :enable
end

This based on the initialization method in the Email class:

def initialize(from_address, to_address)
  @from_address = from_address
  @to_address   = to_address
end

But that results in:

[Tue, 25 Oct 2011 13:24:29 -0400] FATAL: ArgumentError:
chef_handler[MYLibs::Email] (email_demo::default line
/chef/cache/cookbooks/email_demo/recipes/default.rb) had an error: wrong
number of arguments (1 for 2)

When I look at the json output, I can clearly see both defined:

    "arguments": {
      "to_address": "mavenuser@domain.com",
      "from_address": "foo@domain.com"
    },

Am I passing in the initialization arguments wrong?

On Tue, Oct 25, 2011 at 12:12 PM, Maven User maven.2.user@gmail.com wrote:

Hmmm - I don’t see anything in the chef-client cookbook about handlers:

https://github.com/opscode/cookbooks/tree/master/chef-client/recipes

So if I pull down the chef_handler cookbook and add a new handler - don’t I
just depend on that in my recipe?

On Tue, Oct 25, 2011 at 11:57 AM, Andrea Campi <
andrea.campi@zephirworks.com> wrote:

On Oct 25, 2011, at 5:44 PM, Daniel DeLeo dan@kallistec.com wrote:

On Tuesday, October 25, 2011 at 7:51 AM, Maven User wrote:

Looking over various available cookbooks, searching through the wiki
and then good 'ol google - I didn’t find a way to incorporate a mailing
notification that didn’t require additional software to be installed on the
client manually.

What is the typical approach for sending email notification when a
chef-client run is complete?

Are handlers really the only way?
Yes, handlers are the only way at present. Server side notifications may
be added in a future release of Chef, but there’s nothing set in stone at
the moment.

That said, it needn’t be manual; look at the handlers recipe in the
chef-client cookbook.


#6

Try this:

chef_handler “MYLibs::Email” do
source “C:/chef/handlers/Email.rb"
arguments "foo@domain.com”, "mavenuser@domain.com"
action :enable
end

The constructor in the wiki example takes two plain arguments, you are passing a hash.

On Oct 25, 2011, at 7:27 PM, Maven User maven.2.user@gmail.com wrote:

chef_handler “MYLibs::Email” do
source “C:/chef/handlers/Email.rb"
arguments :from_address => "foo@domain.com”, :to_address => "mavenuser@domain.com"
action :enable
end


#7

Sorry - I was JUST typing out the reply saying I got it working.

You need to pass in an array as part of how the default handler provider
works:

def collect_args(resource_args = [])
if resource_args.is_a? Array
resource_args
else
[resource_args]
end
end

If I pass in just two plain strings, then it complains I’ve only
passed in one of two required arguments.

Thank you so much for your patience - I’m (obviously) new to ruby as well!

On Tue, Oct 25, 2011 at 2:49 PM, Andrea Campi
andrea.campi@zephirworks.comwrote:

Try this:

chef_handler “MYLibs::Email” do
source “C:/chef/handlers/Email.rb"
arguments "foo@domain.com”, "mavenuser@domain.com"
action :enable
end

The constructor in the wiki example takes two plain arguments, you are
passing a hash.

On Oct 25, 2011, at 7:27 PM, Maven User maven.2.user@gmail.com wrote:

chef_handler “MYLibs::Email” do
source “C:/chef/handlers/Email.rb"
arguments :from_address => "foo@domain.com”, :to_address => "
mavenuser@domain.com"
action :enable
end


#8

Now the question is where is the logged output of the previous run stored?

Seems like there isn’t a log of the operation if you don’t specify the
actual log file.

On Tue, Oct 25, 2011 at 2:54 PM, Maven User maven.2.user@gmail.com wrote:

Sorry - I was JUST typing out the reply saying I got it working.

You need to pass in an array as part of how the default handler provider
works:

def collect_args(resource_args = [])
if resource_args.is_a? Array
resource_args
else
[resource_args]
end
end

If I pass in just two plain strings, then it complains I’ve only passed in one of two required arguments.

Thank you so much for your patience - I’m (obviously) new to ruby as well!

On Tue, Oct 25, 2011 at 2:49 PM, Andrea Campi <
andrea.campi@zephirworks.com> wrote:

Try this:

chef_handler “MYLibs::Email” do
source “C:/chef/handlers/Email.rb"
arguments "foo@domain.com”, "mavenuser@domain.com"
action :enable
end

The constructor in the wiki example takes two plain arguments, you are
passing a hash.

On Oct 25, 2011, at 7:27 PM, Maven User maven.2.user@gmail.com wrote:

chef_handler “MYLibs::Email” do
source “C:/chef/handlers/Email.rb"
arguments :from_address => "foo@domain.com”, :to_address => "
mavenuser@domain.com"
action :enable
end