Skip to content

Commit 9640920

Browse files
committed
add client_subscription type
1 parent b80f3a4 commit 9640920

File tree

2 files changed

+61
-0
lines changed

2 files changed

+61
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
require 'rubygems' if RUBY_VERSION < '1.9.0' && Puppet.features.rubygems?
2+
require 'json' if Puppet.features.json?
3+
4+
Puppet::Type.type(:sensu_client_subscription).provide(:json) do
5+
confine :feature => :json
6+
7+
def initialize(*args)
8+
super
9+
10+
begin
11+
@conf = JSON.parse(File.read("/etc/sensu/conf.d/subscription_#{resource[:name]}.json"))
12+
rescue
13+
@conf = {}
14+
end
15+
end
16+
17+
def flush
18+
File.open("/etc/sensu/conf.d/subscription_#{resource[:name]}.json", 'w') do |f|
19+
f.puts JSON.pretty_generate(@conf)
20+
end
21+
end
22+
23+
def create
24+
@conf['client'] = {'subscriptions' => [ resource[:name] ] }
25+
end
26+
27+
def destroy
28+
@conf = nil
29+
end
30+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
Puppet::Type.newtype(:sensu_client_subscription) do
2+
@doc = ""
3+
4+
def initialize(*args)
5+
super
6+
7+
self[:notify] = [
8+
"Service[sensu-client]",
9+
].select { |ref| catalog.resource(ref) }
10+
end
11+
12+
ensurable do
13+
newvalue(:present) do
14+
provider.create
15+
end
16+
17+
newvalue(:absent) do
18+
provider.destroy
19+
end
20+
21+
defaultto :present
22+
end
23+
24+
newparam(:name) do
25+
desc "The subscription name"
26+
end
27+
28+
autorequire(:package) do
29+
['sensu']
30+
end
31+
end

0 commit comments

Comments
 (0)