Skip to content

Commit

Permalink
Simple type to manage the dashboard configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
rodjek committed Apr 29, 2012
1 parent 55d4957 commit be2ce33
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 0 deletions.
63 changes: 63 additions & 0 deletions lib/puppet/provider/sensu_dashboard_config/json.rb
Original file line number Diff line number Diff line change
@@ -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
41 changes: 41 additions & 0 deletions lib/puppet/type/sensu_dashboard_config.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit be2ce33

Please sign in to comment.