From 3a83aa06a3415386468cba28dfe254a5961af5ae Mon Sep 17 00:00:00 2001 From: gilles Date: Mon, 17 Oct 2011 15:55:07 -0700 Subject: [PATCH] possibility for perl plugins renamed module into mod as module is a reserved word in ruby --- collectd/attributes/default.rb | 1 + collectd/definitions/collectd_plugin.rb | 23 ++++++++++++++++--- .../templates/default/perl_plugin.conf.erb | 21 +++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 collectd/templates/default/perl_plugin.conf.erb diff --git a/collectd/attributes/default.rb b/collectd/attributes/default.rb index 230ff77..8f202e4 100644 --- a/collectd/attributes/default.rb +++ b/collectd/attributes/default.rb @@ -19,6 +19,7 @@ default[:collectd][:base_dir] = "/var/lib/collectd" default[:collectd][:plugin_dir] = "/usr/lib/collectd" +default[:collectd][:perl_include_dir] = "/usr/local/share/perl/5.10.1" default[:collectd][:types_db] = ["/usr/share/collectd/types.db"] default[:collectd][:interval] = 10 default[:collectd][:read_threads] = 5 diff --git a/collectd/definitions/collectd_plugin.rb b/collectd/definitions/collectd_plugin.rb index dd826e9..1e8babc 100644 --- a/collectd/definitions/collectd_plugin.rb +++ b/collectd/definitions/collectd_plugin.rb @@ -34,10 +34,10 @@ end end -define :collectd_python_plugin, :options => {}, :module => nil, :path => nil do +define :collectd_python_plugin, :options => {}, :mod => nil, :path => nil do begin t = resources(:template => "/etc/collectd/plugins/python.conf") - rescue ArgumentError + rescue Chef::Exceptions::ResourceNotFound collectd_plugin "python" do options :paths=>[node[:collectd][:plugin_dir]], :modules=>{} template "python_plugin.conf.erb" @@ -48,5 +48,22 @@ if not params[:path].blank? t.variables[:options][:paths] << params[:path] end - t.variables[:options][:modules][params[:module] || params[:name]] = params[:options] + t.variables[:options][:modules][params[:mod] || params[:name]] = params[:options] +end + +define :collectd_perl_plugin, :options => {}, :mod => nil, :include_dir => nil do + begin + t = resources(:template => "/etc/collectd/plugins/perl.conf") + rescue Chef::Exceptions::ResourceNotFound + collectd_plugin "perl" do + options :include_dir=>[node[:collectd][:perl_include_dir]], :modules=>{} + template "perl_plugin.conf.erb" + cookbook "collectd" + end + retry + end + if not params[:include_dir].nil? + t.variables[:options][:include_dir] << params[:include_dir] + end + t.variables[:options][:modules][params[:mod] || params[:name]] = params[:options] end diff --git a/collectd/templates/default/perl_plugin.conf.erb b/collectd/templates/default/perl_plugin.conf.erb new file mode 100644 index 0000000..e516a52 --- /dev/null +++ b/collectd/templates/default/perl_plugin.conf.erb @@ -0,0 +1,21 @@ +# This file autogenerated by Chef +# Do not edit, changes will be overwritten + + Globals true + + + + <% @options[:include_dir].each do |path| %> + IncludeDir "<%= path %>" + <% end %> + BaseName "Collectd::Plugins" + <% @options[:modules].each_key do |mod| %> + LoadPlugin "<%= mod %>" + <% end %> + + <% @options[:modules].each_pair do |mod, config| %> + "> + <%= collectd_settings(config, 2) %> + + <% end %> + \ No newline at end of file