diff --git a/manifests/integrations/ssh.pp b/manifests/integrations/ssh.pp new file mode 100644 index 00000000..142157dd --- /dev/null +++ b/manifests/integrations/ssh.pp @@ -0,0 +1,49 @@ +# Class: datadog_agent::integrations::ssh +# +# This class will enable ssh check +# +# Parameters: +# $host: +# ssh server to use for ssh check +# +# $port +# +# $username +# +# $password +# +# $sftp_check +# +# $private_key_file +# +# $add_missing_keys +# +# Sample Usage: +# +# class { 'datadog_agent::integrations::ssh' : +# host => 'localhost', +# private_key_file => '/opt/super_secret_key', +# } +# + +class datadog_agent::integrations::ssh( + $host = $::fqdn, + $port = 22, + $username = $datadog_agent::params::dd_user, + $password = undef, + $sftp_check = true, + $private_key_file = undef, + $add_missing_keys = true, +) inherits datadog_agent::params { + include ::datadog_agent + + file { "${datadog_agent::params::conf_dir}/ssh.yaml": + ensure => file, + owner => $datadog_agent::params::dd_user, + group => $datadog_agent::params::dd_group, + mode => '0600', + content => template('datadog_agent/agent-conf.d/ssh.yaml.erb'), + require => Package[$datadog_agent::params::package_name], + notify => Service[$datadog_agent::params::service_name] + } +} diff --git a/spec/classes/datadog_agent_integrations_ssh_spec.rb b/spec/classes/datadog_agent_integrations_ssh_spec.rb new file mode 100644 index 00000000..1a1bdc82 --- /dev/null +++ b/spec/classes/datadog_agent_integrations_ssh_spec.rb @@ -0,0 +1,32 @@ +require 'spec_helper' + +describe 'datadog_agent::integrations::ssh' do + let(:facts) {{ + operatingsystem: 'Ubuntu', + }} + let(:conf_dir) { '/etc/dd-agent/conf.d' } + let(:dd_user) { 'dd-agent' } + let(:dd_group) { 'root' } + let(:dd_package) { 'datadog-agent' } + let(:dd_service) { 'datadog-agent' } + let(:conf_file) { "#{conf_dir}/ssh.yaml" } + + context 'with default parameters' do + it { should compile } + end + + context 'with parameters set' do + let(:params) {{ + host: 'localhost', + port: 222, + username: 'foo', + password: 'bar', + sftp_check: false, + }} + it { should contain_file(conf_file).with_content(/host: localhost/) } + it { should contain_file(conf_file).with_content(/port: 222/) } + it { should contain_file(conf_file).with_content(/username: foo/) } + it { should contain_file(conf_file).with_content(/password: bar/) } + it { should contain_file(conf_file).without_content(/private_key_file:/) } + end +end diff --git a/templates/agent-conf.d/ssh.yaml.erb b/templates/agent-conf.d/ssh.yaml.erb new file mode 100644 index 00000000..6be72e59 --- /dev/null +++ b/templates/agent-conf.d/ssh.yaml.erb @@ -0,0 +1,19 @@ +# +# Managed by Puppet +# + +init_config: + +instances: + + - host: <%= @host %> + port: <%= @port %> + username: <%= @username %> +<% if @password -%> + password: <%= @password %> +<% end -%> + sftp_check: <%= @sftp_check %> +<% if @private_key_file -%> + private_key_file: <%= @private_key_file %> +<% end -%> + add_missing_keys: <%= @add_missing_keys %>