Commit bf92902d authored by Duc Ha's avatar Duc Ha
Browse files

Merge branch 'KierranM-sumologic_collector-resource'

parents c098bd01 579847e8
......@@ -50,25 +50,30 @@ suites:
- centos-7.1
- debian-8.1
- ubuntu-14.04
- name: installer-resource
- name: default-resource
run_list:
- recipe[installer-resource]
- recipe[default-resource]
attributes:
SUMO_ACCESS_ID: <%= ENV['SUMO_ACCESS_ID'] %>
SUMO_ACCESS_KEY: <%= ENV['SUMO_ACCESS_KEY'] %>
excludes:
- windows-2012r2
- name: installer-resource-windows
- name: default-resource-install
run_list:
- recipe[default-resource::install]
- name: default-resource-configure
run_list:
- recipe[default-resource::configure]
attributes:
SUMO_ACCESS_ID: <%= ENV['SUMO_ACCESS_ID'] %>
SUMO_ACCESS_KEY: <%= ENV['SUMO_ACCESS_KEY'] %>
- name: default-resource-remove
run_list:
- recipe[default-resource::remove]
- name: installer-resource
run_list:
- recipe[installer-resource]
attributes:
SUMO_ACCESS_ID: <%= ENV['SUMO_ACCESS_ID'] %>
SUMO_ACCESS_KEY: <%= ENV['SUMO_ACCESS_KEY'] %>
excludes:
- centos-6.7
- centos-7.1
- debian-8.1
- ubuntu-14.04
- name: source-resource
run_list:
- recipe[source-resource]
......
......@@ -5,5 +5,6 @@ metadata
group :integration do
cookbook 'data-bag-faker', path: 'test/fixtures/cookbooks/data-bag-faker'
cookbook 'installer-resource', path: 'test/fixtures/cookbooks/installer-resource'
cookbook 'default-resource', path: 'test/fixtures/cookbooks/default-resource'
cookbook 'source-resource', path: 'test/fixtures/cookbooks/source-resource'
end
......@@ -2,6 +2,10 @@
This file is used to list changes made in each version of sumologic-collector.
## 1.2.12
* Merged PR#71: Add a new sumologic_collector resource.
## 1.2.11
* Fixed issue 68 with PR#67
......
......@@ -85,9 +85,119 @@ Attributes
Resource/Provider
-----------------
sumologic_collector
---------
Provides actions for installing and managing a SumoLogic Collector
### Actions
`default` = `:install_and_configure`
#### :install
Installs an unconfigured and unregistered SumoLogic Collector. Use `:configure` to configure it later
```ruby
sumologic_collector 'C:\sumo' do
action :install
end
```
#### :install_and_configure
Installs and configures a SumoLogic Collector. This is the default action
```ruby
sumologic_collector 'C:\sumo' do
collector_name 'fileserver'
sumo_access_id 'MYACCESSID'
sumo_access_key 'MYACCESSKEY'
proxy_host 'proxy.mydomain.com'
proxy_port '8080'
end
```
#### :configure
Configures a pre-installed but unconfigured (and unregistered) SumoLogic Collector
*Note: The recommended flow to use this is to have the collector installed without
configuration or registration by using the `:install` action*
```ruby
sumologic_collector 'C:\sumo' do
collector_name 'fileserver'
sumo_access_id 'MYACCESSID'
sumo_access_key 'MYACCESSKEY'
proxy_host 'proxy.mydomain.com'
proxy_port '8080'
action :configure
end
```
#### :remove
Uninstalls a SumoLogic collector using the provided uninstaller
```ruby
sumologic_collector 'C:\sumo' do
action :remove
end
```
#### :start
Starts the SumoLogic Collector
```ruby
sumologic_collector 'C:\sumo' do
action :start
end
```
#### :stop
Stops the SumoLogic Collector
```ruby
sumologic_collector 'C:\sumo' do
action :stop
end
```
#### :restart
Restarts the SumoLogic Collector
```ruby
sumologic_collector 'C:\sumo' do
action :restart
end
```
### Attribute Parameters
See the [Sumo Logic documentation](https://help.sumologic.com/Send_Data/Installed_Collectors/stu_user.properties)
for more information about these attributes.
| Attribute | Type | Description | Default | Required | Used Actions |
| --------- | ---- | ----------- | ------- | -------- | ------------ |
| `dir` | `String` | Directory where collector will be installed (`name` attribute) | none | `true` | all |
| `source` | `String` | URL to download collector installer from | none (uses the latest installer from SumoLogic) | `false` | `:install`, `:install_and_configure` |
| `collector_name` | `String` | Name of this Collector | `nil` | `false` | `:install_and_configure`, `:configure` |
| `collector_url` | `String` | URL used to register Collector for data collection API | `nil` | `false` | `:install_and_configure`, `:configure` |
| `sumo_email` | `String` | eMail address used when logging in with Email and Password | `nil` | `false` | `:install_and_configure`, `:configure` |
| `sumo_password` | `String` | Password used when logging in with Email and Password | `nil` | `false` | `:install_and_configure`, `:configure` |
| `sumo_token_and_url` | `String` | Encoded Setup Wizard token | `nil` | `false` | `:install_and_configure` |
| `sumo_access_id` | `String` | Access ID used when logging in with Access ID and Key | `nil` | `false` | `:install_and_configure`, `:configure` |
| `sumo_access_key` | `String` | Access Key used when logging in with Access ID and Key | `nil` | `false` | `:install_and_configure`, `:configure` |
| `proxy_host` | `String` | Sets proxy host when a proxy server is used | `nil` | `false` | `:install_and_configure`, `:configure` |
| `proxy_port` | `String`, `Fixnum` | Sets proxy port when a proxy server is used | `nil` | `false` | `:install_and_configure`, `:configure` |
| `proxy_user` | `String` | Sets proxy user when a proxy server is used with authentication | `nil` | `false` | `:install_and_configure`, `:configure` |
| `proxy_password` | `String` | Sets proxy password when a proxy server is used with authentication | `nil` | `false` | `:install_and_configure`, `:configure` |
| `proxy_ntlmdomain` | `String` | Sets proxy NTLM domain when a proxy server is used with NTLM authentication | `nil` | `false` | `:install_and_configure`, `:configure` |
| `sources` | `String` | Sets the JSON file describing sources to configure on registration | `nil` | `false` | `:install_and_configure`, `:configure` |
| `sync_sources` | `String` | Sets the JSON file describing sources to configure on registration, which will be continuously monitored and synchronized with the Collector's configuration | `nil` | `false` | `:install_and_configure`, `:configure` |
| `ephemeral` | `Boolean` | When `true`, the Collector will be deleted after goes offline for a certain period of time | `false` | `false` | `:install_and_configure`, `:configure` |
| `clobber` | `Boolean` | When `true`, if there is any existing Collector with the same name, that Collector will be deleted | `false` | `false` | `:install_and_configure`, `:configure` |
| `disable_script_source` | `Boolean` | If your organization's internal policies restrict the use of scripts, you can disable the creation of script-based Script Sources. When this parameter is passed, this option is removed from the Sumo Logic Web Application, and Script Source cannot be configured | `false` | `false` | `:install_and_configure`, `:configure` |
| `runas_username` | `String` | Which user the daemon will run as | `nil` | `false` | `:install_and_configure`, `:install` |
| `winrunas_password` | `String` | On Windows, the password for the user the service will run as | `nil` | `false` | `:install_and_configure`, `:install` |
| `skip_registration` | `Boolean` | When `true` the collector will not register upon installation | `false` | `nil` | `:install_and_configure` |
sumologic_collector_installer
---------
*Note: `sumologic_collector_installer` has been deprecated, please use `sumologic_collector` with the `:install_and_configure` action (the default)*
Allows for additional customisation of the Sumo Logic Collector installer
### Actions
......
......@@ -6,7 +6,7 @@ source_url 'https://github.com/SumoLogic/sumologic-collector-chef-cookbook'
license 'Apache v2.0'
description 'Installs/Configures sumologic-collector'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '1.2.11'
version '1.2.12'
attribute 'sumologic/credentials/bag_name',
display_name: "Credentials bag name",
type: "string",
......
use_inline_resources
def whyrun_supported?
true
end
def load_current_resource
@current_resource = Chef::Resource::SumologicCollector.new(new_resource.dir)
@current_resource.installed(installed?)
end
action :install do
if @current_resource.installed
Chef::Log.debug "Sumo Logic Collector already installed to #{new_resource.dir}"
else
download_installer
# set up some arguments to allow for unconfigured installation
new_resource.skip_registration(true)
new_resource.sumo_access_id('00000000000')
new_resource.sumo_access_key('0000000000000000000000000')
installer_cmd = [installer_bin, installer_opts].join(' ').strip
run_installer installer_cmd
end
end
action :install_and_configure do
if @current_resource.installed
Chef::Log.debug "Sumo Logic Collector already installed to #{new_resource.dir}"
else
download_installer
installer_cmd = [installer_bin, installer_opts].join(' ').strip
run_installer installer_cmd
end
end
action :configure do
if !@current_resource.installed
Chef::Log.info "Collector Directory is not found at #{new_resource.dir}. Will not do anything."
else
template "#{new_resource.dir}/config/user.properties" do
source 'user.properties.erb'
cookbook 'sumologic-collector'
variables resource: new_resource
sensitive true
end
execute 'Restart SumoLogic Collector' do
command "#{collector} restart"
cwd new_resource.dir
action :nothing
subscribes :run, "template[#{new_resource.dir}/config/user.properties]" unless new_resource.skip_restart
end
end
end
action :remove do
if !@current_resource.installed
Chef::Log.info "Collector Directory is not found at #{new_resource.dir}. Will not do anything."
else
uninstall_cmd = node['platform_family'] == 'windows' ? 'uninstall.exe -console' : './uninstall'
execute 'Remove Sumologic Collector' do
command "#{uninstall_cmd} -q"
cwd new_resource.dir
end
end
end
action :start do
if !@current_resource.installed
Chef::Log.info "Collector Directory is not found at #{new_resource.dir}. Will not do anything."
else
execute 'Stop SumoCollector' do
command "#{collector} start"
cwd new_resource.dir
end
end
end
action :stop do
if !@current_resource.installed
Chef::Log.info "Collector Directory is not found at #{new_resource.dir}. Will not do anything."
else
execute 'Stop SumoCollector' do
command "#{collector} stop"
cwd new_resource.dir
end
end
end
action :restart do
if !@current_resource.installed
Chef::Log.info "Collector Directory is not found at #{new_resource.dir}. Will not do anything."
else
execute 'Stop SumoCollector' do
command "#{collector} restart"
cwd new_resource.dir
end
end
end
def collector
node['platform_family'] == 'windows' ? 'collector.exe' : './collector'
end
private
def installed?
case node['platform_family']
when 'windows'
::Win32::Service.exists? 'sumo-collector'
else
::File.exist? '/etc/init.d/collector'
end
end
def installer_bin
node['platform_family'] == 'windows' ? 'sumocollector.exe' : 'sumocollector'
end
def installer_source
case node['platform_family']
when 'windows'
node['kernel']['machine'] =~ /^x86_64$/ ? 'https://collectors.sumologic.com/rest/download/win64' : 'https://collectors.sumologic.com/rest/download/windows'
else
url = 'https://collectors.sumologic.com/rest/download/linux'
"#{url}/#{node['kernel']['machine'] =~ /^i[36']86$/ ? '32' : '64'}"
end
end
def download_installer
if new_resource.source.nil?
Chef::Log.info "No installer source given, using #{installer_source} instead"
new_resource.source(installer_source)
end
remote_file "#{Chef::Config[:file_cache_path]}/#{installer_bin}" do
source new_resource.source
mode '0755' unless node['platform_family'] == 'windows'
end
end
def run_installer(installer_cmd)
execute 'Install Sumo Collector' do
command "#{Chef::Config[:file_cache_path]}/#{installer_cmd}"
timeout 3600
end
end
def installer_opts
args = []
args << '-console'
args << '-q'
args << "-dir #{new_resource.dir}"
args << "-Vcollector.name=#{new_resource.collector_name}" unless new_resource.collector_name.nil?
args << "-Vcollector.url=#{new_resource.collector_url}" unless new_resource.collector_url.nil?
args << "-Vsumo.email=#{new_resource.sumo_email}" unless new_resource.sumo_email.nil?
args << "-Vsumo.password=#{new_resource.sumo_password}" unless new_resource.sumo_password.nil?
args << "-Vsumo.token_and_url=#{new_resource.sumo_token_and_url}" unless new_resource.sumo_token_and_url.nil?
args << "-Vsumo.accessid=#{new_resource.sumo_access_id}" unless new_resource.sumo_access_id.nil?
args << "-Vsumo.accesskey=#{new_resource.sumo_access_key}" unless new_resource.sumo_access_key.nil?
args << "-Vproxy.host=#{new_resource.proxy_host}" unless new_resource.proxy_host.nil?
args << "-Vproxy.port=#{new_resource.proxy_port}" unless new_resource.proxy_port.nil?
args << "-Vproxy.user=#{new_resource.proxy_user}" unless new_resource.proxy_user.nil?
args << "-Vproxy.password=#{new_resource.proxy_password}" unless new_resource.proxy_password.nil?
args << "-Vproxy.ntlmdomain=#{new_resource.proxy_ntlmdomain}" unless new_resource.proxy_ntlmdomain.nil?
args << "-Vsources=#{new_resource.sources}" unless new_resource.sources.nil?
args << "-VsyncSources=#{new_resource.sync_sources}" unless new_resource.sync_sources.nil?
args << "-Vephemeral=true" if new_resource.ephemeral
args << "-Vclobber=true" if new_resource.clobber
args << "-VrunAs.username=#{new_resource.runas_username}" unless new_resource.runas_username.nil?
args << "-VwinRunAs.password=#{new_resource.winrunas_password}" unless new_resource.winrunas_password.nil?
args << "-VskipRegistration=true" if new_resource.skip_registration
args
end
......@@ -6,64 +6,30 @@ end
def load_current_resource
@current_resource = Chef::Resource::SumologicCollectorInstaller.new(new_resource.dir)
@current_resource.installed(installed?)
end
action :install do
if @current_resource.installed
Chef::Log.debug "Sumo Logic Collector already installed to #{new_resource.dir}"
else
remote_file "#{Chef::Config[:file_cache_path]}/#{installer_bin}" do
source new_resource.source
mode '0755' unless node['platform_family'] == 'windows'
end
installer_cmd = [installer_bin, installer_opts].join(' ').strip
execute 'Install Sumo Collector' do
command "#{Chef::Config[:file_cache_path]}/#{installer_cmd}"
timeout 3600
end
# just pass on to the new sumo_collector resource
sumologic_collector new_resource.dir do
source new_resource.source unless new_resource.source.nil?
collector_name new_resource.collector_name unless new_resource.collector_name.nil?
collector_url new_resource.collector_url unless new_resource.collector_url.nil?
sumo_email new_resource.sumo_email unless new_resource.sumo_email.nil?
sumo_password new_resource.sumo_password unless new_resource.sumo_password.nil?
sumo_token_and_url new_resource.sumo_token_and_url unless new_resource.sumo_token_and_url.nil?
sumo_access_id new_resource.sumo_access_id unless new_resource.sumo_access_id.nil?
sumo_access_key new_resource.sumo_access_key unless new_resource.sumo_access_key.nil?
proxy_host new_resource.proxy_host unless new_resource.proxy_host.nil?
proxy_port new_resource.proxy_port unless new_resource.proxy_port.nil?
proxy_user new_resource.proxy_user unless new_resource.proxy_user.nil?
proxy_password new_resource.proxy_password unless new_resource.proxy_password.nil?
proxy_ntlmdomain new_resource.proxy_ntlmdomain unless new_resource.proxy_ntlmdomain.nil?
sources new_resource.sources unless new_resource.sources.nil?
sync_sources new_resource.sync_sources unless new_resource.sync_sources.nil?
ephemeral new_resource.ephemeral unless new_resource.ephemeral.nil?
clobber new_resource.clobber unless new_resource.clobber.nil?
runas_username new_resource.runas_username unless new_resource.runas_username.nil?
winrunas_password new_resource.winrunas_password unless new_resource.winrunas_password.nil?
skip_registration new_resource.skip_registration unless new_resource.skip_registration.nil?
end
end
private
def installed?
# The install dir may be created even during a failed installation, so test
# for a subdirectory that will be present on all platforms and is less
# likely to exist unless installation was successful.
::File.exist?("#{new_resource.dir}/config")
end
def installer_bin
node['platform_family'] == 'windows' ? 'sumocollector.exe' : 'sumocollector'
end
def installer_opts
args = []
args << '-console'
args << '-q'
args << "-dir #{new_resource.dir}"
args << "-Vcollector.name=#{new_resource.collector_name}" unless new_resource.collector_name.nil?
args << "-Vcollector.url=#{new_resource.collector_url}" unless new_resource.collector_url.nil?
args << "-Vsumo.email=#{new_resource.sumo_email}" unless new_resource.sumo_email.nil?
args << "-Vsumo.password=#{new_resource.sumo_password}" unless new_resource.sumo_password.nil?
args << "-Vsumo.token_and_url=#{new_resource.sumo_token_and_url}" unless new_resource.sumo_token_and_url.nil?
args << "-Vsumo.accessid=#{new_resource.sumo_access_id}" unless new_resource.sumo_access_id.nil?
args << "-Vsumo.accesskey=#{new_resource.sumo_access_key}" unless new_resource.sumo_access_key.nil?
args << "-Vproxy.host=#{new_resource.proxy_host}" unless new_resource.proxy_host.nil?
args << "-Vproxy.port=#{new_resource.proxy_port}" unless new_resource.proxy_port.nil?
args << "-Vproxy.user=#{new_resource.proxy_user}" unless new_resource.proxy_user.nil?
args << "-Vproxy.password=#{new_resource.proxy_password}" unless new_resource.proxy_password.nil?
args << "-Vproxy.ntlmdomain=#{new_resource.proxy_ntlmdomain}" unless new_resource.proxy_ntlmdomain.nil?
args << "-Vsources=#{new_resource.sources}" unless new_resource.sources.nil?
args << "-VsyncSources=#{new_resource.sync_sources}" unless new_resource.sync_sources.nil?
args << "-Vephemeral=true" if new_resource.ephemeral
args << "-Vclobber=true" if new_resource.clobber
args << "-VrunAs.username=#{new_resource.runas_username}" unless new_resource.runas_username.nil?
args << "-VwinRunAs.password=#{new_resource.winrunas_password}" unless new_resource.winrunas_password.nil?
args << "-VskipRegistration=true" if new_resource.skip_registration
args
end
# Reference:
# https://service.sumologic.com/help/Default.htm#Using_Quiet_Mode_to_Install_a_Collector.htm
default_action :install_and_configure
actions :install, :install_and_configure, :configure, :remove, :start, :stop, :restart
# Installation attributes
attribute :dir, kind_of: String, name_attribute: true
attribute :source, kind_of: String
attribute :runas_username, kind_of: String, default: nil
attribute :winrunas_password, kind_of: String, default: nil
attribute :skip_registration, kind_of: [TrueClass, FalseClass], default: false
# Configuration attributes
attribute :collector_name, kind_of: String, default: nil
attribute :collector_url, kind_of: String, default: nil
attribute :sumo_email, kind_of: String, default: nil
attribute :sumo_password, kind_of: String, default: nil
attribute :sumo_token_and_url, kind_of: String, default: nil
attribute :sumo_access_id, kind_of: String, default: nil
attribute :sumo_access_key, kind_of: String, default: nil
attribute :proxy_host, kind_of: String, default: nil
attribute :proxy_port, kind_of: [String, Integer], default: nil
attribute :proxy_user, kind_of: String, default: nil
attribute :proxy_password, kind_of: String, default: nil
attribute :proxy_ntlmdomain, kind_of: String, default: nil
attribute :sources, kind_of: String, default: nil
attribute :sync_sources, kind_of: String, default: nil
attribute :ephemeral, kind_of: [TrueClass, FalseClass], default: false
attribute :clobber, kind_of: [TrueClass, FalseClass], default: false
attribute :disable_script_source, kind_of: [TrueClass, FalseClass], default: false
# Misc
attribute :installed, kind_of: [TrueClass, FalseClass], default: false
attribute :skip_restart, kind_of: [TrueClass, FalseClass], default: false
......@@ -6,7 +6,7 @@ default_action :install
actions :install
attribute :dir, kind_of: String, name_attribute: true
attribute :source, kind_of: String, required: true
attribute :source, kind_of: String
attribute :collector_name, kind_of: String, default: nil
attribute :collector_url, kind_of: String, default: nil
attribute :sumo_email, kind_of: String, default: nil
......@@ -26,4 +26,3 @@ attribute :clobber, kind_of: [TrueClass, FalseClass], default: false
attribute :runas_username, kind_of: String, default: nil
attribute :winrunas_password, kind_of: String, default: nil
attribute :skip_registration, kind_of: [TrueClass, FalseClass], default: false
attribute :installed, kind_of: [TrueClass, FalseClass], default: false
###########################################################
# Generated by Chef #
# on #
# <%= Time.now.to_s %> #
###########################################################
# Installer mode true to fool SumoLogic
installerMode=true
# Authentication
<% if not @resource.sumo_access_id.nil? %>
accessid=<%= @resource.sumo_access_id %>
accesskey=<%= @resource.sumo_access_key %>
<% elsif not @resource.sumo_email.nil? %>
email=<%= @resource.sumo_email %>
password=<%= @resource.sumo_password %>
<% end %>
<%= "url=#{@resource.collector_url}" unless @resource.collector_url.nil? %>
<% unless @resource.proxy_host.nil? %>
# Proxy Settings
proxyHost=<%= @resource.proxy_host %>
proxyPort=<%= @resource.proxy_port %>
<% unless @resource.proxy_user.nil? %>
proxyUser=<%= @resource.proxy_user %>
proxyPassword=<%= @resource.proxy_password %>
<% end %>
<%= "proxyNtlmDomain=#{@resource.proxy_ntlmdomain}" unless @resource.proxy_ntlmdomain.nil? %>
<% end %>
# Other Settings
name=<%= @resource.collector_name %>
<%= "sources=#{@resource.sources}" unless @resource.sources.nil? %>
<%= "syncSources=#{@resource.sync_sources}" unless @resource.sync_sources.nil? %>
<%= "ephemeral=#{@resource.ephemeral}" unless @resource.ephemeral.nil? %>
<%= "clobber=#{@resource.clobber}" unless @resource.clobber.nil? %>
<%= "disableScriptSource=#{@disable_script_source}" unless @resource.disable_script_source.nil? %>
# Deafult Resource cookbook
A cookbook to test the `sumologic_collector` resource.
name 'default-resource'
version '1.0.0'
depends 'sumologic-collector'
sumo_dir = node['platform_family'] == 'windows' ? 'c:\sumo' : '/opt/SumoCollector'
# install a blank collector
sumologic_collector sumo_dir do
action :install
end
sumologic_collector sumo_dir do
collector_name 'test-instance'
sumo_access_id node['SUMO_ACCESS_ID']
sumo_access_key node['SUMO_ACCESS_KEY']
proxy_host 'proxy.test.com'
proxy_port 8080
ephemeral true
skip_restart true
action :configure
end
sumo_dir = node['platform_family'] == 'windows' ? 'c:\sumo' : '/opt/SumoCollector'
sumologic_collector sumo_dir do
sumo_access_id node['SUMO_ACCESS_ID']
sumo_access_key node['SUMO_ACCESS_KEY']
skip_registration true
end
sumo_dir = node['platform_family'] == 'windows' ? 'c:\sumo' : '/opt/SumoCollector'
sumologic_collector sumo_dir do
action :install
end
sumo_dir = node['platform_family'] == 'windows' ? 'c:\sumo' : '/opt/SumoCollector'
# install a blank collector
sumologic_collector sumo_dir do
action :install
end
sumologic_collector sumo_dir do
action :remove
end
case node['platform_family']
when 'windows'
sumo_dir = node['platform_family'] == 'windows' ? 'c:\sumo' : '/opt/SumoCollector'
sumologic_collector_installer 'c:\sumo' do
source 'https://collectors.sumologic.com/rest/download/win64'
sumo_access_id node['SUMO_ACCESS_ID']
sumo_access_key node['SUMO_ACCESS_KEY']
skip_registration true
end
else
sumologic_collector_installer '/opt/SumoCollector' do
source 'https://collectors.sumologic.com/rest/download/linux/64'
sumo_access_id node['SUMO_ACCESS_ID']
sumo_access_key node['SUMO_ACCESS_KEY']