From be2ce33eeb49ae112eec4ce4dbbd6cf3cdddcd7c Mon Sep 17 00:00:00 2001 From: Tim Sharpe Date: Sun, 29 Apr 2012 13:20:50 +1000 Subject: [PATCH] Simple type to manage the dashboard configuration --- .../provider/sensu_dashboard_config/json.rb | 63 +++++++++++++++++++ lib/puppet/type/sensu_dashboard_config.rb | 41 ++++++++++++ 2 files changed, 104 insertions(+) create mode 100644 lib/puppet/provider/sensu_dashboard_config/json.rb create mode 100644 lib/puppet/type/sensu_dashboard_config.rb diff --git a/lib/puppet/provider/sensu_dashboard_config/json.rb b/lib/puppet/provider/sensu_dashboard_config/json.rb new file mode 100644 index 0000000000..59b37eecc5 --- /dev/null +++ b/lib/puppet/provider/sensu_dashboard_config/json.rb @@ -0,0 +1,63 @@ +require 'json' + +Puppet::Type.type(:sensu_dashboard_config).provide(:json) do + def initialize(*args) + super + + @conf = JSON.parse(File.read('/etc/sensu/config.json')) + end + + def flush + File.open('/etc/sensu/config.json', 'w') do |f| + f.puts JSON.pretty_generate(@conf) + end + end + + def create + @conf['dashboard'] = {} + self.port = resource[:port] + self.host = resource[:host] + self.user = resource[:user] + self.password = resource[:password] + end + + def destroy + @conf.delete 'dashboard' + end + + def exists? + @conf.has_key? 'dashboard' + end + + def port + @conf['dashboard']['port'].to_s + end + + def port=(value) + @conf['dashboard']['port'] = value.to_i + end + + def host + @conf['dashboard']['host'] + end + + def host=(value) + @conf['dashboard']['host'] = value + end + + def user + @conf['dashboard']['user'] + end + + def user=(value) + @conf['dashboard']['user'] = value + end + + def password + @conf['dashboard']['password'] + end + + def password=(value) + @conf['dashboard']['password'] = value + end +end diff --git a/lib/puppet/type/sensu_dashboard_config.rb b/lib/puppet/type/sensu_dashboard_config.rb new file mode 100644 index 0000000000..ca2d62418a --- /dev/null +++ b/lib/puppet/type/sensu_dashboard_config.rb @@ -0,0 +1,41 @@ +Puppet::Type.newtype(:sensu_dashboard_config) do + @doc = "" + + ensurable do + newvalue(:present) do + provider.create + end + + newvalue(:absent) do + provider.destroy + end + + defaultto :present + end + + newparam(:name) do + desc "This value has no effect, set it to what ever you want." + end + + newproperty(:port) do + desc "The port that the Sensu Dashboard should listen on" + + defaultto '5671' + end + + newproperty(:host) do + desc "The hostname that the Sensu Dashboard should listen on" + + defaultto 'localhost' + end + + newproperty(:user) do + desc "The username to use when connecting to the Sensu Dashboard" + + defaultto 'sensu' + end + + newproperty(:password) do + desc "The password to use when connecting to the Sensu Dashboard" + end +end