Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Windows support #3

Merged
merged 9 commits into from
Jan 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .fixtures.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ fixtures:
repositories:
"stdlib": "git://github.com/puppetlabs/puppetlabs-stdlib.git"
"apt": "git://github.com/puppetlabs/puppetlabs-apt.git"
"powershell": "git://github.com/puppetlabs/puppetlabs-powershell.git"
symlinks:
"filebeat": "#{source_dir}"
57 changes: 40 additions & 17 deletions manifests/config.pp
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,46 @@
default => 'filebeat.yml.erb',
}

file {'filebeat.yml':
ensure => file,
path => '/etc/filebeat/filebeat.yml',
content => template("${module_name}/${template_file}"),
owner => 'root',
group => 'root',
mode => '0644',
notify => Service['filebeat'],
}
case $::kernel {
'Linux' : {
file {'filebeat.yml':
ensure => file,
path => '/etc/filebeat/filebeat.yml',
content => template("${module_name}/${template_file}"),
owner => 'root',
group => 'root',
mode => '0644',
notify => Service['filebeat'],
}

file {'filebeat-config-dir':
ensure => directory,
path => $filebeat::config_dir,
owner => 'root',
group => 'root',
mode => '0755',
recurse => $filebeat::purge_conf_dir,
purge => $filebeat::purge_conf_dir,
}
} # end Linux

'Windows' : {
file {'filebeat.yml':
ensure => file,
path => 'C:/Program Files/Filebeat/filebeat.yml',
content => template("${module_name}/${template_file}"),
notify => Service['filebeat'],
}

file {'filebeat-config-dir':
ensure => directory,
path => $filebeat::config_dir,
owner => 'root',
group => 'root',
mode => '0755',
recurse => $filebeat::purge_conf_dir,
purge => $filebeat::purge_conf_dir,
file {'filebeat-config-dir':
ensure => directory,
path => $filebeat::config_dir,
recurse => $filebeat::purge_conf_dir,
purge => $filebeat::purge_conf_dir,
}
} # end Windows
default : {
fail($filebeat::fail_message)
}
}
}
34 changes: 27 additions & 7 deletions manifests/init.pp
Original file line number Diff line number Diff line change
Expand Up @@ -46,17 +46,37 @@
validate_string($idle_timeout, $registry_file, $config_dir, $package_ensure)

anchor { 'filebeat::begin': } ->
class { 'filebeat::package': } ->
class { 'filebeat::config': } ->
class { 'filebeat::service': } ->
anchor { 'filebeat::end':}
anchor { 'filebeat::end': }

if $manage_repo {
include filebeat::repo
case $::kernel {
'Linux' : {
include filebeat::package
if $manage_repo {
include filebeat::repo

Anchor['filebeat::begin'] ->
Class['filebeat::repo'] ->
Class['filebeat::package']
Anchor['filebeat::begin'] ->
Class['filebeat::repo'] ->
Class['filebeat::package'] ->
Class['filebeat::config']
}
else {
Anchor['filebeat::begin'] ->
Class['filebeat::package'] ->
Class['filebeat::config']
}
}
'Windows' : {
include filebeat::install

Anchor['filebeat::begin'] ->
Class['filebeat::install'] ->
Class['filebeat::config']
}
default: {
fail($filebeat::fail_message)
}
}

if !empty($prospectors) {
Expand Down
42 changes: 42 additions & 0 deletions manifests/install.pp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
class filebeat::install (
$download_url = $filebeat::download_url,
$install_dir = $filebeat::install_dir,
$tmp_dir = $filebeat::tmp_dir,

) {
$filename = regsubst($download_url, '^https.*\/([^\/]+)\.[^.].*', '\1')
$foldername = 'Filebeat'

file { $tmp_dir:
ensure => directory
}
file { $install_dir:
ensure => directory
}

exec { "download ${filename}":
command => "(New-Object System.Net.WebClient).DownloadFile('${download_url}', '${tmp_dir}/${filename}.zip')",
onlyif => "if(Test-Path -Path '${tmp_dir}/${filename}.zip') { exit 1 } else { exit 0 }",
provider => powershell,
require => File[$tmp_dir]
}
exec { "unzip ${filename}":
command => "\$sh=New-Object -COM Shell.Application;\$sh.namespace((Convert-Path '${install_dir}')).Copyhere(\$sh.namespace((Convert-Path '${tmp_dir}/${filename}.zip')).items(), 16)",
creates => "${install_dir}/Filebeat",
provider => powershell,
require => [Exec["download ${filename}"],File[$install_dir]],
}
exec { 'rename folder':
command => "Rename-Item '${install_dir}/${filename}' Filebeat",
creates => "${install_dir}/Filebeat",
provider => powershell,
require => Exec["unzip ${filename}"],
}
exec { "install ${filename}":
cwd => "${install_dir}/Filebeat",
command => './install-service-filebeat.ps1',
onlyif => "if(Get-WmiObject -Class Win32_Service -Filter \"Name='filebeat'\") { exit 1 } else {exit 0 }",
provider => powershell,
require => Exec['rename folder'],
}
}
20 changes: 19 additions & 1 deletion manifests/params.pp
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,27 @@
$spool_size = 1024
$idle_timeout = '5s'
$registry_file = '.filebeat'
$config_dir = '/etc/filebeat/conf.d'
$purge_conf_dir = true
$outputs = {}
$shipper = {}
$logging = {}

$fail_message = "${::kernel} is not yet supported by this module."

case $::kernel {
'Linux' : {
$config_dir = '/etc/filebeat/conf.d'
}

'Windows' : {
$config_dir = 'C:/Program Files/Filebeat/conf.d'
$download_url = 'https://download.elastic.co/beats/filebeat/filebeat-1.0.1-windows.zip'
$install_dir = 'C:/Program Files'
$tmp_dir = 'C:/Temp'
}

default : {
fail($fail_message)
}
}
}
32 changes: 24 additions & 8 deletions manifests/prospector.pp
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,29 @@
$partial_line_waiting = '5s',
$force_close_files = false,
) {
file { "filebeat-${name}":
ensure => $ensure,
path => "${filebeat::config_dir}/${name}.yml",
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/prospector.yml.erb"),
notify => Service['filebeat'],

case $::kernel {
'Linux' : {
file { "filebeat-${name}":
ensure => $ensure,
path => "${filebeat::config_dir}/${name}.yml",
owner => 'root',
group => 'root',
mode => '0644',
content => template("${module_name}/prospector.yml.erb"),
notify => Service['filebeat'],
}
}
'Windows' : {
file { "filebeat-${name}":
ensure => $ensure,
path => "${filebeat::config_dir}/${name}.yml",
content => template("${module_name}/prospector.yml.erb"),
notify => Service['filebeat'],
}
}
default : {
fail($filebeat::fail_message)
}
}
}
2 changes: 1 addition & 1 deletion manifests/repo.pp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
}
}
default: {
fail("\"${module_name}\" provides no repository information for OSfamily \"${::osfamily}\"")
fail($filebeat::fail_message)
}
}
}
11 changes: 11 additions & 0 deletions metadata.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@
"12.04",
"14.04"
]
},
{
"operatingsystem": "Windows",
"operatingsystemrelease": [
"Server 2012",
"Server 2012 R2"
]
}
],
"dependencies": [
Expand All @@ -33,6 +40,10 @@
{
"name": "puppetlabs/apt",
"version_requirement": ">=2.0.0 <3.0.0"
},
{
"name": "puppetlabs/powershell",
"version_requirement": ">= 1.0.1 < 2.0.0"
}
]
}
21 changes: 21 additions & 0 deletions spec/classes/filebeat_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
describe 'filebeat', :type => :class do
let :facts do
{
:kernel => 'Linux',
:osfamily => 'Debian',
:lsbdistid => 'Ubuntu',
:puppetversion => ENV['PUPPET_GEM_VERSION'],
Expand Down Expand Up @@ -39,6 +40,7 @@
describe 'on a RHEL system' do
let :facts do
{
:kernel => 'Linux',
:osfamily => 'RedHat',
:puppetversion => ENV['PUPPET_GEM_VERSION'],
}
Expand All @@ -50,6 +52,25 @@
) }
end

describe 'on a Windows system' do
let :facts do
{
:kernel => 'Windows',
:puppetversion => ENV['PUPPET_GEM_VERSION'],
}
end

it { is_expected.to contain_file('filebeat.yml').with(
:path => 'C:/Program Files/Filebeat/filebeat.yml',
)}
it { is_expected.to contain_file('filebeat-config-dir').with(
:ensure => 'directory',
:path => 'C:/Program Files/Filebeat/conf.d',
:recurse => true,
)}
end


describe 'on a Solaris system' do
let :facts do
{
Expand Down
71 changes: 59 additions & 12 deletions spec/defines/prospector_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,26 @@
it { expect { should raise_error(Puppet::Error) } }
end

context 'with file blobs set' do
let :params do
{
:paths => [
'/var/log/apache2/*.log',
],
:log_type => 'apache',
}
context 'When deploying on Linux system' do
let :facts do {
:kernel => 'Linux',
}
end

it { is_expected.to contain_file('filebeat-apache-logs').with(
:path => '/apache-logs.yml',
:mode => '0644',
:content => 'filebeat:
context 'with file blobs set on Linux' do
let :params do
{
:paths => [
'/var/log/apache2/*.log',
],
:log_type => 'apache',
}
end

it { is_expected.to contain_file('filebeat-apache-logs').with(
:path => '/apache-logs.yml',
:mode => '0644',
:content => 'filebeat:
prospectors:
- paths:
- /var/log/apache2/*.log
Expand All @@ -41,5 +47,46 @@
partial_line_waiting: 5s
',
)}
end
end

context 'When deploying on Windows system' do
let :facts do {
:kernel => 'Windows',
}
end

context 'with file blobs set on Linux' do
let :params do
{
:paths => [
'C:/Program Files/Apache Software Foundation/Apache2.2/*.log',
],
:log_type => 'apache',
}
end

it { is_expected.to contain_file('filebeat-apache-logs').with(
:path => '/apache-logs.yml',
:content => 'filebeat:
prospectors:
- paths:
- C:/Program Files/Apache Software Foundation/Apache2.2/*.log
encoding: plain
fields_under_root: false
input_type: log
ignore_older: 24h
document_type: apache
scan_frequency: 10s
harvester_buffer_size: 16384
tail_files: false
force_close_files: false
backoff: 1s
max_backoff: 10s
backoff_factor: 2
partial_line_waiting: 5s
',
)}
end
end
end
1 change: 1 addition & 0 deletions spec/spec_helper_acceptance.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
hosts.each do |host|
on host, puppet('module','install','puppetlabs-stdlib'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module','install','puppetlabs-apt'), { :acceptable_exit_codes => [0,1] }
on host, puppet('module','install','puppetlabs-powershell'), { :acceptable_exit_codes => [0,1] }
end
end
end