diff --git a/.kitchen.yml b/.kitchen.yml index dce1bf6b..91dbe759 100644 --- a/.kitchen.yml +++ b/.kitchen.yml @@ -415,6 +415,30 @@ suites: - "somepid" - "pidname" +- name: datadog_ssh_check + run_list: + - recipe[datadog::ssh_check] + attributes: + datadog: + <<: *DATADOG + ssh_check: + instances: + - host: localhost + username: root + password: password + add_missing_keys: false + tags: + - tag1 + - tag2 + - host: sftp_server.example.com + username: test + port: 2323 + sftp_check: true + private_key_file: /path/to/key + tags: + - tag1 + - tag3 + - name: datadog_supervisord run_list: - recipe[datadog::supervisord] diff --git a/recipes/ssh_check.rb b/recipes/ssh_check.rb new file mode 100644 index 00000000..0a0e81fd --- /dev/null +++ b/recipes/ssh_check.rb @@ -0,0 +1,24 @@ +include_recipe 'datadog::dd-agent' + +# Monitor SSH connectivity +# +# Assuming you have SSH connections you want to monitor, you will need to set +# up the following attributes at some point in your Chef run, in either a role +# or another cookbook. +# +# node['datadog']['ssh_check']['instances'] = [ +# { +# 'host' => '1.2.3.4', # required for each instance +# 'username' => 'user', # required for each instance +# 'password' => 'password', # optional +# 'port' => 22, # optional, defaults to 22 +# 'sftp_check' => true, # optional, defaults to true +# 'private_key_file' => '/path/to/key', # optional +# 'add_missing_keys' => false, # optional, defaults to false +# 'tags' => [node.chef_environment] # optional +# } +# ] + +datadog_monitor 'ssh_check' do + instances node['datadog']['ssh_check']['instances'] +end diff --git a/templates/default/ssh_check.yaml.erb b/templates/default/ssh_check.yaml.erb new file mode 100644 index 00000000..02b048d3 --- /dev/null +++ b/templates/default/ssh_check.yaml.erb @@ -0,0 +1,24 @@ +instances: +<% @instances.each do |i| -%> + - host: <%= i['host'] %> + username: <%= i['username'] %> + <% + keys = %w(password port sftp_check private_key_file add_missing_keys tags) + keys.each do |key| + if i.key?(key) + -%> + <%= key %>: <%= i[key] %> + <% + end + end + -%> + <% if i.key?('tags') -%> + tags: + <% i['tags'].each do |t| -%> + - <%= t %> + <% end -%> + <% end -%> +<% end -%> + +# Nothing to configure here +init_config: diff --git a/test/integration/datadog_ssh_check/serverspec/Gemfile b/test/integration/datadog_ssh_check/serverspec/Gemfile new file mode 120000 index 00000000..74f9789f --- /dev/null +++ b/test/integration/datadog_ssh_check/serverspec/Gemfile @@ -0,0 +1 @@ +../../helpers/serverspec/Gemfile \ No newline at end of file diff --git a/test/integration/datadog_ssh_check/serverspec/ssh_check_spec.rb b/test/integration/datadog_ssh_check/serverspec/ssh_check_spec.rb new file mode 100644 index 00000000..def67271 --- /dev/null +++ b/test/integration/datadog_ssh_check/serverspec/ssh_check_spec.rb @@ -0,0 +1,44 @@ +# Encoding: utf-8 +require 'json_spec' +require 'serverspec' +require 'yaml' + +set :backend, :exec +set :path, '/sbin:/usr/local/sbin:$PATH' + +AGENT_CONFIG = '/etc/dd-agent/conf.d/ssh_check.yaml' + +describe service('datadog-agent') do + it { should be_running } +end + +describe file(AGENT_CONFIG) do + it { should be_a_file } + + it 'is valid yaml matching input values' do + generated = YAML.load_file(AGENT_CONFIG) + + expected = { + 'instances' => [ + { + 'host' => 'localhost', + 'username' => 'root', + 'password' => 'password', + 'add_missing_keys' => false, + 'tags' => ['tag1', 'tag2'] + }, + { + 'host' => 'sftp_server.example.com', + 'username' => 'test', + 'port' => 2323, + 'sftp_check' => true, + 'private_key_file' => '/path/to/key', + 'tags' => ['tag1', 'tag3'] + } + ], + 'init_config' => nil + } + + expect(generated.to_json).to be_json_eql expected.to_json + end +end