Add recipe for windows_service integration
Fixes
ADD
recipes/windows_service.rb
+#
+# Cookbook Name:: datadog
+# Recipe:: windows_service
+#
+
+# Example windows_service.yaml file:
+#
+# init_config:
+#
+# instances:
+# For each instance you define what host to connect to (defaulting to the
+# current host) as well as a list of services you care about. The service
+# names should match the Service name in the properties and NOT the display
+# name in the services.msc list.
+#
+# If you want to check services on a remote host, you have to specify a
+# hostname and (optional) credentials
+#
+#- host: MYREMOTESERVER
+# username: MYREMOTESERVER\fred
+# password: mysecretpassword
+# tags:
+# - fredserver
+#
+# The sample configuration will monitor the WMI Performance Adapter service,
+# named "wmiApSrv" in the service properties.
+#
+# - host: . # "." means the current host
+# services:
+# - wmiApSrv # service names are not case-sensitive
+
+# Example attributes for monitoring local Windows service:
+#
+# node['datadog']['windows_service']['instances'] = {
+# "instances": [
+# {
+# "services": ["RemoteServiceName"],
+# "host": "."
+# }
+# ]
+# }
+
+# Example attributes for monitoring remote Windows service:
+#
+# node['datadog']['windows_service']['instances'] = {
+# "instances": [
+# {
+# "username": "RemoteHostname\thomas",
+# "services": ["RemoteServiceName1", "RemoteServiceName2"],
+# "host": "RemoteHostName",
+# "password": "secretpw"
+# }
+# ]
+# }
+
+include_recipe 'datadog::dd-agent'
+
+datadog_monitor 'windows_service' do
+ instances node['datadog']['windows_service']['instances']
+end

ADD
spec/integrations/windows_service_spec.rb
+describe 'datadog::windows_service' do
+ expected_yaml = <<-EOF
+ instances:
+ - host: REMOTEHOSTNAME
+ username: REMOTEHOSTNAME\\thomas
+ password: secretpw
+ services:
+ - RemoteService1
+ - RemoteService2
+
+ init_config:
+
+ 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',
+ windows_service: {
+ instances: [
+ {
+ username: 'REMOTEHOSTNAME\\thomas',
+ services: ['RemoteService1', 'RemoteService2'],
+ host: 'REMOTEHOSTNAME',
+ password: 'secretpw'
+ }
+ ]
+ }
+ }
+ 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('windows_service') }
+
+ it 'renders expected YAML config file for remote host service monitoring' do
+ expect(chef_run).to render_file('/etc/dd-agent/conf.d/windows_service.yaml').with_content { |content|
+ expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json)
+ }
+ end
+end
+
+describe 'datadog::windows_service' do
+ expected_yaml = <<-EOF
+ instances:
+ - host: .
+ services:
+ - LocalService1
+ - LocalService2
+
+ init_config:
+
+ 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',
+ windows_service: {
+ instances: [
+ {
+ services: ['LocalService1', 'LocalService2'],
+ host: '.'
+ }
+ ]
+ }
+ }
+ 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('windows_service') }
+
+ it 'renders expected YAML config file for local host service monitoring' do
+ expect(chef_run).to render_file('/etc/dd-agent/conf.d/windows_service.yaml').with_content { |content|
+ expect(YAML.load(content).to_json).to be_json_eql(YAML.load(expected_yaml).to_json)
+ }
+ end
+end

ADD
templates/default/windows_service.yaml.erb
+# Generated by Chef, local modifications will be overwritten
+
+<%= JSON.parse(({ 'instances' => @instances }).to_json).to_yaml %>
+
+# Nothing to configure here
+init_config:

Add recipe for windows_service integration (#387)

Fixes #386