Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding a datadog::ssh_check recipe to leverage SSH checks #262

Merged
merged 1 commit into from
Apr 15, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
24 changes: 24 additions & 0 deletions recipes/ssh_check.rb
Original file line number Diff line number Diff line change
@@ -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
24 changes: 24 additions & 0 deletions templates/default/ssh_check.yaml.erb
Original file line number Diff line number Diff line change
@@ -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:
1 change: 1 addition & 0 deletions test/integration/datadog_ssh_check/serverspec/Gemfile
44 changes: 44 additions & 0 deletions test/integration/datadog_ssh_check/serverspec/ssh_check_spec.rb
Original file line number Diff line number Diff line change
@@ -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