Commit 4122d2b Kyrill Poole
committed
1 parent 3e5e23c commit 4122d2b Copy full SHA for 4122d2b
File tree 3 files changed +149
-0
lines changed
provider/sensu_flapjack_config
3 files changed +149
-0
lines changed Original file line number Diff line number Diff line change
1
+ require 'rubygems' if RUBY_VERSION < '1.9.0' && Puppet . version < '3'
2
+ require 'json' if Puppet . features . json?
3
+
4
+ Puppet ::Type . type ( :sensu_flapjack_config ) . provide ( :json ) do
5
+ confine :feature => :json
6
+
7
+ def conf
8
+ begin
9
+ @conf ||= JSON . parse ( File . read ( config_file ) )
10
+ rescue
11
+ @conf ||= { }
12
+ end
13
+ end
14
+
15
+ def flush
16
+ File . open ( config_file , 'w' ) do |f |
17
+ f . puts JSON . pretty_generate ( conf )
18
+ end
19
+ end
20
+
21
+ def create
22
+ conf [ 'flapjack' ] = { }
23
+ self . port = resource [ :port ]
24
+ self . host = resource [ :host ]
25
+ self . db = resource [ :db ]
26
+ end
27
+
28
+ def config_file
29
+ "#{ resource [ :base_path ] } /flapjack.json"
30
+ end
31
+
32
+ def destroy
33
+ conf . delete 'flapjack'
34
+ end
35
+
36
+ def exists?
37
+ conf . has_key? 'flapjack'
38
+ end
39
+
40
+ def port
41
+ conf [ 'flapjack' ] [ 'port' ] . to_s
42
+ end
43
+
44
+ def port = ( value )
45
+ conf [ 'flapjack' ] [ 'port' ] = value . to_i
46
+ end
47
+
48
+ def host
49
+ conf [ 'flapjack' ] [ 'host' ]
50
+ end
51
+
52
+ def host = ( value )
53
+ conf [ 'flapjack' ] [ 'host' ] = value
54
+ end
55
+
56
+ def db
57
+ conf [ 'flapjack' ] [ 'db' ]
58
+ end
59
+
60
+ def db = ( value )
61
+ conf [ 'flapjack' ] [ 'db' ] = value . to_i
62
+ end
63
+ end
Original file line number Diff line number Diff line change
1
+ Puppet ::Type . newtype ( :sensu_flapjack_config ) do
2
+ @doc = ""
3
+
4
+ def initialize ( *args )
5
+ super
6
+
7
+ self [ :notify ] = [
8
+ "Service[sensu-api]" ,
9
+ "Service[sensu-server]" ,
10
+ ] . select { |ref | catalog . resource ( ref ) }
11
+ end
12
+
13
+ ensurable do
14
+ newvalue ( :present ) do
15
+ provider . create
16
+ end
17
+
18
+ newvalue ( :absent ) do
19
+ provider . destroy
20
+ end
21
+
22
+ defaultto :present
23
+ end
24
+
25
+ newparam ( :name ) do
26
+ desc "This value has no effect, set it to what ever you want."
27
+ end
28
+
29
+ newparam ( :base_path ) do
30
+ desc "The base path to the client config file"
31
+ defaultto '/etc/sensu/conf.d/'
32
+ end
33
+
34
+ newproperty ( :port ) do
35
+ desc "The port that Flapjack's Redis instance is listening on"
36
+
37
+ defaultto '6380'
38
+ end
39
+
40
+ newproperty ( :host ) do
41
+ desc "The hostname that Flapjack's Redis instance is listening on"
42
+
43
+ defaultto 'localhost'
44
+ end
45
+
46
+ newproperty ( :db ) do
47
+ desc "The Flapjack Redis DB to use"
48
+
49
+ defaultto '0'
50
+ end
51
+
52
+ autorequire ( :package ) do
53
+ [ 'sensu' ]
54
+ end
55
+ end
Original file line number Diff line number Diff line change
1
+ # = Class: sensu::flapjack::config
2
+ #
3
+ # Sets the Sensu flapjack config
4
+ #
5
+ class sensu::flapjack::config {
6
+
7
+ if $caller_module_name != $module_name {
8
+ fail(" Use of private class ${name} by ${caller_module_name} " )
9
+ }
10
+
11
+ if $sensu::purge_config and !$sensu::server and !$sensu::api {
12
+ $ensure = ' absent'
13
+ } else {
14
+ $ensure = ' present'
15
+ }
16
+
17
+ file { '/etc/sensu/conf.d/flapjack.json' :
18
+ ensure => $ensure ,
19
+ owner => ' sensu' ,
20
+ group => ' sensu' ,
21
+ mode => ' 0444' ,
22
+ }
23
+
24
+ sensu_flapjack_config { $::fqdn :
25
+ ensure => $ensure ,
26
+ host => $sensu::flapjack_redis_host ,
27
+ port => $sensu::flapjack_redis_port ,
28
+ db => $sensu::flapjack_redis_db ,
29
+ }
30
+
31
+ }
You can’t perform that action at this time.
0 commit comments