-
Notifications
You must be signed in to change notification settings - Fork 262
/
integration.rb
82 lines (68 loc) · 3.06 KB
/
integration.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# Copyright:: 2011-Present, Datadog
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# Install/remove a Datadog integration
# This resource basically wraps the datadog-agent integration command to be able
# to install and remove integrations from a Chef recipe.
# The datadog_resource must be used on a system where the datadog-agent has
# already been setup.
# enable unified mode on specific Chef versions.
# See CHEF-33 Deprecation warning:
# https://docs.chef.io/deprecations_unified_mode/
unified_mode true if respond_to?(:unified_mode)
default_action :install
property :property_name, String, name_property: true
property :version, String, required: true
property :third_party, [true, false], required: false, default: false
action :install do
if Chef::Datadog.agent_major_version(node) == 5
Chef::Log.error('The datadog_integration resource is not available with Agent v5.')
return
end
Chef::Log.debug("Getting integration #{new_resource.property_name}")
execute 'integration install' do
# Space at the end of '--third-party ' is intentional, so that if --third-party is not specified, no additional space is added to the command line
command "\"#{agent_exe_filepath}\" integration install #{'--third-party ' if new_resource.third_party}#{new_resource.property_name}==#{new_resource.version}"
user 'dd-agent' unless platform_family?('windows')
not_if {
output = shell_out("#{agent_exe_filepath} integration show -q #{new_resource.property_name}").stdout
output.strip == new_resource.version
}
notifies :restart, 'service[datadog-agent]' if node['datadog']['agent_start']
end
end
action :remove do
if Chef::Datadog.agent_major_version(node) == 5
Chef::Log.error('The datadog_integration resource is not available with Agent v5.')
return
end
Chef::Log.debug("Removing integration #{new_resource.property_name}")
execute 'integration remove' do
command "\"#{agent_exe_filepath}\" integration remove #{new_resource.property_name}"
user 'dd-agent' unless platform_family?('windows')
not_if {
output = shell_out("#{agent_exe_filepath} integration show -q #{new_resource.property_name}").stdout
output.strip.empty?
}
notifies :restart, 'service[datadog-agent]' if node['datadog']['agent_start']
end
end
def agent_exe_filepath
if platform_family?('windows')
# The Windows Agent will always be setup in this path if the _install-windows.rb
# has been used to install it.
"C:\\Program\ Files\\Datadog\\Datadog\ Agent\\embedded\\agent.exe"
else
'/opt/datadog-agent/bin/agent/agent'
end
end