diff --git a/.fixtures.yml b/.fixtures.yml index 15cbbfd..228e7c5 100644 --- a/.fixtures.yml +++ b/.fixtures.yml @@ -2,6 +2,6 @@ fixtures: forge_modules: stdlib: repo: 'puppetlabs/stdlib' - ref: '4.5.1' + ref: '4.12.0' symlinks: loggly: "#{source_dir}" diff --git a/.gitignore b/.gitignore index 641e153..5a8d64c 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ spec/fixtures .vagrant .bundle vendor +.DS_Store diff --git a/CONTRIBUTORS b/CONTRIBUTORS index c55f0f5..31f402f 100644 --- a/CONTRIBUTORS +++ b/CONTRIBUTORS @@ -9,3 +9,4 @@ Ryan Coleman jasons-loggly maxgutman psquickitjayant +drewrothstein diff --git a/Gemfile.lock b/Gemfile.lock index 3ceca1d..82cf32d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -354,7 +354,7 @@ DEPENDENCIES beaker-rspec guard-rake metadata-json-lint - puppet (~> 3.7.0) + puppet (~> 3.7.5) puppet-blacksmith puppetlabs_spec_helper rake @@ -364,3 +364,6 @@ DEPENDENCIES travis travis-lint vagrant-wrapper + +BUNDLED WITH + 1.12.5 diff --git a/manifests/syslog_ng.pp b/manifests/syslog_ng.pp index 8c7db47..0958d52 100644 --- a/manifests/syslog_ng.pp +++ b/manifests/syslog_ng.pp @@ -72,10 +72,12 @@ # include a configuration snippet directory, so we ensure it is # present file_line { 'snippet_dir': - ensure => present, - path => '/etc/syslog-ng/syslog-ng.conf', - line => '@include "/etc/syslog-ng/conf.d/"', - before => File['/etc/syslog-ng/conf.d/22-loggly.conf'], + ensure => present, + path => '/etc/syslog-ng/syslog-ng.conf', + line => '@include "/etc/syslog-ng/conf.d/"', + replace => false, + match => '^@include "/etc/syslog-ng/conf.d.*$', + before => File['/etc/syslog-ng/conf.d/22-loggly.conf'], } # Packages available from the EPEL repo for syslog-ng on diff --git a/manifests/uninstall.pp b/manifests/uninstall.pp new file mode 100644 index 0000000..d755213 --- /dev/null +++ b/manifests/uninstall.pp @@ -0,0 +1,84 @@ +# == Define: loggly::uninstall +# +# Removes loggly in its entirety. +# If any custom logs were specified, they must be specified here for removal. +# +# === Parameters +# +# [*logname*] +# The label of the log file to remove configuration from if it was previously specified. +# +# [*filepath*] +# The fully qualified path to the file to remove configuration from. +# +# === Variables +# +# [*_t*] +# An internal temp variable used for string parsing. +# +# [*_logname*] +# An internal temp variable used for string parsing. +# +# === Examples +# +# loggly::uninstall { 'remove': } +# +# loggly::uninstall { '/phil/collins': } +# +# loggly::uninstall { '/phil/collins': +# logname => 'in_the_air_tonight', +# } +# +# === Authors +# +# Drew Rothstein +# +define loggly::uninstall ( + $logname = undef, + $filepath = $title, +) { + include loggly::params + + file { $::loggly::params::base_dir: + ensure => absent, + recurse => true, + purge => true, + force => true, + } + + file { '/etc/rsyslog.d/22-loggly.conf': + ensure => absent, + notify => Exec['restart_rsyslogd'], + } + + file { '/etc/syslog-ng/conf.d/22-loggly.conf': + ensure => absent, + notify => Exec['restart_syslog_ng'], + } + + if is_absolute_path($filepath) { + $_t = split($filepath, '/') + $_logname = pick($logname, $_t[-1]) + + validate_string($_logname) + + file { "/etc/rsyslog.d/${_logname}.conf": + ensure => absent, + notify => Exec['restart_rsyslogd'], + } + } + + exec { 'restart_rsyslogd': + command => 'service rsyslog restart', + path => [ '/usr/sbin', '/sbin', '/usr/bin/', '/bin', ], + refreshonly => true, + } + + exec { 'restart_syslog_ng': + command => 'service syslog-ng restart', + path => [ '/usr/sbin', '/sbin', '/usr/bin/', '/bin', ], + refreshonly => true, + } +} + +# vim: syntax=puppet ft=puppet ts=2 sw=2 nowrap et diff --git a/metadata.json b/metadata.json index eacc1a6..31575f1 100644 --- a/metadata.json +++ b/metadata.json @@ -11,7 +11,7 @@ "dependencies": [ { "name": "puppetlabs-stdlib", - "version_requirement": ">= 4.2.0 < 5.0.0" + "version_requirement": ">= 4.12.0 < 5.0.0" } ], "requirements": [ diff --git a/spec/acceptance/class_spec.rb b/spec/acceptance/class_spec.rb index 00e841f..3c54dd2 100644 --- a/spec/acceptance/class_spec.rb +++ b/spec/acceptance/class_spec.rb @@ -1,26 +1,37 @@ require 'spec_helper_acceptance' describe 'loggly class' do + # Using puppet_apply as a helper + it 'should work idempotently with no errors' do + pp = <<-EOS + class { 'loggly': + base_dir => '/usr/local/loggly', + enable_tls => true, + } + EOS - context 'default parameters' do - # Using puppet_apply as a helper - it 'should work idempotently with no errors' do - pp = <<-EOS - class { 'loggly': } - EOS + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end - # Run it twice and test for idempotency - apply_manifest(pp, :catch_failures => true) - apply_manifest(pp, :catch_changes => true) - end + describe file('/usr/local/loggly') do + it { is_expected.to be_directory } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + end - describe package('loggly') do - it { is_expected.to be_installed } - end + describe file('/usr/local/loggly/certs') do + it { is_expected.to be_directory } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + end - describe service('loggly') do - it { is_expected.to be_enabled } - it { is_expected.to be_running } - end + describe file('/usr/local/loggly/certs/loggly_full.crt') do + it { is_expected.to be_file } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + it { should contain 'BEGIN CERTIFICATE' } + it { should contain 'END CERTIFICATE' } end end diff --git a/spec/acceptance/nodesets/centos-64-x64.yml b/spec/acceptance/nodesets/centos-64-x64.yml index d19aa69..e140e98 100644 --- a/spec/acceptance/nodesets/centos-64-x64.yml +++ b/spec/acceptance/nodesets/centos-64-x64.yml @@ -6,6 +6,7 @@ HOSTS: box : centos-64-x64-vbox4210-nocm box_url : http://puppet-vagrant-boxes.puppetlabs.com/centos-64-x64-vbox4210-nocm.box hypervisor : vagrant + CONFIG: log_level: verbose type: foss diff --git a/spec/acceptance/nodesets/centos-66-x64.yml b/spec/acceptance/nodesets/centos-66-x64.yml index 07843d5..17a1aba 100644 --- a/spec/acceptance/nodesets/centos-66-x64.yml +++ b/spec/acceptance/nodesets/centos-66-x64.yml @@ -6,6 +6,7 @@ HOSTS: box: puppetlabs/centos-6.6-64-nocm box_url: https://vagrantcloud.com/puppetlabs/boxes/centos-6.6-64-nocm hypervisor: vagrant + CONFIG: log_level: verbose type: foss diff --git a/spec/acceptance/nodesets/centos-7-x64.yml b/spec/acceptance/nodesets/centos-7-x64.yml index 8e73537..9160138 100644 --- a/spec/acceptance/nodesets/centos-7-x64.yml +++ b/spec/acceptance/nodesets/centos-7-x64.yml @@ -3,8 +3,8 @@ HOSTS: roles: - master platform: el-7-x86_64 - box: chef/centos-7.0 - box_url: https://vagrantcloud.com/chef/boxes/centos-7.0 + box: centos/7 + box_url: https://atlas.hashicorp.com/centos/boxes/7 hypervisor: vagrant CONFIG: diff --git a/spec/acceptance/nodesets/debian-711-x64.yml b/spec/acceptance/nodesets/debian-711-x64.yml new file mode 100644 index 0000000..3c2d3f2 --- /dev/null +++ b/spec/acceptance/nodesets/debian-711-x64.yml @@ -0,0 +1,12 @@ +HOSTS: + debian-711-x64: + roles: + - master + platform: debian-7-amd64 + box: debian/wheezy64 + box_url: https://atlas.hashicorp.com/debian/boxes/wheezy64 + hypervisor: vagrant + +CONFIG: + log_level: verbose + type: foss diff --git a/spec/acceptance/nodesets/debian-76-x64.yml b/spec/acceptance/nodesets/debian-76-x64.yml deleted file mode 100644 index 683e635..0000000 --- a/spec/acceptance/nodesets/debian-76-x64.yml +++ /dev/null @@ -1,12 +0,0 @@ -HOSTS: - debian-76-x64: - roles: - - master - platform: debian-7-amd64 - box: puppetlabs/debian-7.6-64-nocm - box_url: https://vagrantcloud.com/puppetlabs/boxes/debian-7.6-64-nocm - hypervisor: vagrant - -CONFIG: - log_level: verbose - type: foss diff --git a/spec/acceptance/rsyslog_spec.rb b/spec/acceptance/rsyslog_spec.rb new file mode 100644 index 0000000..99d6090 --- /dev/null +++ b/spec/acceptance/rsyslog_spec.rb @@ -0,0 +1,34 @@ +require 'spec_helper_acceptance' + +describe 'rsyslog class' do + # Using puppet_apply as a helper + it 'should work idempotently with no errors' do + pp = <<-EOS + class { 'loggly::rsyslog': + customer_token => '00000000-0000-0000-0000-000000000000', + cert_path => '/usr/local/loggly/certs', + enable_tls => true, + } + EOS + + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe package('rsyslog-gnutls') do + it { is_expected.to be_installed } + end + + describe service('rsyslog') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + + describe file('/etc/rsyslog.d/22-loggly.conf') do + it { is_expected.to be_file } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + it { should contain 'LogglyFormat' } + end +end diff --git a/spec/acceptance/syslog_ng_spec.rb b/spec/acceptance/syslog_ng_spec.rb new file mode 100644 index 0000000..17cfb49 --- /dev/null +++ b/spec/acceptance/syslog_ng_spec.rb @@ -0,0 +1,58 @@ +require 'spec_helper_acceptance' + +describe 'syslog_ng class' do + # Using puppet_apply as a helper + # Install syslog-ng as this module assumes it is installed outside of it + it 'should work idempotently with no errors' do + case fact('operatingsystem') + when 'CentOS' + pp = <<-EOS + package { 'epel-release': + ensure => 'installed', + } + + package { 'syslog-ng': + ensure => 'installed', + require => Package['epel-release'], + } + + class { 'loggly::syslog_ng': + customer_token => '00000000-0000-0000-0000-000000000000', + cert_path => '/usr/local/loggly/certs', + enable_tls => true, + } + EOS + else + pp = <<-EOS + package { 'syslog-ng': + ensure => 'installed', + } + + class { 'loggly::syslog_ng': + customer_token => '00000000-0000-0000-0000-000000000000', + cert_path => '/usr/local/loggly/certs', + enable_tls => true, + } + EOS + end + # Run it twice and test for idempotency + apply_manifest(pp, :catch_failures => true) + apply_manifest(pp, :catch_changes => true) + end + + describe package('syslog-ng') do + it { is_expected.to be_installed } + end + + describe service('syslog-ng') do + it { is_expected.to be_enabled } + it { is_expected.to be_running } + end + + describe file('/etc/syslog-ng/conf.d/22-loggly.conf') do + it { is_expected.to be_file } + it { is_expected.to be_owned_by 'root' } + it { is_expected.to be_grouped_into 'root' } + it { should contain 'LogglyFormat' } + end +end diff --git a/spec/defines/loggly__uninstall_spec.rb b/spec/defines/loggly__uninstall_spec.rb new file mode 100644 index 0000000..4d2895b --- /dev/null +++ b/spec/defines/loggly__uninstall_spec.rb @@ -0,0 +1,59 @@ +require 'spec_helper' + +describe 'loggly::uninstall', :type => :define do + let(:facts) do + { + :operatingsystem => 'RedHat' + } + end + + context 'should remove loggly configuration directory and files' do + let :title do + 'remove_me' + end + + it { is_expected.to contain_file( + '/etc/rsyslog.d/22-loggly.conf').with_ensure( + 'absent').that_notifies('Exec[restart_rsyslogd]') } + + it { is_expected.to contain_file( + '/etc/syslog-ng/conf.d/22-loggly.conf').with_ensure( + 'absent').that_notifies('Exec[restart_syslog_ng]') } + end + + context 'should remove configuration for $title' do + let :title do + '/phil/collins' + end + + it { is_expected.to contain_file( + '/etc/rsyslog.d/collins.conf').with_ensure('absent') } + end + + context 'should remove configuration for $logname' do + let :title do + '/phil/collins' + end + + let(:params) {{ + :logname => 'in_the_air_tonight' + }} + + it { is_expected.to contain_file( + '/etc/rsyslog.d/in_the_air_tonight.conf').with_ensure('absent') } + end + + context 'should remove configuration for $logname and notify' do + let :title do + '/phil/collins' + end + + let(:params) {{ + :logname => 'in_the_air_tonight' + }} + + it { is_expected.to contain_file( + '/etc/rsyslog.d/in_the_air_tonight.conf').with_ensure( + 'absent').that_notifies('Exec[restart_rsyslogd]') } + end +end