Skip to content

Commit

Permalink
Merge pull request #149 from vkhatri/travis-148
Browse files Browse the repository at this point in the history
Release v2.2.0
  • Loading branch information
vkhatri authored Oct 12, 2018
2 parents e4402ff + 86331f1 commit b180a27
Show file tree
Hide file tree
Showing 16 changed files with 200 additions and 167 deletions.
21 changes: 6 additions & 15 deletions .kitchen.dokken.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,9 @@ platforms:
- RUN yum install -y net-tools initscripts

suites:
- name: chef12
driver:
chef_version: 12.22.5
verifier:
inspec_tests:
- test/smoke/v6
run_list:
- recipe[filebeat_test::defaultv6]

- name: chef13
driver:
chef_version: 13.9.4
chef_version: 13.11.3
verifier:
inspec_tests:
- test/smoke/v6
Expand All @@ -110,24 +101,24 @@ suites:

- name: chef14
driver:
chef_version: 14.2.0
chef_version: 14.5.33
verifier:
inspec_tests:
- test/smoke/v6
run_list:
- recipe[filebeat_test::defaultv6]

- name: chef13runit
- name: chef14runit
driver:
chef_version: 13.9.4
chef_version: 14.5.33
verifier:
inspec_tests:
- test/smoke/v6runit
run_list:
- recipe[filebeat_test::defaultv6runit]

- name: chef13-preview
- name: chef14preview
driver:
chef_version: 13.9.4
chef_version: 14.5.33
run_list:
- recipe[filebeat_test::defaultv6preview]
27 changes: 8 additions & 19 deletions .kitchen.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,20 +36,9 @@ platforms:
platform: windows

suites:
- name: chef12
driver:
require_chef_omnibus: 12.22.5
verifier:
inspec_tests:
- test/smoke/v6
excludes:
- windows-2012R2
run_list:
- recipe[filebeat_test::defaultv6]

- name: chef13
driver:
require_chef_omnibus: 13.9.4
require_chef_omnibus: 13.11.3
verifier:
inspec_tests:
- test/smoke/v6
Expand All @@ -60,7 +49,7 @@ suites:

- name: chef14
driver:
require_chef_omnibus: 14.2.0
require_chef_omnibus: 14.5.33
verifier:
inspec_tests:
- test/smoke/v6
Expand All @@ -69,9 +58,9 @@ suites:
run_list:
- recipe[filebeat_test::defaultv6]

- name: chef13win
- name: chef14win
driver:
require_chef_omnibus: 13.9.4
require_chef_omnibus: 14.5.33
verifier:
inspec_tests:
- test/smoke/v6windows
Expand All @@ -80,17 +69,17 @@ suites:
includes:
- windows-2012R2

- name: chef13runit
- name: chef14runit
driver:
require_chef_omnibus: 13.9.4
require_chef_omnibus: 14.5.33
excludes:
- windows-2012R2
run_list:
- recipe[filebeat::default]

- name: chef13preview
- name: chef14preview
driver:
chef_version: 13.9.4
require_chef_omnibus: 14.5.33
verifier:
inspec_tests:
- test/smoke/v6
Expand Down
2 changes: 0 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ env:
- INSTANCE=chef13-fedora26
- INSTANCE=chef13-ubuntu14
- INSTANCE=chef13-ubuntu16
- INSTANCE=chef13-debian8
- INSTANCE=chef13-debian9
- INSTANCE=chef13-amazon
- INSTANCE=chef13-amazon2

Expand Down
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,24 @@
filebeat CHANGELOG
==================

2.2.0
-----

- Luke Waite - Correct default file path for `filebeat_config` lwrp

- Piotr Kantyka - Updated logging.files path config only when empty

- Virender Khatri - Updated filebeat version to v6.4.2

- Virender Khatri - Updated Kitchen Test for recent Chef Version

- Virender Khatri - Removed v5 / Chef12 configuration references

- Virender Khatri - Rename helper method purge_prospectors_dir to purge_prospectors_config in favor of filebeat_service resource

- Virender Khatri - Wrapped helper methods into a module Filebeat::Helpers


2.1.0
-----

Expand Down
47 changes: 38 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ This is a [Chef] cookbook to manage [Filebeat].
## Most Recent Release

```ruby
cookbook 'filebeat', '~> 2.1.0'
cookbook 'filebeat', '~> 2.2.0'
```


## From Git

```ruby
cookbook 'filebeat', github: 'vkhatri/chef-filebeat', tag: 'v2.1.0'
cookbook 'filebeat', github: 'vkhatri/chef-filebeat', tag: 'v2.2.0'
```


Expand Down Expand Up @@ -80,6 +80,8 @@ Also works on Solaris zones given a physical Solaris 11.2 server. For that, use

- `filebeat_service` - filebeat service resource

- `filebeat_runit_service` - filebeat service resource using runit

- `filebeat_prospector` - filebeat prospector resource


Expand Down Expand Up @@ -146,12 +148,10 @@ end
- *filebeat_install_resource_name* (optional, String) - default `default`, filebeat_install/filebeat_install_preview resource name, set this attribute if LWRP resource name is other than `default`
- *service_name* (optional, String) - default `filebeat`, filebeat service name, must be common across resources
- *disable_service* (optional, Boolean) - default `false`, set to `true`, to disable filebeat service
- *notify_restart* (optional, Boolean) - default `true`, set to `false`, to ignore filebeat service restart notify
- *purge_prospectors_dir* (optional, Boolean) - default `false`, set to `true`, to purge prospectors
- *runit_filebeat_cmd_options* (optional, Boolean) - default `''`, set to `true`, runit filebeat service command line options
- *ignore_failure* (optional, Boolean) - default `false`, set to `true`, to ignore filebeat service failures
- *retries* (optional, Integer) - default `2`, filebeat service resource attribute
- *retry_delay* (optional, Integer) - default `0`, filebeat service resource attribute
- *service_ignore_failure* (optional, Boolean) - default `false`, set to `true`, to ignore filebeat service failures
- *service_retries* (optional, Integer) - default `2`, filebeat service resource attribute
- *service_retry_delay* (optional, Integer) - default `0`, filebeat service resource attribute


## LWRP filebeat_config
Expand Down Expand Up @@ -204,7 +204,7 @@ filebeat.config_dir: "/etc/filebeat/conf.d"
- *action* (optional) - default `:create`, options: :create, :delete
- *filebeat_install_resource_name* (optional, String) - default `default`, filebeat_install/filebeat_install_preview resource name, set this attribute if LWRP resource name is other than `default`
- *config* (Hash) - default `{}` filebeat configuration options
- *sensitive* (optional, Boolean) - default `false`, filebeat configuration file chef resource attribute
- *config_sensitive* (optional, Boolean) - default `false`, filebeat configuration file chef resource attribute
- *service_name* (optional, String) - default `filebeat`, filebeat service name, must be common across resources
- *conf_file* (optional, String, NilClass) - default `nil`, filebeat configuration file, this attribute is derived by helper method
- *disable_service* (optional, Boolean) - default `false`, set to `true`, to disable filebeat service
Expand Down Expand Up @@ -250,17 +250,46 @@ filebeat:
- *action* (optional) - default `:create`, options: :create, :delete
- *filebeat_install_resource_name* (optional, String) - default `default`, filebeat_install/filebeat_install_preview resource name, set this attribute if LWRP resource name is other than `default`
- *config* (Hash) - default `{}` filebeat configuration options
- *sensitive* (optional, Boolean) - default `false`, filebeat configuration file chef resource attribute
- *config_sensitive* (optional, Boolean) - default `false`, filebeat configuration file chef resource attribute
- *service_name* (optional, String) - default `filebeat`, filebeat service name, must be common across resources
- *disable_service* (optional, Boolean) - default `false`, set to `true`, to disable filebeat service
- *notify_restart* (optional, Boolean) - default `true`, set to `false`, to ignore filebeat service restart notify


## LWRP filebeat_runit_service

LWRP `filebeat_runit_service` configures `filebeat` service using `runit`.


**LWRP example**

```ruby
filebeat_runit_service 'default' do
[options ..]
end
```

**LWRP Options**

- *action* (optional) - default `:create`, options: :create, :delete
- *filebeat_install_resource_name* (optional, String) - default `default`, filebeat_install/filebeat_install_preview resource name, set this attribute if LWRP resource name is other than `default`
- *service_name* (optional, String) - default `filebeat`, filebeat service name, must be common across resources
- *disable_service* (optional, Boolean) - default `false`, set to `true`, to disable filebeat service
- *purge_prospectors_dir* (optional, Boolean) - default `false`, set to `true`, to purge prospectors
- *runit_filebeat_cmd_options* (optional, Boolean) - default `''`, set to `true`, runit filebeat service command line options
- *service_ignore_failure* (optional, Boolean) - default `false`, set to `true`, to ignore filebeat service failures


## How to Create Filebeat LWRP Resources via Node Attribute

Check out filebeat test cookbook [filebeat_test](test/cookbooks/filebeat_test).


## TODO

- Add other platforms support to install_preview resource


## Contributing

1. Fork the repository on Github
Expand Down
115 changes: 62 additions & 53 deletions libraries/helper.rb
Original file line number Diff line number Diff line change
@@ -1,68 +1,77 @@
require 'fileutils'

def purge_prospectors_dir(prospectors_dir)
valid_prospectors = []
module Filebeat
# Filebeat Helper Module
module Helpers
def purge_prospectors_config(prospectors_dir)
valid_prospectors = []

# collect lwrp filebeat_prospector prospectors
run_context.resource_collection.select { |resource| valid_prospectors.push("lwrp-prospector-#{resource.name}.yml") if resource.resource_name == :filebeat_prospector }
# collect lwrp filebeat_prospector prospectors
run_context.resource_collection.select { |resource| valid_prospectors.push("lwrp-prospector-#{resource.name}.yml") if resource.resource_name == :filebeat_prospector }

# prospectors yml files to clean up
extra_prospectors = Dir.entries(prospectors_dir).reject { |a| valid_prospectors.include?(a) || a.match(/^custom-prospector-.*yml$/) }.sort
extra_prospectors -= ['.', '..']
# prospectors yml files to clean up
extra_prospectors = Dir.entries(prospectors_dir).reject { |a| valid_prospectors.include?(a) || a.match(/^custom-prospector-.*yml$/) }.sort
extra_prospectors -= ['.', '..']

extra_prospectors.each do |prospector|
prospector_file = ::File.join(prospectors_dir, prospector)
FileUtils.rm prospector_file
Chef::Log.warn("deleted filebeat prospector configuration file #{prospector_file}")
end
extra_prospectors.each do |prospector|
prospector_file = ::File.join(prospectors_dir, prospector)
FileUtils.rm prospector_file
Chef::Log.warn("deleted filebeat prospector configuration file #{prospector_file}")
end

Chef::Log.info("\n could not find any filebeat prospector configuration file to purge") if extra_prospectors.empty?
end
Chef::Log.info("\n could not find any filebeat prospector configuration file to purge") if extra_prospectors.empty?
end

def machine_arch
node['kernel']['machine'] =~ /x86_64/ ? 'x86_64' : 'x86'
end
def machine_arch
node['kernel']['machine'] =~ /x86_64/ ? 'x86_64' : 'x86'
end

def win_package_url(version, package_url)
package_url = if version < '5.0'
package_url == 'auto' ? "https://download.elastic.co/beats/filebeat/filebeat-#{version}-windows.zip" : package_url
else
package_url == 'auto' ? "https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-#{version}-windows-#{machine_arch}.zip" : package_url
end
package_url
end
def win_package_url(version, package_url)
package_url = if version < '5.0'
package_url == 'auto' ? "https://download.elastic.co/beats/filebeat/filebeat-#{version}-windows.zip" : package_url
else
package_url == 'auto' ? "https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-#{version}-windows-#{machine_arch}.zip" : package_url
end
package_url
end

def default_config_dir(version, windows_base_dir)
conf_dir = if node['platform'] == 'windows'
if version < '5.0'
"#{windows_base_dir}/filebeat-#{version}-windows"
else
"#{windows_base_dir}/filebeat-#{version}-windows-#{machine_arch}"
end
else
'/etc/filebeat'
end
conf_dir
end
def default_config_dir(version, windows_base_dir)
conf_dir = if node['platform'] == 'windows'
if version < '5.0'
"#{windows_base_dir}/filebeat-#{version}-windows"
else
"#{windows_base_dir}/filebeat-#{version}-windows-#{machine_arch}"
end
else
'/etc/filebeat'
end
conf_dir
end

def default_conf_file(conf_dir)
node['platform'] == 'windows' ? "#{conf_dir}/filebeat.yml" : ::File.join(conf_dir, 'filebeat.yml')
end
def default_conf_file(conf_dir)
node['platform'] == 'windows' ? "#{conf_dir}/filebeat.yml" : ::File.join(conf_dir, 'filebeat.yml')
end

def default_prospectors_dir(conf_dir)
node['platform'] == 'windows' ? "#{conf_dir}/conf.d" : ::File.join(conf_dir, 'conf.d')
end
def default_prospectors_dir(conf_dir)
node['platform'] == 'windows' ? "#{conf_dir}/conf.d" : ::File.join(conf_dir, 'conf.d')
end

def check_beat_resource(run_context, resource_type, resource_name = 'default')
run_context.resource_collection.find(resource_type => resource_name)
rescue StandardError
nil
end
def check_beat_resource(run_context, resource_type, resource_name = 'default')
run_context.resource_collection.find(resource_type => resource_name)
rescue StandardError
nil
end

def find_beat_resource(run_context, resource_type, resource_name = 'default')
run_context.resource_collection.find(resource_type => resource_name)
end
def find_beat_resource(run_context, resource_type, resource_name = 'default')
run_context.resource_collection.find(resource_type => resource_name)
end

def default_log_dir(conf_dir)
node['platform'] == 'windows' ? "#{conf_dir}/logs" : '/var/log/filebeat'
def default_log_dir(conf_dir)
node['platform'] == 'windows' ? "#{conf_dir}/logs" : '/var/log/filebeat'
end
end
end

# ::Chef::Recipe.send(:include, Filebeat::Helpers)
# ::Chef::Resource.send(:include, Filebeat::Helpers)
# ::Chef::Provider.send(:include, Filebeat::Helpers)
2 changes: 1 addition & 1 deletion metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
license 'Apache-2.0'
description 'Installs/Configures Elastic Filebeat'
long_description IO.read(File.join(File.dirname(__FILE__), 'README.md'))
version '2.1.0'
version '2.2.0'
source_url 'https://github.com/vkhatri/chef-filebeat' if respond_to?(:source_url)
issues_url 'https://github.com/vkhatri/chef-filebeat/issues' if respond_to?(:issues_url)
chef_version '>= 12.14' if respond_to?(:chef_version)
Expand Down
Loading

0 comments on commit b180a27

Please sign in to comment.