Skip to content

Commit

Permalink
Merge branch 'KierranM-sumologic_collector-resource'
Browse files Browse the repository at this point in the history
  • Loading branch information
duchatran committed Apr 20, 2016
2 parents c098bd0 + 579847e commit bf92902
Show file tree
Hide file tree
Showing 26 changed files with 507 additions and 118 deletions.
25 changes: 15 additions & 10 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
1 change: 1 addition & 0 deletions Berksfile
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
110 changes: 110 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
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",
Expand Down
172 changes: 172 additions & 0 deletions providers/default.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
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
Loading

0 comments on commit bf92902

Please sign in to comment.