File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 99# Sample Usage:
1010#
1111# class { 'datadog_agent::integrations::haproxy' :
12- # url => 'http://localhost:8080',
13- # creds => { username => 'admin',
14- # password => 'password',
15- # },
12+ # url => 'http://localhost:8080',
13+ # creds => { username => 'admin',
14+ # password => 'password',
15+ # },
16+ # options => { collect_aggregates_only => 'False' },
1617# }
1718#
1819class datadog_agent::integrations::haproxy (
1920 $creds = {},
2021 $url = " http://${::ipaddress} :8080" ,
22+ $options = {},
2123 $instances = undef ,
2224) inherits datadog_agent::params {
2325 include datadog_agent
2426
2527 if !$instances and $url {
2628 $_instances = [{
27- ' creds' => $creds ,
28- ' url' => $url ,
29+ ' creds' => $creds ,
30+ ' url' => $url ,
31+ ' options' => $options ,
2932 }]
3033 } elsif !$instances {
3134 $_instances = []
Original file line number Diff line number Diff line change 1+ # Class: datadog_agent::integrations::twemproxy
2+ #
3+ # This class will install the necessary configuration for the twemproxy aka nutcracker integration
4+ #
5+ # Parameters:
6+ # $host:
7+ # The host twemproxy is running on. Defaults to '127.0.0.1'
8+ # $port
9+ # The twemproxy password for the datadog user. Defaults to 22222
10+ #
11+ # Sample Usage:
12+ #
13+ # class { 'datadog_agent::integrations::twemproxy' :
14+ # instances => [
15+ # {
16+ # 'host' => 'localhost',
17+ # 'port' => '22222',
18+ # },
19+ # {
20+ # 'host' => 'localhost',
21+ # 'port' => '22223',
22+ # },
23+ # ]
24+ # }
25+ #
26+ class datadog_agent::integrations::twemproxy (
27+ $host = ' localhost' ,
28+ $port = ' 22222' ,
29+ $instances = undef ,
30+ ) inherits datadog_agent::params {
31+ include datadog_agent
32+
33+ if !$instances and $host {
34+ $_instances = [{
35+ ' host' => $host ,
36+ ' port' => $port ,
37+ }]
38+ } elsif !$instances {
39+ $_instances = []
40+ } else {
41+ $_instances = $instances
42+ }
43+
44+ file { "${datadog_agent::params::conf_dir}/twemproxy.yaml" :
45+ ensure => file ,
46+ owner => $datadog_agent::params::dd_user ,
47+ group => $datadog_agent::params::dd_group ,
48+ mode => ' 0600' ,
49+ content => template (' datadog_agent/agent-conf.d/twemproxy.yaml.erb' ),
50+ require => Package[$datadog_agent::params::package_name ],
51+ notify => Service[$datadog_agent::params::service_name ]
52+ }
53+ }
Original file line number Diff line number Diff line change 5555 end
5656 end
5757
58+ context 'with options set' do
59+ let ( :params ) { {
60+ options : {
61+ 'optionk' => 'optionv' ,
62+ } ,
63+ } }
64+ it { should contain_file ( conf_file ) . with_content ( %r{optionk: optionv} ) }
65+ end
66+
5867 context 'with instances set' do
5968 let ( :params ) { {
6069 instances : [
6170 {
62- 'url' => 'http://foo.bar:8421' ,
63- 'creds' => {
71+ 'url' => 'http://foo.bar:8421' ,
72+ 'creds' => {
6473 'username' => 'foo' ,
6574 'password' => 'bar' ,
66- }
75+ } ,
76+ 'options' => {
77+ 'optionk1' => 'optionv1' ,
78+ } ,
6779 } ,
6880 {
69- 'url' => 'http://shoe.baz:1248' ,
70- 'creds' => {
81+ 'url' => 'http://shoe.baz:1248' ,
82+ 'creds' => {
7183 'username' => 'shoe' ,
7284 'password' => 'baz' ,
73- }
85+ } ,
86+ 'options' => {
87+ 'optionk2' => 'optionv2' ,
88+ } ,
7489 } ,
7590 ]
7691 } }
7792 it { should contain_file ( conf_file ) . with_content ( %r{url: http://foo.bar:8421} ) }
7893 it { should contain_file ( conf_file ) . with_content ( %r{username: foo} ) }
7994 it { should contain_file ( conf_file ) . with_content ( %r{password: bar} ) }
95+ it { should contain_file ( conf_file ) . with_content ( %r{optionk1: optionv1} ) }
8096 it { should contain_file ( conf_file ) . with_content ( %r{url: http://shoe.baz:1248} ) }
8197 it { should contain_file ( conf_file ) . with_content ( %r{username: shoe} ) }
8298 it { should contain_file ( conf_file ) . with_content ( %r{password: baz} ) }
99+ it { should contain_file ( conf_file ) . with_content ( %r{optionk2: optionv2} ) }
83100 end
84101end
Original file line number Diff line number Diff line change 1+ require 'spec_helper'
2+
3+ describe 'datadog_agent::integrations::twemproxy' do
4+ let ( :facts ) { {
5+ operatingsystem : 'Ubuntu' ,
6+ } }
7+ let ( :conf_dir ) { '/etc/dd-agent/conf.d' }
8+ let ( :dd_user ) { 'dd-agent' }
9+ let ( :dd_group ) { 'root' }
10+ let ( :dd_package ) { 'datadog-agent' }
11+ let ( :dd_service ) { 'datadog-agent' }
12+ let ( :conf_file ) { "#{ conf_dir } /twemproxy.yaml" }
13+
14+ it { should compile . with_all_deps }
15+ it { should contain_file ( conf_file ) . with (
16+ owner : dd_user ,
17+ group : dd_group ,
18+ mode : '0600' ,
19+ ) }
20+ it { should contain_file ( conf_file ) . that_requires ( "Package[#{ dd_package } ]" ) }
21+ it { should contain_file ( conf_file ) . that_notifies ( "Service[#{ dd_service } ]" ) }
22+
23+ context 'with default parameters' do
24+ it { should contain_file ( conf_file ) . with_content ( %r{host: localhost} ) }
25+ it { should contain_file ( conf_file ) . with_content ( %r{port: 22222} ) }
26+ end
27+
28+ context 'with parameters set' do
29+ let ( :params ) { {
30+ instances : [
31+ {
32+ 'host' => 'twemproxy1' ,
33+ 'port' => '1234' ,
34+ } ,
35+ {
36+ 'host' => 'twemproxy2' ,
37+ 'port' => '4567' ,
38+ }
39+ ]
40+ } }
41+ it { should contain_file ( conf_file ) . with_content ( %r{host: twemproxy1} ) }
42+ it { should contain_file ( conf_file ) . with_content ( %r{port: 1234} ) }
43+ it { should contain_file ( conf_file ) . with_content ( %r{host: twemproxy2} ) }
44+ it { should contain_file ( conf_file ) . with_content ( %r{port: 4567} ) }
45+ end
46+ end
Original file line number Diff line number Diff line change @@ -13,4 +13,9 @@ instances:
1313 <%= k %> : <%= v %>
1414 <%- end -%>
1515 <%- end -%>
16+ <%- if instance['options'] -%>
17+ <%- instance['options'].each do |k, v| -%>
18+ <%= k %> : <%= v %>
19+ <%- end -%>
20+ <%- end -%>
1621<% end -%>
Original file line number Diff line number Diff line change 1+ #
2+ # MANAGED BY PUPPET
3+ #
4+
5+ init_config:
6+
7+ instances:
8+ <%- (Array(@_instances)).each do |instance| -%>
9+ - host: <%= instance['host'] %>
10+ port: <%= instance['port'] %>
11+ <% end -%>
You can’t perform that action at this time.
0 commit comments