diff --git a/functions/clean_empty.pp b/functions/clean_empty.pp new file mode 100644 index 00000000..11e08b93 --- /dev/null +++ b/functions/clean_empty.pp @@ -0,0 +1,16 @@ +# For cleaning up empty elements on hashes and arrays +function datadog_agent::clean_empty ( + Any $var +) { + if $var.is_a(Array) { + $_var = $var.map |$item| { datadog_agent::clean_empty($item) } + $_var.filter |$item| { !datadog_agent::is_empty($item) } + + } elsif $var.is_a(Hash) { + $_var = Hash($var.map |$key, $value| { Tuple([$key, datadog_agent::clean_empty($value)]) }) + $_var.filter |$key, $value| { !datadog_agent::is_empty($value) } + + } elsif !datadog_agent::is_empty($var) { + $var + } +} diff --git a/functions/is_empty.pp b/functions/is_empty.pp new file mode 100644 index 00000000..5b038998 --- /dev/null +++ b/functions/is_empty.pp @@ -0,0 +1,10 @@ +# For testing if variable is empty +function datadog_agent::is_empty ( + Any $var +) { + if $var.is_a(Collection) or $var.is_a(String) or $var.is_a(Numeric) or $var.is_a(Binary) or $var.is_a(Undef) { + $var.empty + } else { + false + } +} \ No newline at end of file diff --git a/manifests/integrations/apache.pp b/manifests/integrations/apache.pp index 50b9ab06..09cccaf7 100644 --- a/manifests/integrations/apache.pp +++ b/manifests/integrations/apache.pp @@ -27,14 +27,29 @@ # } # class datadog_agent::integrations::apache ( - String $url = 'http://localhost/server-status?auto', - Optional[String] $username = undef, - Optional[String] $password = undef, - Array $tags = [], - Boolean $disable_ssl_validation = false + String $url = 'http://localhost/server-status?auto', + Optional[String] $username = undef, + Optional[String] $password = undef, + Array $tags = [], + Optional[Boolean] $disable_ssl_validation = undef, + Optional[Hash] $init_config = undef, + Optional[Array] $instances = undef, + Optional[Array] $logs = undef, ) inherits datadog_agent::params { require ::datadog_agent + if !$instances { + $_instances = datadog_agent::clean_empty([{ + 'apache_status_url' => $url, + 'apache_user' => $username, + 'apache_password' => $password, + 'tags' => $tags, + 'disable_ssl_validation' => $disable_ssl_validation, + }]) + } else { + $_instances = $instances + } + $legacy_dst = "${datadog_agent::params::legacy_conf_dir}/apache.yaml" if $::datadog_agent::_agent_major_version > 5 { $dst_dir = "${datadog_agent::params::conf_dir}/apache.d" diff --git a/manifests/integrations/http_check.pp b/manifests/integrations/http_check.pp index 11c2f44e..51d73877 100644 --- a/manifests/integrations/http_check.pp +++ b/manifests/integrations/http_check.pp @@ -196,7 +196,9 @@ $allow_redirects = true, $tags = [], $contact = [], - Optional[Array] $instances = undef, + Optional[Hash] $init_config = undef, + Optional[Array] $instances = undef, + Optional[Array] $logs = undef, $ca_certs = undef, ) inherits datadog_agent::params { require ::datadog_agent @@ -233,12 +235,46 @@ 'contact' => $contact, 'ca_certs' => $ca_certs, }] - } elsif !$instances{ + } elsif !$instances { $_instances = [] } else { $_instances = $instances } + $instances_array = $_instances.map |$instance| { + Hash($instance.map |$key, $value| { + case $key { + 'sitename': { + Tuple(['name', $value]) + } + + 'data', 'headers': { + if !$value.is_a(Array) { + Tuple([$key, $value]).next + } + + $value_hash = Hash($value.map |$item| { + $sub_item_array = $item.split(':') + $sub_item_key = $sub_item_array[0].rstrip + $sub_item_value = $sub_item_array[1, - 1].join(':').lstrip + + Tuple([$sub_item_key, $sub_item_value]) + }) + + Tuple([$key, datadog_agent::clean_empty($value_hash)]) + } + + 'tags': { + Tuple([$key, datadog_agent::clean_empty($value)]) + } + + default: { + Tuple([$key, $value]) + } + } + }) + } + $legacy_dst = "${datadog_agent::params::legacy_conf_dir}/http_check.yaml" if $::datadog_agent::_agent_major_version > 5 { $dst_dir = "${datadog_agent::params::conf_dir}/http_check.d" diff --git a/manifests/integrations/mysql.pp b/manifests/integrations/mysql.pp index 0781b121..05d409d9 100644 --- a/manifests/integrations/mysql.pp +++ b/manifests/integrations/mysql.pp @@ -63,13 +63,13 @@ # } # # -class datadog_agent::integrations::mysql( +class datadog_agent::integrations::mysql ( String $host = 'localhost', Optional[String] $user = 'datadog', Optional[Variant[String, Integer]] $port = 3306, Optional[String] $password = undef, Optional[String] $sock = undef, - Array $tags = [], + Optional[Array] $tags = undef, $replication = '0', $galera_cluster = '0', Boolean $extra_status_metrics = false, @@ -77,10 +77,11 @@ Boolean $extra_performance_metrics = false, Boolean $schema_size_metrics = false, Boolean $disable_innodb_metrics = false, - Optional[Array] $queries = [], + Optional[Array] $queries = undef, + Optional[Hash] $init_config = undef, Optional[Array] $instances = undef, - Optional[Array] $logs = [], - ) inherits datadog_agent::params { + Optional[Array] $logs = undef, +) inherits datadog_agent::params { require ::datadog_agent if ($host == undef and $sock == undef) or @@ -89,26 +90,51 @@ } if !$instances and $host { - $_instances = [{ - 'host' => $host, - 'password' => $password, - 'user' => $user, - 'port' => $port, - 'sock' => $sock, - 'tags' => $tags, - 'replication' => $replication, - 'galera_cluster' => $galera_cluster, - 'extra_status_metrics' => $extra_status_metrics, - 'extra_innodb_metrics' => $extra_innodb_metrics, - 'extra_performance_metrics' => $extra_performance_metrics, - 'schema_size_metrics' => $schema_size_metrics, - 'disable_innodb_metrics' => $disable_innodb_metrics, - 'queries' => $queries, - }] - } elsif !$instances{ + $_instances = datadog_agent::clean_empty([{ + 'server' => $host, + 'pass' => $password, + 'user' => $user, + 'port' => $port, + 'sock' => $sock, + 'tags' => $tags, + 'options' => { + 'replication' => $replication, + 'galera_cluster' => $galera_cluster, + 'extra_status_metrics' => $extra_status_metrics, + 'extra_innodb_metrics' => $extra_innodb_metrics, + 'extra_performance_metrics' => $extra_performance_metrics, + 'schema_size_metrics' => $schema_size_metrics, + 'disable_innodb_metrics' => $disable_innodb_metrics, + }, + 'queries' => $queries, + }]) + } elsif !$instances { $_instances = [] } else { - $_instances = $instances + $_instances = datadog_agent::clean_empty($instances.map |$instance| { + if $instance['host'] { + { + 'server' => $instance['host'], + 'pass' => $instance['password'], + 'user' => $instance['user'], + 'port' => $instance['port'], + 'sock' => $instance['sock'], + 'tags' => $instance['tags'], + 'options' => { + 'replication' => $instance['replication'], + 'galera_cluster' => $instance['galera_cluster'], + 'extra_status_metrics' => $instance['extra_status_metrics'], + 'extra_innodb_metrics' => $instance['extra_innodb_metrics'], + 'extra_performance_metrics' => $instance['extra_performance_metrics'], + 'schema_size_metrics' => $instance['schema_size_metrics'], + 'disable_innodb_metrics' => $instance['disable_innodb_metrics'], + }, + 'queries' => $queries, + } + } else { + $instance + } + }) } $legacy_dst = "${datadog_agent::params::legacy_conf_dir}/mysql.yaml" diff --git a/spec/classes/datadog_agent_integrations_apache_spec.rb b/spec/classes/datadog_agent_integrations_apache_spec.rb index eef84648..3ab8dba6 100644 --- a/spec/classes/datadog_agent_integrations_apache_spec.rb +++ b/spec/classes/datadog_agent_integrations_apache_spec.rb @@ -100,6 +100,25 @@ skip('doubly undefined behavior') end + + context 'with instances hash' do + let(:params) do + { + instances: [ + { + 'apache_status_url' => 'http://foobar', + 'apache_user' => 'userfoo', + 'apache_password' => 'passfoo', + 'tags' => ['foo', 'bar', 'baz'], + }, + ], + } + end + + it { is_expected.to contain_file(conf_file).with_content(%r{apache_status_url: http://foobar}) } + it { is_expected.to contain_file(conf_file).with_content(%r{apache_user: userfoo}) } + it { is_expected.to contain_file(conf_file).with_content(%r{apache_password: passfoo}) } + end end end end diff --git a/spec/classes/datadog_agent_integrations_http_check_spec.rb b/spec/classes/datadog_agent_integrations_http_check_spec.rb index c0eeeb82..5ae9b6cb 100644 --- a/spec/classes/datadog_agent_integrations_http_check_spec.rb +++ b/spec/classes/datadog_agent_integrations_http_check_spec.rb @@ -65,7 +65,7 @@ collect_response_time: false, disable_ssl_validation: true, skip_event: true, - http_response_status_code: '503', + http_response_status_code: 503, no_proxy: true, check_certificate_expiration: true, days_warning: 14, @@ -85,7 +85,7 @@ it { is_expected.to contain_file(conf_file).with_content(%r{data: key=value}) } it { is_expected.to contain_file(conf_file).with_content(%r{threshold: 456}) } it { is_expected.to contain_file(conf_file).with_content(%r{window: 789}) } - it { is_expected.to contain_file(conf_file).with_content(%r{content_match: 'foomatch'}) } + it { is_expected.to contain_file(conf_file).with_content(%r{content_match: foomatch}) } it { is_expected.to contain_file(conf_file).with_content(%r{reverse_content_match: true}) } it { is_expected.to contain_file(conf_file).with_content(%r{include_content: true}) } it { is_expected.to contain_file(conf_file).without_content(%r{collect_response_time: true}) } @@ -97,7 +97,7 @@ it { is_expected.to contain_file(conf_file).with_content(%r{days_warning: 14}) } it { is_expected.to contain_file(conf_file).with_content(%r{days_critical: 7}) } it { is_expected.to contain_file(conf_file).with_content(%r{allow_redirects: true}) } - it { is_expected.to contain_file(conf_file).with_content(%r{ca_certs: /dev/null}) } + it { is_expected.to contain_file(conf_file).with_content(%r{ca_certs: "/dev/null"}) } end context 'with json post data' do @@ -116,52 +116,6 @@ it { is_expected.to contain_file(conf_file).with_content(%r{headers:\s+Content-Type:\s+application/json}) } end - context 'with headers parameter array' do - let(:params) do - { - sitename: 'foo.bar.baz', - url: 'http://foo.bar.baz:4096', - headers: ['foo', 'bar', 'baz'], - } - end - - it { is_expected.to contain_file(conf_file).with_content(%r{headers:\s+foo\s+bar\s+baz\s*?[^-]}m) } - end - - context 'with headers parameter empty values' do - context 'mixed in with other headers' do - let(:params) do - { - sitename: 'foo.bar.baz', - url: 'http://foo.bar.baz:4096', - headers: ['foo', '', 'baz'], - } - end - - it { is_expected.to contain_file(conf_file).with_content(%r{headers:\s+foo\s+baz\s*?[^-]}m) } - end - - context 'single element array of an empty string' do - let(:params) do - { - headers: [''], - } - end - - skip('undefined behavior') - end - - context 'single value empty string' do - let(:params) do - { - headers: '', - } - end - - skip('doubly undefined behavior') - end - end - context 'with tags parameter array' do let(:params) do { @@ -220,6 +174,62 @@ it { is_expected.to contain_file(conf_file).with_content(%r{notify:\s+- alice\s+bob\s+carlo}) } end end + + context 'with instances hash' do + let(:params) do + { + instances: [ + { + 'name' => 'foo.bar.baz', + 'url' => 'http://foo.bar.baz:4096', + 'username' => 'foouser', + 'password' => 'barpassword', + 'timeout' => 123, + 'method' => 'post', + 'data' => 'key=value', + 'threshold' => 456, + 'window' => 789, + 'content_match' => 'foomatch', + 'reverse_content_match' => true, + 'include_content' => true, + 'collect_response_time' => false, + 'disable_ssl_validation' => true, + 'skip_event' => true, + 'http_response_status_code' => 503, + 'no_proxy' => true, + 'check_certificate_expiration' => true, + 'days_warning' => 14, + 'days_critical' => 7, + 'allow_redirects' => true, + 'ca_certs' => '/dev/null', + }, + ], + } + end + + it { is_expected.to contain_file(conf_file).with_content(%r{name: foo.bar.baz}) } + it { is_expected.to contain_file(conf_file).with_content(%r{url: http://foo.bar.baz:4096}) } + it { is_expected.to contain_file(conf_file).with_content(%r{username: foouser}) } + it { is_expected.to contain_file(conf_file).with_content(%r{password: barpassword}) } + it { is_expected.to contain_file(conf_file).with_content(%r{timeout: 123}) } + it { is_expected.to contain_file(conf_file).with_content(%r{method: post}) } + it { is_expected.to contain_file(conf_file).with_content(%r{data: key=value}) } + it { is_expected.to contain_file(conf_file).with_content(%r{threshold: 456}) } + it { is_expected.to contain_file(conf_file).with_content(%r{window: 789}) } + it { is_expected.to contain_file(conf_file).with_content(%r{content_match: foomatch}) } + it { is_expected.to contain_file(conf_file).with_content(%r{reverse_content_match: true}) } + it { is_expected.to contain_file(conf_file).with_content(%r{include_content: true}) } + it { is_expected.to contain_file(conf_file).without_content(%r{collect_response_time: true}) } + it { is_expected.to contain_file(conf_file).with_content(%r{disable_ssl_validation: true}) } + it { is_expected.to contain_file(conf_file).with_content(%r{skip_event: true}) } + it { is_expected.to contain_file(conf_file).with_content(%r{http_response_status_code: 503}) } + it { is_expected.to contain_file(conf_file).with_content(%r{no_proxy: true}) } + it { is_expected.to contain_file(conf_file).with_content(%r{check_certificate_expiration: true}) } + it { is_expected.to contain_file(conf_file).with_content(%r{days_warning: 14}) } + it { is_expected.to contain_file(conf_file).with_content(%r{days_critical: 7}) } + it { is_expected.to contain_file(conf_file).with_content(%r{allow_redirects: true}) } + it { is_expected.to contain_file(conf_file).with_content(%r{ca_certs: "/dev/null"}) } + end end end end diff --git a/spec/classes/datadog_agent_integrations_mysql_spec.rb b/spec/classes/datadog_agent_integrations_mysql_spec.rb index 74c86804..746d5bad 100644 --- a/spec/classes/datadog_agent_integrations_mysql_spec.rb +++ b/spec/classes/datadog_agent_integrations_mysql_spec.rb @@ -40,8 +40,8 @@ it { is_expected.to contain_file(conf_file).with_content(%r{server: localhost}) } it { is_expected.to contain_file(conf_file).with_content(%r{user: datadog}) } it { is_expected.to contain_file(conf_file).without_content(%r{sock: }) } - it { is_expected.to contain_file(conf_file).with_content(%r{replication: 0}) } - it { is_expected.to contain_file(conf_file).with_content(%r{galera_cluster: 0}) } + it { is_expected.to contain_file(conf_file).with_content(%r{replication: '0'}) } + it { is_expected.to contain_file(conf_file).with_content(%r{galera_cluster: '0'}) } end end @@ -60,9 +60,9 @@ it { is_expected.to contain_file(conf_file).with_content(%r{pass: foobar}) } it { is_expected.to contain_file(conf_file).with_content(%r{server: mysql1}) } it { is_expected.to contain_file(conf_file).with_content(%r{user: baz}) } - it { is_expected.to contain_file(conf_file).with_content(%r{sock: /tmp/mysql.foo.sock}) } - it { is_expected.to contain_file(conf_file).with_content(%r{replication: 1}) } - it { is_expected.to contain_file(conf_file).with_content(%r{galera_cluster: 1}) } + it { is_expected.to contain_file(conf_file).with_content(%r{sock: "/tmp/mysql.foo.sock"}) } + it { is_expected.to contain_file(conf_file).with_content(%r{replication: '1'}) } + it { is_expected.to contain_file(conf_file).with_content(%r{galera_cluster: '1'}) } end context 'with tags parameter array' do @@ -103,7 +103,49 @@ end it { is_expected.to contain_file(conf_file).with_content(%r{- query}) } - it { is_expected.to contain_file(conf_file).with_content(%r{query: SELECT TIMESTAMPDIFF\(second,MAX\(create_time\),NOW\(\)\) as last_accessed FROM requests}) } + it { is_expected.to contain_file(conf_file).with_content(%r{query: SELECT TIMESTAMPDIFF\(second,MAX\(create_time\),NOW\(\)\) as last_accessed FROM}) } + it { is_expected.to contain_file(conf_file).with_content(%r{metric: app.seconds_since_last_request}) } + it { is_expected.to contain_file(conf_file).with_content(%r{type: gauge}) } + it { is_expected.to contain_file(conf_file).with_content(%r{field: last_accessed}) } + end + + context 'with instances hash' do + let(:params) do + { + instances: [ + { + 'server' => 'mysql1', + 'pass' => 'foobar', + 'user' => 'baz', + 'sock' => '/tmp/mysql.foo.sock', + 'tags' => ['foo', 'bar', 'baz'], + 'options' => { + 'replication' => 1, + 'galera_cluster' => 1, + }, + 'queries' => [ + { + 'query' => 'SELECT TIMESTAMPDIFF(second,MAX(create_time),NOW()) as last_accessed FROM requests', + 'metric' => 'app.seconds_since_last_request', + 'type' => 'gauge', + 'field' => 'last_accessed', + }, + ], + }, + ], + } + end + + it { is_expected.to contain_file(conf_file).with_content(%r{server: mysql1}) } + it { is_expected.to contain_file(conf_file).with_content(%r{pass: foobar}) } + it { is_expected.to contain_file(conf_file).with_content(%r{user: baz}) } + it { is_expected.to contain_file(conf_file).with_content(%r{sock: "/tmp/mysql.foo.sock"}) } + it { is_expected.to contain_file(conf_file).with_content(%r{tags:[^-]+- foo\s+- bar\s+- baz\s*?[^-]}m) } + it { is_expected.to contain_file(conf_file).with_content(%r{options:}) } + it { is_expected.to contain_file(conf_file).with_content(%r{replication: 1}) } + it { is_expected.to contain_file(conf_file).with_content(%r{galera_cluster: 1}) } + it { is_expected.to contain_file(conf_file).with_content(%r{- query}) } + it { is_expected.to contain_file(conf_file).with_content(%r{query: SELECT TIMESTAMPDIFF\(second,MAX\(create_time\),NOW\(\)\) as last_accessed FROM}) } it { is_expected.to contain_file(conf_file).with_content(%r{metric: app.seconds_since_last_request}) } it { is_expected.to contain_file(conf_file).with_content(%r{type: gauge}) } it { is_expected.to contain_file(conf_file).with_content(%r{field: last_accessed}) } diff --git a/templates/agent-conf.d/apache.yaml.erb b/templates/agent-conf.d/apache.yaml.erb index 93afc187..1570f936 100644 --- a/templates/agent-conf.d/apache.yaml.erb +++ b/templates/agent-conf.d/apache.yaml.erb @@ -1,24 +1,3 @@ ### MANAGED BY PUPPET - -init_config: - -instances: - - apache_status_url: <%= @url %> -<% if @disable_ssl_validation -%> - disable_ssl_validation: <%= @disable_ssl_validation %> -<% end -%> -<% if @username -%> - apache_user: <%= @username %> -<% end -%> -<% if @password -%> - apache_password: <%= @password %> -<% end -%> -<% if @tags and ! @tags.empty? -%> - tags: - <%- Array(@tags).each do |tag| -%> - <%- if tag != '' -%> - - <%= tag %> - <%- end -%> - <%- end -%> -<% end -%> - +<% require 'yaml' -%> +<%= {'init_config'=>@init_config, 'instances'=>@_instances, 'logs'=>@logs}.to_yaml %> diff --git a/templates/agent-conf.d/http_check.yaml.erb b/templates/agent-conf.d/http_check.yaml.erb index 46487072..b6de23b9 100644 --- a/templates/agent-conf.d/http_check.yaml.erb +++ b/templates/agent-conf.d/http_check.yaml.erb @@ -1,112 +1,3 @@ ### MANAGED BY PUPPET - -init_config: - -instances: -<%- (Array(@_instances)).each do |instance| -%> - - name: <%= instance['sitename'] %> - url: <%= instance['url'] %> -<% if instance['timeout'] -%> - timeout: <%= instance['timeout'] %> -<% end -%> -<% if instance['method'] -%> - method: <%= instance['method'] %> -<% end -%> -<% if instance['min_collection_interval'] -%> - min_collection_interval: <%= instance['min_collection_interval'] %> -<% end -%> -<% if instance['data'].is_a?(String) -%> - data: <%= instance['data'] %> -<% elsif instance['data'].is_a?(Array) -%> - data: - <%- instance['data'].each do |data| -%> - <%= data %> - <%- end -%> -<% end -%> -<% if instance['username'] -%> - username: <%= instance['username'] %> -<% end -%> -<% if instance['password'] -%> - password: <%= instance['password'] %> -<% end -%> -<% if instance['threshold'] -%> - threshold: <%= instance['threshold'] %> -<% end -%> -<% if instance['window'] -%> - window: <%= instance['window'] %> -<% end -%> -<% if instance['reverse_content_match'] -%> - reverse_content_match: <%= instance["reverse_content_match"] %> -<% end -%> -<% if instance['content_match'] -%> - content_match: '<%= instance["content_match"] %>' -<% end -%> -<% unless instance['include_content'].nil? -%> - include_content: <%= instance['include_content'] %> -<% end -%> -<% if instance['http_response_status_code'] -%> - http_response_status_code: <%= instance['http_response_status_code'] %> -<% end -%> -<% unless instance['collect_response_time'].nil? -%> - collect_response_time: <%= instance['collect_response_time'] %> -<% end -%> -<% unless instance['disable_ssl_validation'].nil? -%> - disable_ssl_validation: <%= instance['disable_ssl_validation'] %> -<% end -%> -<% unless instance['ignore_ssl_warning'].nil? -%> - ignore_ssl_warning: <%= instance['ignore_ssl_warning'] %> -<% end -%> -<% unless instance['skip_event'].nil? -%> - skip_event: <%= instance['skip_event'] %> -<% end -%> -<% unless instance['no_proxy'].nil? -%> - no_proxy: <%= instance['no_proxy'] %> -<% end -%> -<% if instance['ca_certs'] -%> - ca_certs: <%= instance['ca_certs'] %> -<% end -%> -<% unless instance['check_certificate_expiration'].nil? -%> - check_certificate_expiration: <%= instance['check_certificate_expiration'] %> -<% if instance['check_certificate_expiration'] == true -%> -<% if instance['days_warning'] -%> - days_warning: <%= instance['days_warning'] %> -<% end -%> -<% if instance['days_critical'] -%> - days_critical: <%= instance['days_critical'] %> -<% end -%> -<% if instance['check_hostname'] -%> - check_hostname: <%= instance['check_hostname'] %> -<% end -%> -<% if instance['ssl_server_name'] -%> - ssl_server_name: <%= instance['ssl_server_name'] %> -<% end -%> -<% end -%> -<% end -%> -<% if instance['headers'] and ! instance['headers'].empty? -%> - headers: - <%- Array(instance['headers']).each do |header| -%> - <%- if header != '' -%> - <%= header %> - <%- end -%> - <%- end -%> -<% end -%> -<% unless instance['allow_redirects'].nil? -%> - allow_redirects: <%= instance['allow_redirects'] %> -<% end -%> -<% if instance['tags'] and ! instance['tags'].empty? -%> - tags: - <%- Array(instance['tags']).each do |tag| -%> - <%- if tag != '' -%> - - <%= tag %> - <%- end -%> - <%- end -%> -<% end -%> -<% if instance['contacts'] and ! instance['contacts'].empty? -%> - notify: - <%- Array(instance['contacts']).each do |contact| -%> - <%- if contact != '' -%> - - <%= contact %> - <%- end -%> - <%- end -%> -<% end -%> -<% end -%> +<% require 'yaml' -%> +<%= {'init_config'=>@init_config, 'instances'=>@instances_array, 'logs'=>@logs}.to_yaml %> diff --git a/templates/agent-conf.d/mysql.yaml.erb b/templates/agent-conf.d/mysql.yaml.erb index 44c82873..1570f936 100644 --- a/templates/agent-conf.d/mysql.yaml.erb +++ b/templates/agent-conf.d/mysql.yaml.erb @@ -1,55 +1,3 @@ ### MANAGED BY PUPPET - -<% -require 'yaml' -%> - -init_config: - -instances: -<%- (Array(@_instances)).each do |instance| -%> - - server: <%= instance['host'] %> -<% if instance['user'] and instance['user'] != :undef -%> - user: <%= instance['user'] %> -<% end -%> -<% if instance['password'] and instance['password'] != :undef -%> - pass: <%= instance['password'] %> -<% end -%> -<% if instance['port'] and instance['port'] != :undef -%> - port: <%= instance['port'] %> -<% end -%> -<% if instance['sock'] and instance['sock'] != :undef -%> - sock: <%= instance['sock'] %> -<% end -%> - -<% if instance['tags'] and ! instance['tags'].empty? -%> - tags: - <%- Array(instance['tags']).each do |tag| -%> - <%- if tag != '' -%> - - <%= tag %> - <%- end -%> - <%- end -%> -<% end -%> - - options: # Optional - replication: <%= instance['replication'] %> - galera_cluster: <%= instance['galera_cluster'] %> - extra_status_metrics: <%= instance['extra_status_metrics'] %> - extra_innodb_metrics: <%= instance['extra_innodb_metrics'] %> - extra_performance_metrics: <%= instance['extra_performance_metrics'] %> - schema_size_metrics: <%= instance['schema_size_metrics'] %> - disable_innodb_metrics: <%= instance['disable_innodb_metrics'] %> - - <% if instance['queries'] and ! instance['queries'].empty? %> - queries: - <%- Array(instance['queries']).each do |query| -%> - - query: <%= query['query'] %> - metric: <%= query['metric'] %> - type: <%= query['type'] %> - field: <%= query['field'] %> - <%- end -%> - <%- end -%> - -<% end -%> - -<%= (Array({'logs'=>@logs}.to_yaml.lines))[1..-1].join %> \ No newline at end of file +<% require 'yaml' -%> +<%= {'init_config'=>@init_config, 'instances'=>@_instances, 'logs'=>@logs}.to_yaml %>