Commit 15c6a24 1 parent 4c5c93c commit 15c6a24 Copy full SHA for 15c6a24
File tree 3 files changed +117
-0
lines changed
provider/sensu_check_config
3 files changed +117
-0
lines changed Original file line number Diff line number Diff line change
1
+ require 'json'
2
+
3
+ Puppet ::Type . type ( :sensu_check_config ) . provide ( :json ) do
4
+ def initialize ( *args )
5
+ super
6
+
7
+ begin
8
+ @conf = JSON . parse ( File . read ( "/etc/sensu/conf.d/checks_#{ resource [ :name ] } .json" ) )
9
+ rescue
10
+ @conf = { }
11
+ end
12
+ end
13
+
14
+ def flush
15
+ File . open ( "/etc/sensu/conf.d/checks_#{ resource [ :name ] } .json" , 'w' ) do |f |
16
+ f . puts JSON . pretty_generate ( @conf )
17
+ end
18
+ end
19
+
20
+ def create
21
+ @conf [ 'checks' ] = { }
22
+ @conf [ 'checks' ] [ resource [ :name ] ] = { }
23
+ self . handlers = resource [ :handlers ]
24
+ self . command = resource [ :command ]
25
+ self . interval = resource [ :interval ]
26
+ self . subscribers = resource [ :subscribers ]
27
+ end
28
+
29
+ def destroy
30
+ @conf = nil
31
+ end
32
+
33
+ def exists?
34
+ @conf . has_key? ( 'checks' ) and @conf [ 'checks' ] . has_key? ( resource [ :name ] )
35
+ end
36
+
37
+ def interval
38
+ @conf [ 'checks' ] [ resource [ :name ] ] [ 'interval' ] . to_s
39
+ end
40
+
41
+ def interval = ( value )
42
+ @conf [ 'checks' ] [ resource [ :name ] ] [ 'interval' ] = value . to_i
43
+ end
44
+
45
+ def handlers
46
+ @conf [ 'checks' ] [ resource [ :name ] ] [ 'handlers' ] || [ ]
47
+ end
48
+
49
+ def handlers = ( value )
50
+ @conf [ 'checks' ] [ resource [ :name ] ] [ 'handlers' ] = value
51
+ end
52
+
53
+ def command
54
+ @conf [ 'checks' ] [ resource [ :name ] ] [ 'command' ]
55
+ end
56
+
57
+ def command = ( value )
58
+ @conf [ 'checks' ] [ resource [ :name ] ] [ 'command' ] = value
59
+ end
60
+
61
+ def subscribers
62
+ @conf [ 'checks' ] [ resource [ :name ] ] [ 'subscribers' ] || [ ]
63
+ end
64
+
65
+ def subscribers = ( value )
66
+ @conf [ 'checks' ] [ resource [ :name ] ] [ 'subscribers' ] = value
67
+ end
68
+ end
Original file line number Diff line number Diff line change
1
+ Puppet ::Type . newtype ( :sensu_check_config ) do
2
+ @doc = ""
3
+
4
+ ensurable do
5
+ newvalue ( :present ) do
6
+ provider . create
7
+ end
8
+
9
+ newvalue ( :absent ) do
10
+ provider . destroy
11
+ end
12
+
13
+ defaultto :present
14
+ end
15
+
16
+ newparam ( :name ) do
17
+ desc "The name of the check"
18
+ end
19
+
20
+ newproperty ( :handlers , :array_matching => :all ) do
21
+ desc ""
22
+ end
23
+
24
+ newproperty ( :command ) do
25
+ desc ""
26
+ end
27
+
28
+ newproperty ( :interval ) do
29
+ desc ""
30
+ end
31
+
32
+ newproperty ( :subscribers , :array_matching => :all ) do
33
+ desc ""
34
+ end
35
+ end
Original file line number Diff line number Diff line change
1
+ define sensu::check (
2
+ $command ,
3
+ $handlers = [],
4
+ $interval = ' 60' ,
5
+ $subscribers = []
6
+ ) {
7
+
8
+ sensu_check_config { $name:
9
+ command => $command ,
10
+ handlers => $handlers ,
11
+ interval => $interval ,
12
+ subscribers => $subscribers ,
13
+ }
14
+ }
You can’t perform that action at this time.
0 commit comments