From 8d67a3e96be9175bde2f008cc5f102aabdafdc5f Mon Sep 17 00:00:00 2001 From: Justin Ridgewell Date: Fri, 15 Apr 2016 11:18:50 -0400 Subject: [PATCH] Add PHP-FPM recipe (#253) --- recipes/php_fpm.rb | 18 ++++++++ spec/integrations/php_fpm_spec.rb | 67 ++++++++++++++++++++++++++++++ templates/default/php_fpm.yaml.erb | 4 ++ 3 files changed, 89 insertions(+) create mode 100644 recipes/php_fpm.rb create mode 100644 spec/integrations/php_fpm_spec.rb create mode 100644 templates/default/php_fpm.yaml.erb diff --git a/recipes/php_fpm.rb b/recipes/php_fpm.rb new file mode 100644 index 00000000..9294de47 --- /dev/null +++ b/recipes/php_fpm.rb @@ -0,0 +1,18 @@ +include_recipe 'datadog::dd-agent' + +# Build a data structure with configuration. +# @see https://github.com/DataDog/dd-agent/blob/master/conf.d/php_fpm.yaml.example PHP-FPM Example +# @example +# node.override['datadog']['php_fpm']['instances'] = [ +# { +# 'status_url' => 'http://localhost/status', +# 'ping_url' => 'http://localhost/ping', +# 'ping_reply' => 'pong', +# 'user' => 'bits', +# 'password' => 'D4T4D0G', +# 'tags' => ['prod'] +# } +# ] +datadog_monitor 'php_fpm' do + instances node['datadog']['php_fpm']['instances'] +end diff --git a/spec/integrations/php_fpm_spec.rb b/spec/integrations/php_fpm_spec.rb new file mode 100644 index 00000000..e484325e --- /dev/null +++ b/spec/integrations/php_fpm_spec.rb @@ -0,0 +1,67 @@ +describe 'datadog::php_fpm' do + expected_yaml = <<-EOF + init_config: + + instances: + - status_url: http://localhost/status + user: user + password: mypassword + tags: + - optional_tag1 + - optional_tag2 + - ping_url: http://localhost/ping + ping_reply: pong + user: user + password: mypassword + tags: + - optional_tag1 + - optional_tag2 + EOF + + cached(:chef_run) do + ChefSpec::SoloRunner.new(step_into: ['datadog_monitor']) do |node| + node.automatic['languages'] = { 'python' => { 'version' => '2.7.2' } } + + node.set['datadog'] = { + 'api_key' => 'someapikey', + 'php_fpm' => { + 'instances' => [ + { + 'password' => 'mypassword', + 'status_url' => 'http://localhost/status', + 'user' => 'user', + 'tags' => [ + 'optional_tag1', + 'optional_tag2' + ] + }, + { + 'password' => 'mypassword', + 'ping_url' => 'http://localhost/ping', + 'ping_reply' => 'pong', + 'user' => 'user', + 'tags' => [ + 'optional_tag1', + 'optional_tag2' + ] + } + ] + } + } + end.converge(described_recipe) + end + + subject { chef_run } + + it_behaves_like 'datadog-agent' + + it { is_expected.to include_recipe('datadog::dd-agent') } + + it { is_expected.to add_datadog_monitor('php_fpm') } + + it 'renders expected YAML config file' do + expect(chef_run).to render_file('/etc/dd-agent/conf.d/php_fpm.yaml').with_content { |content| + expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json) + } + end +end diff --git a/templates/default/php_fpm.yaml.erb b/templates/default/php_fpm.yaml.erb new file mode 100644 index 00000000..a90a865b --- /dev/null +++ b/templates/default/php_fpm.yaml.erb @@ -0,0 +1,4 @@ +<%= JSON.parse(({ 'instances' => @instances }).to_json).to_yaml %> + +init_config: +# nothing to add here