Re: Using the wrapper cookbook development method to remove the pager duty contact from the Nagios Cookbook


#1

Hi Chef users email distribution list,

An update on this item: if I set load_default_config to false my template renders correctly. Therefore, I conclude that the observed behavior is a consequence of Chef’s resource cloning.

The only change from the pastebin below is that I tried defining and explicitly passing in the variable that I have manipulated in my wrapper logic:

nagios_contactgroups = Nagios.instance.contactgroups

begin
t = resources(:template => “#{node[‘nagios’][‘config_dir’]}/contacts.cfg”)
t.source "contacts.cfg.erb"
t.cookbook "sm-nagios"
t.variables(:nagios_contactgroups => Nagios.instance.contactgroups)
#rescue Chef::Exceptions::ResourceNotFound

Chef::Log.warn “could not find template #{node[‘nagios’][‘config_dir’]/contacts.cfg to modify”

End

Can anyone shed light on why the cloned resource is superseding my attempt to open back up the object and re-render it?

I am going to turn off load_default_config and copy in all of the logic, adding in my logic to manipulate the arrays – I’d love to understand where I went wrong with the wrapper method here though, I won’t be able to use wrappers if the behavior isn’t intelligible to me.

Any assistance anyone can offer is greatly appreciated.

Thanks all,
Joseph Hammerman

From: Joseph Hammerman <JHammerman@secondmarket.commailto:JHammerman@secondmarket.com>
Reply-To: "chef@lists.opscode.commailto:chef@lists.opscode.com" <chef@lists.opscode.commailto:chef@lists.opscode.com>
Date: Friday, May 15, 2015 at 6:01 PM
To: "chef@lists.opscode.commailto:chef@lists.opscode.com" <chef@lists.opscode.commailto:chef@lists.opscode.com>
Subject: [chef] Using the wrapper cookbook development method to remove the pager duty contact from the Nagios Cookbook

Hi Chef users email distribution list,

I’m trying to use the wrapper development method to change the values written out for the contactgroups in the Nagios cookbook. As you all may or may not know, this cookbook makes heavy use of definitions, resources and LWRPs. Within the users_helper.rb definition file, the following block of code exists:

def return_user_contacts
contacts = []

# add base contacts from nagios_users data bag
@users.each do |s|
  contacts << s['id']
end

# add pagerduty user if enabled
contacts << 'pagerduty' unless @node['nagios']['pagerduty']['key'].empty?

contacts

end

I personally like to have an email only contactgroup.

I attempted this (which manipulates the arrays correctly):

http://pastebin.com/RVwBGa8f

My reasoning was that I have updated the information in the class members that are referenced when the file is rendered, so if I rerender the file, if the arrays contain the correct members, the file should be rendered with the content that I desire.

However, during the Chef run, I see this output:

Recipe: sm-nagios::_load_default_config

  • nagios_contactgroup[admins] action create (up to date)
  • nagios_contactgroup[admins-sms] action create (up to date)

I’m thinking I could be encountering the resource cloning that Chef does?

Can anyone assist in better understanding the method / process I should be using here?

Thanks all,
Joseph Hammerman

This message is intended only for the addressee. Please notify sender by e-mail if you are not the intended recipient. If you are not the intended recipient, you may not copy, disclose, or distribute this message or its contents to any other person and any such actions may be unlawful.
SecondMarket, Inc. (Member FINRA/SIPC, MSRB Registered) (“SecondMarket”) does
not accept time sensitive, action-oriented messages or transaction orders, including orders to purchase or sell securities, via e-mail.
SecondMarket reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the SecondMarket e-mail system and archived in accordance with FINRA and SEC regulations.
This message is intended for those with an in-depth understanding of the high risk and illiquid nature of alternative assets and these assets may not be suitable for you. This message is not a solicitation for an order, and there is not enough information contained in this message in which to make an investment decision and any information contained herein should not be used as a basis for this purpose. SecondMarket does not produce in-house research, make recommendations to purchase or sell specific securities, provide investment advisory services, or conduct a general retail business.

This message is intended only for the addressee. Please notify sender by e-mail if you are not the intended recipient. If you are not the intended recipient, you may not copy, disclose, or distribute this message or its contents to any other person and any such actions may be unlawful.
SecondMarket, Inc. (Member FINRA/SIPC, MSRB Registered) (“SecondMarket”) does
not accept time sensitive, action-oriented messages or transaction orders, including orders to purchase or sell securities, via e-mail.
SecondMarket reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the SecondMarket e-mail system and archived in accordance with FINRA and SEC regulations.
This message is intended for those with an in-depth understanding of the high risk and illiquid nature of alternative assets and these assets may not be suitable for you. This message is not a solicitation for an order, and there is not enough information contained in this message in which to make an investment decision and any information contained herein should not be used as a basis for this purpose. SecondMarket does not produce in-house research, make recommendations to purchase or sell specific securities, provide investment advisory services, or conduct a general retail business.


#2

On Monday, May 18, 2015 at 9:25 AM, Joseph Hammerman wrote:

Hi Chef users email distribution list,

An update on this item: if I set load_default_config to false my template renders correctly. Therefore, I conclude that the observed behavior is a consequence of Chef’s resource cloning.

The only change from the pastebin below is that I tried defining and explicitly passing in the variable that I have manipulated in my wrapper logic:

nagios_contactgroups = Nagios.instance.contactgroups

begin
t = resources(:template => “#{node[‘nagios’][‘config_dir’]}/contacts.cfg”)
t.source "contacts.cfg.erb"
t.cookbook "sm-nagios"
t.variables(:nagios_contactgroups => Nagios.instance.contactgroups)
#rescue Chef::Exceptions::ResourceNotFound

Chef::Log.warn “could not find template #{node[‘nagios’][‘config_dir’]/contacts.cfg to modify”

End

Can anyone shed light on why the cloned resource is superseding my attempt to open back up the object and re-render it?
The problem with the clone behavior (well, one of them) is that you end up with two resources of the same type+name, but Chef elsewhere treats type+name as a unique id for a resource in the collection. Therefore, anything that looks up a resource by name+type (like the resources method) is going to have undefined behavior when resources have been cloned.


Daniel DeLeo


#3

Thank you for clarifying that Daniel.

This information is definitely making me reconsider the viability of the
wrapper cookbook development method.

Would you happen to know if there is any more up to date information on
this issue than the final comment in CHEF-3694?

Would you (or anyone else on the thread with us) be able to tell me if
there a way to identify which version of the object you are referencing?
It might save me some debug time if I ever encounter a similar issue.

Thanks,
Joe

On 5/18/15, 1:29 PM, “Daniel DeLeo” dan@kallistec.com wrote:

On Monday, May 18, 2015 at 9:25 AM, Joseph Hammerman wrote:

Hi Chef users email distribution list,

An update on this item: if I set load_default_config to false my
template renders correctly. Therefore, I conclude that the observed
behavior is a consequence of Chef¹s resource cloning.

The only change from the pastebin below is that I tried defining and
explicitly passing in the variable that I have manipulated in my wrapper
logic:

nagios_contactgroups = Nagios.instance.contactgroups

begin
t = resources(:template =>
"#{node[‘nagios’][‘config_dir’]}/contacts.cfg")
t.source "contacts.cfg.erb"
t.cookbook "sm-nagios"
t.variables(:nagios_contactgroups => Nagios.instance.contactgroups)
#rescue Chef::Exceptions::ResourceNotFound

Chef::Log.warn "could not find template

#{node[‘nagios’][‘config_dir’]/contacts.cfg to modify"
End

Can anyone shed light on why the cloned resource is superseding my
attempt to open back up the object and re-render it?
The problem with the clone behavior (well, one of them) is that you end
up with two resources of the same type+name, but Chef elsewhere treats
type+name as a unique id for a resource in the collection. Therefore,
anything that looks up a resource by name+type (like the resources
method) is going to have undefined behavior when resources have been
cloned.


Daniel DeLeo


This message is intended only for the addressee. Please notify sender by e-mail if you are not the intended recipient. If you are not the intended recipient, you may not copy, disclose, or distribute this message or its contents to any other person and any such actions may be unlawful.
SecondMarket, Inc. (Member FINRA/SIPC, MSRB Registered) (“SecondMarket”) does
not accept time sensitive, action-oriented messages or transaction orders, including orders to purchase or sell securities, via e-mail.
SecondMarket reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the SecondMarket e-mail system and archived in accordance with FINRA and SEC regulations.
This message is intended for those with an in-depth understanding of the high risk and illiquid nature of alternative assets and these assets may not be suitable for you. This message is not a solicitation for an order, and there is not enough information contained in this message in which to make an investment decision and any information contained herein should not be used as a basis for this purpose. SecondMarket does not produce in-house research, make recommendations to purchase or sell specific securities, provide investment advisory services, or conduct a general retail business.


#4

Joe,

The wrapper cookbook pattern is well worth it, IMO. Your problem seems related to architecture of the community cookbook and your internal needs. Maybe it would be helpful to open an issue in the nagios cookbook issue tracker to see if they can change/add something to help.

Drew

On May 18, 2015, at 9:22 PM, Joseph Hammerman JHammerman@secondmarket.com wrote:

Thank you for clarifying that Daniel.

This information is definitely making me reconsider the viability of the
wrapper cookbook development method.

Would you happen to know if there is any more up to date information on
this issue than the final comment in CHEF-3694?

Would you (or anyone else on the thread with us) be able to tell me if
there a way to identify which version of the object you are referencing?
It might save me some debug time if I ever encounter a similar issue.

Thanks,
Joe

On 5/18/15, 1:29 PM, “Daniel DeLeo” dan@kallistec.com wrote:

On Monday, May 18, 2015 at 9:25 AM, Joseph Hammerman wrote:

Hi Chef users email distribution list,

An update on this item: if I set load_default_config to false my
template renders correctly. Therefore, I conclude that the observed
behavior is a consequence of Chef¹s resource cloning.

The only change from the pastebin below is that I tried defining and
explicitly passing in the variable that I have manipulated in my wrapper
logic:

nagios_contactgroups = Nagios.instance.contactgroups

begin
t = resources(:template =>
"#{node[‘nagios’][‘config_dir’]}/contacts.cfg")
t.source "contacts.cfg.erb"
t.cookbook "sm-nagios"
t.variables(:nagios_contactgroups => Nagios.instance.contactgroups)
#rescue Chef::Exceptions::ResourceNotFound

Chef::Log.warn "could not find template

#{node[‘nagios’][‘config_dir’]/contacts.cfg to modify"
End

Can anyone shed light on why the cloned resource is superseding my
attempt to open back up the object and re-render it?
The problem with the clone behavior (well, one of them) is that you end
up with two resources of the same type+name, but Chef elsewhere treats
type+name as a unique id for a resource in the collection. Therefore,
anything that looks up a resource by name+type (like the resources
method) is going to have undefined behavior when resources have been
cloned.


Daniel DeLeo


This message is intended only for the addressee. Please notify sender by e-mail if you are not the intended recipient. If you are not the intended recipient, you may not copy, disclose, or distribute this message or its contents to any other person and any such actions may be unlawful.
SecondMarket, Inc. (Member FINRA/SIPC, MSRB Registered) (“SecondMarket”) does
not accept time sensitive, action-oriented messages or transaction orders, including orders to purchase or sell securities, via e-mail.
SecondMarket reserves the right to monitor and review the content of all messages sent to or from this e-mail address. Messages sent to or from this e-mail address may be stored on the SecondMarket e-mail system and archived in accordance with FINRA and SEC regulations.
This message is intended for those with an in-depth understanding of the high risk and illiquid nature of alternative assets and these assets may not be suitable for you. This message is not a solicitation for an order, and there is not enough information contained in this message in which to make an investment decision and any information contained herein should not be used as a basis for this purpose. SecondMarket does not produce in-house research, make recommendations to purchase or sell specific securities, provide investment advisory services, or conduct a general retail business.