]> git.openstreetmap.org Git - chef.git/blob - cookbooks/munin/providers/plugin.rb
Make the rrddump.sh script do all the work, including cleanup.
[chef.git] / cookbooks / munin / providers / plugin.rb
1 #
2 # Cookbook Name:: munin
3 # Provider:: munin_plugin
4 #
5 # Copyright 2013, 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 def whyrun_supported?
21   true
22 end
23
24 use_inline_resources
25
26 action :create do
27   link_action = case target_path
28                 when nil then :delete
29                 else :create
30                 end
31
32   link plugin_path do
33     action link_action
34     to target_path
35   end
36
37   if new_resource.conf # ~FC023
38     munin_plugin_conf new_resource.name do
39       cookbook new_resource.conf_cookbook
40       template new_resource.conf
41       variables new_resource.conf_variables
42       restart_munin false
43     end
44   end
45 end
46
47 action :delete do
48   link plugin_path do
49     action :delete
50   end
51
52   if new_resource.conf # ~FC023
53     munin_plugin_conf new_resource.name do
54       action :delete
55       restart_munin false
56     end
57   end
58 end
59
60 def plugin_path
61   "/etc/munin/plugins/#{new_resource.name}"
62 end
63
64 def target_path
65   if ::File.exist?(target)
66     target
67   elsif ::File.exist?("/usr/local/share/munin/plugins/#{target}")
68     "/usr/local/share/munin/plugins/#{target}"
69   elsif ::File.exist?("/usr/share/munin/plugins/#{target}")
70     "/usr/share/munin/plugins/#{target}"
71   end
72 end
73
74 def target
75   new_resource.target || new_resource.name
76 end