]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/definitions/munin_plugin.rb
Add a bunch more cookbooks
[chef.git] / cookbooks / munin / definitions / munin_plugin.rb
1 #
2 # Cookbook Name:: munin
3 # Definition:: munin_plugin
4 #
5 # Copyright 2010, OpenStreetMap Foundation
6 #
7 # Licensed under the Apache License, Version 2.0 (the "License");
8 # you may not use this file except in compliance with the License.
9 # You may obtain a copy of the License at
10 #
11 #     http://www.apache.org/licenses/LICENSE-2.0
12 #
13 # Unless required by applicable law or agreed to in writing, software
14 # distributed under the License is distributed on an "AS IS" BASIS,
15 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 # See the License for the specific language governing permissions and
17 # limitations under the License.
18 #
19
20 define :munin_plugin, :action => :create do
21   target = params[:target] || params[:name]
22
23   if File.exists?("/usr/local/share/munin/plugins/#{target}")
24     target_path = "/usr/local/share/munin/plugins/#{target}"
25   elsif File.exists?("/usr/share/munin/plugins/#{target}")
26     target_path = "/usr/share/munin/plugins/#{target}"
27   else
28     target_path = nil
29   end
30
31   if target_path.nil? or params[:action] == :delete
32     link "/etc/munin/plugins/#{params[:name]}" do
33       action :delete
34     end
35   else
36     link "/etc/munin/plugins/#{params[:name]}" do
37       action params[:action]
38       to target_path
39       notifies :restart, resources(:service => "munin-node")
40     end
41   end
42
43   if params[:conf]
44     conf_template = params[:conf]
45     conf_cookbook = params[:conf_cookbook]
46     conf_variables = params[:conf_variables]
47
48     munin_plugin_conf params[:name] do
49       action params[:action]
50       template conf_template
51       if conf_cookbook
52         cookbook conf_cookbook
53       end
54       if conf_variables
55         variables conf_variables
56       end
57     end
58   end
59 end