diff --git a/.fixtures.yml b/.fixtures.yml index 3486053..aa1b858 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -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}" diff --git a/manifests/config.pp b/manifests/config.pp index 7b6f944..d897841 100644 --- a/manifests/config.pp +++ b/manifests/config.pp @@ -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) + } } } diff --git a/manifests/init.pp b/manifests/init.pp index 7877b11..21895df 100644 --- a/manifests/init.pp +++ b/manifests/init.pp @@ -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) { diff --git a/manifests/install.pp b/manifests/install.pp new file mode 100644 index 0000000..c87f5b0 --- /dev/null +++ b/manifests/install.pp @@ -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'], + } +} \ No newline at end of file diff --git a/manifests/params.pp b/manifests/params.pp index 94ad505..2385b48 100644 --- a/manifests/params.pp +++ b/manifests/params.pp @@ -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) + } + } } diff --git a/manifests/prospector.pp b/manifests/prospector.pp index 0876efa..3cce616 100644 --- a/manifests/prospector.pp +++ b/manifests/prospector.pp @@ -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) + } } } diff --git a/manifests/repo.pp b/manifests/repo.pp index 684d505..c470df9 100644 --- a/manifests/repo.pp +++ b/manifests/repo.pp @@ -42,7 +42,7 @@ } } default: { - fail("\"${module_name}\" provides no repository information for OSfamily \"${::osfamily}\"") + fail($filebeat::fail_message) } } } diff --git a/metadata.json b/metadata.json index c3ad572..ea62703 100644 --- a/metadata.json +++ b/metadata.json @@ -23,6 +23,13 @@ "12.04", "14.04" ] + }, + { + "operatingsystem": "Windows", + "operatingsystemrelease": [ + "Server 2012", + "Server 2012 R2" + ] } ], "dependencies": [ @@ -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" } ] } diff --git a/spec/classes/filebeat_spec.rb b/spec/classes/filebeat_spec.rb index 87ae423..befe099 100644 --- a/spec/classes/filebeat_spec.rb +++ b/spec/classes/filebeat_spec.rb @@ -3,6 +3,7 @@ describe 'filebeat', :type => :class do let :facts do { + :kernel => 'Linux', :osfamily => 'Debian', :lsbdistid => 'Ubuntu', :puppetversion => ENV['PUPPET_GEM_VERSION'], @@ -39,6 +40,7 @@ describe 'on a RHEL system' do let :facts do { + :kernel => 'Linux', :osfamily => 'RedHat', :puppetversion => ENV['PUPPET_GEM_VERSION'], } @@ -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 { diff --git a/spec/defines/prospector_spec.rb b/spec/defines/prospector_spec.rb index 1333575..0919543 100644 --- a/spec/defines/prospector_spec.rb +++ b/spec/defines/prospector_spec.rb @@ -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 @@ -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 diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb index b389f22..4976660 100644 --- a/spec/spec_helper_acceptance.rb +++ b/spec/spec_helper_acceptance.rb @@ -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