Skip to content

Commit

Permalink
#13, major changes to support repository package install
Browse files Browse the repository at this point in the history
  • Loading branch information
vkhatri committed Nov 28, 2015
1 parent e44cd95 commit c4971f5
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 94 deletions.
43 changes: 23 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,22 +41,27 @@ This cookbook was tested on Windows, Amazon & Ubuntu Linux and expected to work

- windows
- powershell
- apt
- yum


## Recipes

- `filebeat::default` - default recipe (use it for run_list)

- `filebeat::install` - install filebeat
- `filebeat::install_windows` - install filebeat for windows platform

- `filebeat::install_package` - install filebeat package for linux platform

- `filebeat::config` - configure filebeat


## Core Attributes


* `default['filebeat']['version']` (default: `1.0.0-rc2`): filebeat version
* `default['filebeat']['version']` (default: `1.0.0`): filebeat version

* `default['filebeat']['package_url']` (default: `auto`): package url
* `default['filebeat']['package_url']` (default: `auto`): package url for windows installation

* `default['filebeat']['conf_dir']` (default: `/etc/filebeat`): filebeat yaml configuration file directory

Expand All @@ -79,40 +84,38 @@ This cookbook was tested on Windows, Amazon & Ubuntu Linux and expected to work
* `default['filebeat']['config']['filebeat']['config_dir']` (default: `node['filebeat']['prospectors_dir']`): filebeat prospectors configuration files folder


* `default['filebeat']['config']['output']['elasticsearch']['enabled']` (default: `true`): enable elasticsearch output
* `default['filebeat']['config']['output']` (default: `{}`): configure elasticsearch. logstash, file etc. output

* `default['filebeat']['config']['output']['elasticsearch']['hosts']` (default: `[]`): elasticsearch hosts

* `default['filebeat']['config']['output']['elasticsearch']['save_topology']` (default: `false`):
For more attribute info, visit below links:

https://github.com/elastic/filebeat/blob/master/etc/filebeat.yml

* `default['filebeat']['config']['output']['logstash']['enabled']` (default: `true`): enable logstash output

* `default['filebeat']['config']['output']['logstash']['hosts']` (default: `[]`): logstash hosts
# Elasticsearch YUM/APT Repository Attributes

* `default['filebeat']['config']['output']['logstash']['loadbalance']` (default: `true`): set true to load balance between logstash hosts
* `default['filebeat']['yum']['description']` (default: ``): beats yum reporitory attribute

* `default['filebeat']['config']['output']['logstash']['index']` (default: `filebeat`): logstash index name
* `default['filebeat']['yum']['gpgcheck']` (default: `true`): beats yum reporitory attribute

* `default['filebeat']['config']['output']['logstash']['tls']['enabled']` (default: `false`):
* `default['filebeat']['yum']['enabled']` (default: `true`): beats yum reporitory attribute

* `default['filebeat']['config']['output']['logstash']['save_topology']` (default: `false`):
* `default['filebeat']['yum']['baseurl']` (default: `https://packages.elastic.co/beats/yum/el/$basearch`): beatsyum reporitory attribute

* `default['filebeat']['yum']['gpgkey']` (default: `https://packages.elasticsearch.org/GPG-KEY-elasticsearch`): beats yum reporitory attribute

* `default['filebeat']['config']['output']['file']['enabled']` (default: `false`):
* `default['filebeat']['yum']['action']` (default: `:create`): beats yum reporitory attribute

* `default['filebeat']['config']['output']['file']['path']` (default: `/tmp/filebeat`):

* `default['filebeat']['config']['output']['file']['filename']` (default: `filebeat`):
* `default['filebeat']['apt']['description']` (default: `calculated`): beats apt reporitory attribute

* `default['filebeat']['config']['output']['file']['rotate_every_kb']` (default: `10240`):
* `default['filebeat']['apt']['components']` (default: `['stable', 'main']`): beats apt reporitory attribute

* `default['filebeat']['config']['output']['file']['number_of_files']` (default: `7`):
* `default['filebeat']['apt']['uri']` (default: `https://packages.elastic.co/beats/apt`): beats apt reporitory attribute

* `default['filebeat']['apt']['key']` (default: `http://packages.elasticsearch.org/GPG-KEY-elasticsearch`): beats apt reporitory attribute

For more attribute info, visit below links:
* `default['filebeat']['apt']['action']` (default: `:add`): filebeat apt reporitory attribute

https://github.com/elastic/filebeat/blob/master/etc/filebeat.yml


## How to Add Filebeat Prospectors via Node Attribute
Expand Down
15 changes: 14 additions & 1 deletion attributes/default.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
default['filebeat']['version'] = '1.0.0-rc2'
default['filebeat']['version'] = '1.0.0'
default['filebeat']['disable_service'] = false
default['filebeat']['package_url'] = 'auto'

Expand All @@ -10,3 +10,16 @@
default['filebeat']['windows'] = {
'base_dir' => 'C:/opt/filebeat/'
}

default['filebeat']['yum']['baseurl'] = 'https://packages.elastic.co/beats/yum/el/$basearch'
default['filebeat']['yum']['description'] = 'Elastic Beats Repository'
default['filebeat']['yum']['gpgcheck'] = true
default['filebeat']['yum']['enabled'] = true
default['filebeat']['yum']['gpgkey'] = 'https://packages.elasticsearch.org/GPG-KEY-elasticsearch'
default['filebeat']['yum']['action'] = :create

default['filebeat']['apt']['uri'] = 'https://packages.elastic.co/beats/apt'
default['filebeat']['apt']['description'] = 'Elastic Beats Repository'
default['filebeat']['apt']['components'] = %w(stable main)
default['filebeat']['apt']['action'] = :add
default['filebeat']['apt']['key'] = 'https://packages.elasticsearch.org/GPG-KEY-elasticsearch'
2 changes: 2 additions & 0 deletions metadata.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

depends 'windows'
depends 'powershell'
depends 'apt'
depends 'yum'

%w(windows ubuntu centos amazon redhat fedora).each do |os|
supports os
Expand Down
9 changes: 8 additions & 1 deletion recipes/default.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,12 @@
# limitations under the License.
#

include_recipe 'filebeat::install'
# install filebeat
if node['platform'] == 'windows'
include_recipe 'filebeat::install_windows'
else
include_recipe 'filebeat::install_package'
end

# configure filebeat
include_recipe 'filebeat::config'
62 changes: 0 additions & 62 deletions recipes/install.rb

This file was deleted.

43 changes: 43 additions & 0 deletions recipes/install_package.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#
# Cookbook Name:: filebeat
# Recipe:: package
#
# Copyright 2015, Virender Khatri
#
# 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.
#

case node['platform_family']
when 'debian'
# apt repository configuration
apt_repository 'beats' do
uri node['filebeat']['apt']['uri']
components node['filebeat']['apt']['components']
key node['filebeat']['apt']['key']
action node['filebeat']['apt']['action']
end
when 'rhel'
# yum repository configuration
yum_repository 'beats' do
description node['filebeat']['yum']['description']
baseurl node['filebeat']['yum']['baseurl']
gpgcheck node['filebeat']['yum']['gpgcheck']
gpgkey node['filebeat']['yum']['gpgkey']
enabled node['filebeat']['yum']['enabled']
action node['filebeat']['yum']['action']
end
end

package 'filebeat' do
version node['platform_family'] == 'rhel' ? node['filebeat']['version'] + '-1' : node['filebeat']['version']
end
39 changes: 39 additions & 0 deletions recipes/install_windows.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#
# Cookbook Name:: filebeat
# Recipe:: install_windows
#
# Copyright 2015, Virender Khatri
#
# 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.
#

package_url = node['filebeat']['package_url'] == 'auto' ? "https://download.elastic.co/beats/filebeat/filebeat-#{node['filebeat']['version']}-windows.zip" : node['filebeat']['package_url']

package_file = ::File.join(Chef::Config[:file_cache_path], ::File.basename(package_url))

remote_file 'filebeat_package_file' do
path package_file
source package_url
not_if { ::File.exist?(package_file) }
end

directory node['filebeat']['windows']['base_dir'] do
recursive true
action :create
end

windows_zipfile node['filebeat']['windows']['base_dir'] do
source package_file
action :unzip
not_if { ::File.exist?(node['filebeat']['windows']['base_dir'] + "/filebeat-#{node['filebeat']['version']}-windows" + '/install-service-filebeat.ps1') }
end
34 changes: 24 additions & 10 deletions spec/unit/recipes/default_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,6 @@
describe 'filebeat::default' do
shared_examples_for 'filebeat' do
context 'all_platforms' do
%w(install config).each do |r|
it "include recipe filebeat::#{r}" do
expect(chef_run).to include_recipe("filebeat::#{r}")
end
end

it 'download filebeat package file' do
expect(chef_run).to create_remote_file('filebeat_package_file')
end

it 'create prospector directory /etc/filebeat/conf.d' do
expect(chef_run).to create_directory('/etc/filebeat/conf.d')
end
Expand All @@ -37,6 +27,14 @@

include_examples 'filebeat'

it 'adds beats yum repository' do
expect(chef_run).to create_yum_repository('beats')
end

it 'include recipe filebeat::install_package' do
expect(chef_run).to include_recipe('filebeat::install_package')
end

it 'install filebeat package' do
expect(chef_run).to install_package('filebeat')
end
Expand All @@ -51,6 +49,14 @@

include_examples 'filebeat'

it 'adds beats apt beats' do
expect(chef_run).to add_apt_repository('beats')
end

it 'include recipe filebeat::install_package' do
expect(chef_run).to include_recipe('filebeat::install_package')
end

it 'install filebeat package' do
expect(chef_run).to install_package('filebeat')
end
Expand All @@ -65,6 +71,14 @@

include_examples 'filebeat'

it 'include recipe filebeat::install_windows' do
expect(chef_run).to include_recipe('filebeat::install_windows')
end

it 'download filebeat package file' do
expect(chef_run).to create_remote_file('filebeat_package_file')
end

it 'create filebeat base dir C:/opt/filebeat/' do
expect(chef_run).to create_directory('C:/opt/filebeat/')
end
Expand Down

0 comments on commit c4971f5

Please sign in to comment.