hectcastro / chef-collectd

A Chef cookbook to install collectd.
Apache License 2.0
23 stars 65 forks source link

Write_graphite template is missing Host and Port directives #13

Closed rodriguezsergio closed 11 years ago

rodriguezsergio commented 11 years ago

Not sure why Chef isn't adding the Host and Port fields. I have two roles (base and monitoring) set up with client and server-specific attributes. This is a snippet from the monitoring role.

   'collectd' => {
      'graphite_ipaddress' => 'localhost',
        'plugins' => {
          'write_graphite' => {
            'config' => {
              'Prefix' => 'collectd.',
              'StoreRates' => true,
              'AlwaysAppendDS' => false,
              'EscapeCharacter' => '_'
          }

Which creates the following on my VM

#
# This file is generated by Chef
# Do not edit, changes will be overwritten
#
LoadPlugin "write_graphite"

<Plugin "write_graphite">
  <Carbon>
  Prefix "collectd."
  StoreRates true
  AlwaysAppendDS false
  EscapeCharacter "_"
  </Carbon>
</Plugin>

Looking at the logic in 'attribute_driven', it would appear that Host and Port would be inserted along with the attributes I specified in my role, but that's obviously not the case. The logic appears fine, but maybe I'm missing something here...

if node.default["collectd"]["plugins"].key?("write_graphite") # This exists so continue
  write_graphite = node.default["collectd"]["plugins"]["write_graphite"] # Grab the attributes that were set by the Chef Roles

  if node["collectd"]["graphite_ipaddress"].empty? # Not empty .. skip this
    [skipped]
  else 
    write_graphite["config"]["Host"] = node["collectd"]["graphite_ipaddress"] # Use the value I set, in this case 'localhost'
  end
  write_graphite["config"]["Port"] = 2003 # Set Port to 2003
end

While, this isn't really a big deal for me since I've alleviated it by adding the two keys to my role, I still think it's something worth checking out/fixing.

hectcastro commented 11 years ago

@srodrig0209, can you test with the changes in the pull request to see if they resolve your issue?

rodriguezsergio commented 11 years ago

Looks like it does.

#
# This file is generated by Chef
# Do not edit, changes will be overwritten
#
LoadPlugin "write_graphite"

<Plugin "write_graphite">
  <Carbon>
  Prefix "collectd."
  StoreRates true
  AlwaysAppendDS false
  EscapeCharacter "_"
  Host "localhost"
  Port 2003
  </Carbon>
</Plugin>