├── .coveralls.yml ├── spec ├── fixtures │ └── unit │ │ └── puppet │ │ └── provider │ │ ├── syslog │ │ ├── augeas │ │ │ ├── empty │ │ │ ├── full │ │ │ └── broken │ │ └── rsyslog │ │ │ ├── empty │ │ │ ├── full │ │ │ └── broken │ │ └── rsyslog_filter │ │ └── augeas │ │ ├── empty │ │ ├── broken │ │ └── full ├── spec_helper_acceptance.rb ├── spec_helper.rb └── unit │ └── puppet │ └── provider │ ├── rsyslog_filter │ └── augeas_spec.rb │ └── syslog │ ├── rsyslog_spec.rb │ └── augeas_spec.rb ├── .gitmodules ├── .fixtures.yml ├── .msync.yml ├── .github ├── labeler.yml ├── workflows │ ├── labeler.yml │ ├── ci.yml │ ├── release.yml │ └── prepare_release.yml ├── PULL_REQUEST_TEMPLATE.md ├── ISSUE_TEMPLATE.md └── release.yml ├── .puppet-lint.rc ├── .rubocop.yml ├── .editorconfig ├── .gitignore ├── lib └── puppet │ ├── provider │ ├── syslog │ │ ├── rsyslog.rb │ │ └── augeas.rb │ └── rsyslog_filter │ │ └── augeas.rb │ └── type │ ├── rsyslog_filter.rb │ └── syslog.rb ├── .sync.yml ├── .pmtignore ├── Gemfile ├── Rakefile ├── .travis.sh ├── .overcommit.yml ├── metadata.json ├── .rubocop_todo.yml ├── README.md ├── CHANGELOG.md └── LICENSE /.coveralls.yml: -------------------------------------------------------------------------------- 1 | service_name: travis-ci 2 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/syslog/augeas/empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/syslog/rsyslog/empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/rsyslog_filter/augeas/empty: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "augeas"] 2 | path = augeas 3 | url = git://github.com/hercules-team/augeas.git 4 | -------------------------------------------------------------------------------- /.fixtures.yml: -------------------------------------------------------------------------------- 1 | --- 2 | fixtures: 3 | repositories: 4 | augeasproviders_core: https://github.com/voxpupuli/puppet-augeasproviders_core.git 5 | -------------------------------------------------------------------------------- /.msync.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | modulesync_config_version: '10.4.0' 6 | -------------------------------------------------------------------------------- /.github/labeler.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | skip-changelog: 6 | - head-branch: ['^release-*', 'release'] 7 | -------------------------------------------------------------------------------- /.puppet-lint.rc: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | 4 | --fail-on-warnings 5 | --no-parameter_documentation-check 6 | --no-parameter_types-check 7 | -------------------------------------------------------------------------------- /.rubocop.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | inherit_from: .rubocop_todo.yml 6 | inherit_gem: 7 | voxpupuli-test: rubocop.yml 8 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # editorconfig.org 2 | 3 | # Managed by modulesync - DO NOT EDIT 4 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 5 | 6 | root = true 7 | 8 | [*] 9 | charset = utf-8 10 | end_of_line = lf 11 | indent_size = 2 12 | tab_width = 2 13 | indent_style = space 14 | insert_final_newline = true 15 | trim_trailing_whitespace = true 16 | -------------------------------------------------------------------------------- /spec/spec_helper_acceptance.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Managed by modulesync - DO NOT EDIT 4 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 5 | 6 | require 'voxpupuli/acceptance/spec_helper_acceptance' 7 | 8 | configure_beaker(modules: :metadata) 9 | 10 | Dir['./spec/support/acceptance/**/*.rb'].sort.each { |f| require f } 11 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | 4 | /pkg/ 5 | /Gemfile.lock 6 | /Gemfile.local 7 | /vendor/ 8 | /.vendor/ 9 | /spec/fixtures/manifests/ 10 | /spec/fixtures/modules/ 11 | /.vagrant/ 12 | /.bundle/ 13 | /.ruby-version 14 | /coverage/ 15 | /log/ 16 | /.idea/ 17 | /.dependencies/ 18 | /.librarian/ 19 | /Puppetfile.lock 20 | *.iml 21 | .*.sw? 22 | /.yardoc/ 23 | /Guardfile 24 | bolt-debug.log 25 | .rerun.json 26 | -------------------------------------------------------------------------------- /lib/puppet/provider/syslog/rsyslog.rb: -------------------------------------------------------------------------------- 1 | # Alternative Augeas-based providers for Puppet 2 | # 3 | # Copyright (c) 2012 Raphaël Pinson 4 | # Licensed under the Apache License, Version 2.0 5 | 6 | Puppet::Type.type(:syslog).provide(:rsyslog, parent: :augeas) do 7 | desc 'Uses Augeas API to update an rsyslog.conf entry' 8 | 9 | default_file { '/etc/rsyslog.conf' } 10 | lens { 'Rsyslog.lns' } 11 | 12 | resource_path do |resource| 13 | entry_path(resource) 14 | end 15 | 16 | confine feature: :augeas 17 | end 18 | -------------------------------------------------------------------------------- /.github/workflows/labeler.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | name: "Pull Request Labeler" 6 | 7 | # yamllint disable-line rule:truthy 8 | on: 9 | pull_request_target: {} 10 | 11 | permissions: 12 | contents: read 13 | pull-requests: write 14 | 15 | jobs: 16 | labeler: 17 | permissions: 18 | contents: read 19 | pull-requests: write 20 | runs-on: ubuntu-latest 21 | steps: 22 | - uses: actions/labeler@v5 23 | -------------------------------------------------------------------------------- /.sync.yml: -------------------------------------------------------------------------------- 1 | --- 2 | .github/workflows/ci.yml: 3 | with: 4 | additional_packages: libaugeas-dev augeas-tools 5 | rubocop: false 6 | Gemfile: 7 | optional: 8 | ':test': 9 | - gem: ruby-augeas 10 | spec/spec_helper.rb: 11 | spec_overrides: 12 | - "require 'fixtures/modules/augeasproviders_core/spec/support/spec/psh_fixtures'" 13 | - "require 'augeas_spec'" 14 | - "# augeasproviders: setting $LOAD_PATH to work around broken type autoloading" 15 | - "$LOAD_PATH.unshift(File.join(__dir__, 'fixtures/modules/augeasproviders_core/lib'))" 16 | spec/spec_helper_acceptance.rb: 17 | unmanaged: false 18 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 9 | #### Pull Request (PR) description 10 | 13 | 14 | #### This Pull Request (PR) fixes the following issues 15 | 21 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | name: CI 6 | 7 | # yamllint disable-line rule:truthy 8 | on: 9 | pull_request: {} 10 | push: 11 | branches: 12 | - main 13 | - master 14 | 15 | concurrency: 16 | group: ${{ github.ref_name }} 17 | cancel-in-progress: true 18 | 19 | permissions: 20 | contents: read 21 | 22 | jobs: 23 | puppet: 24 | name: Puppet 25 | uses: voxpupuli/gha-puppet/.github/workflows/basic.yml@v4 26 | with: 27 | additional_packages: 'libaugeas-dev augeas-tools' 28 | rubocop: false 29 | -------------------------------------------------------------------------------- /.pmtignore: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | 4 | /docs/ 5 | /pkg/ 6 | /Gemfile 7 | /Gemfile.lock 8 | /Gemfile.local 9 | /vendor/ 10 | /.vendor/ 11 | /spec/ 12 | /Rakefile 13 | /.vagrant/ 14 | /.bundle/ 15 | /.ruby-version 16 | /coverage/ 17 | /log/ 18 | /.idea/ 19 | /.dependencies/ 20 | /.github/ 21 | /.librarian/ 22 | /Puppetfile.lock 23 | /Puppetfile 24 | *.iml 25 | /.editorconfig 26 | /.fixtures.yml 27 | /.gitignore 28 | /.msync.yml 29 | /.overcommit.yml 30 | /.pmtignore 31 | /.rspec 32 | /.rspec_parallel 33 | /.rubocop.yml 34 | /.sync.yml 35 | .*.sw? 36 | /.yardoc/ 37 | /.yardopts 38 | /Dockerfile 39 | /HISTORY.md 40 | -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | name: Release 6 | 7 | # yamllint disable-line rule:truthy 8 | on: 9 | push: 10 | tags: 11 | - '*' 12 | 13 | permissions: 14 | contents: write 15 | 16 | jobs: 17 | release: 18 | name: Release 19 | uses: voxpupuli/gha-puppet/.github/workflows/release.yml@v3 20 | with: 21 | allowed_owner: 'voxpupuli' 22 | secrets: 23 | # Configure secrets here: 24 | # https://docs.github.com/en/actions/security-guides/encrypted-secrets 25 | username: ${{ secrets.PUPPET_FORGE_USERNAME }} 26 | api_key: ${{ secrets.PUPPET_FORGE_API_KEY }} 27 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | 10 | 11 | ## Affected Puppet, Ruby, OS and module versions/distributions 12 | 13 | - Puppet: 14 | - Ruby: 15 | - Distribution: 16 | - Module version: 17 | 18 | ## How to reproduce (e.g Puppet code you use) 19 | 20 | ## What are you seeing 21 | 22 | ## What behaviour did you expect instead 23 | 24 | ## Output log 25 | 26 | ## Any additional information you'd like to impart 27 | -------------------------------------------------------------------------------- /.github/workflows/prepare_release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | name: 'Prepare Release' 6 | 7 | on: 8 | workflow_dispatch: 9 | inputs: 10 | version: 11 | description: 'Module version to be released. Must be a valid semver string without leading v. (1.2.3)' 12 | required: false 13 | 14 | permissions: 15 | contents: write 16 | pull-requests: write 17 | 18 | jobs: 19 | release_prep: 20 | uses: 'voxpupuli/gha-puppet/.github/workflows/prepare_release.yml@v3' 21 | with: 22 | version: ${{ github.event.inputs.version }} 23 | allowed_owner: 'voxpupuli' 24 | secrets: 25 | # Configure secrets here: 26 | # https://docs.github.com/en/actions/security-guides/encrypted-secrets 27 | github_pat: '${{ secrets.PCCI_PAT_RELEASE_PREP }}' 28 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | 4 | source ENV['GEM_SOURCE'] || 'https://rubygems.org' 5 | 6 | group :test do 7 | gem 'voxpupuli-test', '~> 13.0', :require => false 8 | gem 'puppet_metadata', '~> 5.0', :require => false 9 | gem 'ruby-augeas', :require => false 10 | end 11 | 12 | group :development do 13 | gem 'guard-rake', :require => false 14 | gem 'overcommit', '>= 0.39.1', :require => false 15 | end 16 | 17 | group :system_tests do 18 | gem 'voxpupuli-acceptance', '~> 4.0', :require => false 19 | end 20 | 21 | group :release do 22 | gem 'voxpupuli-release', '~> 5.0', :require => false 23 | end 24 | 25 | gem 'rake', :require => false 26 | 27 | gem 'openvox', ENV.fetch('OPENVOX_GEM_VERSION', [">= 7", "< 9"]), :require => false, :groups => [:test] 28 | 29 | # vim: syntax=ruby 30 | -------------------------------------------------------------------------------- /.github/release.yml: -------------------------------------------------------------------------------- 1 | --- 2 | # Managed by modulesync - DO NOT EDIT 3 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 4 | 5 | # https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes 6 | 7 | changelog: 8 | exclude: 9 | labels: 10 | - duplicate 11 | - invalid 12 | - modulesync 13 | - question 14 | - skip-changelog 15 | - wont-fix 16 | - wontfix 17 | 18 | categories: 19 | - title: Breaking Changes 🛠 20 | labels: 21 | - backwards-incompatible 22 | 23 | - title: New Features 🎉 24 | labels: 25 | - enhancement 26 | 27 | - title: Bug Fixes 🐛 28 | labels: 29 | - bug 30 | 31 | - title: Documentation Updates 📚 32 | labels: 33 | - documentation 34 | - docs 35 | 36 | - title: Dependency Updates ⬆️ 37 | labels: 38 | - dependencies 39 | 40 | - title: Other Changes 41 | labels: 42 | - "*" 43 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/syslog/augeas/full: -------------------------------------------------------------------------------- 1 | # Log all kernel messages to the console. 2 | # Logging much else clutters up the screen. 3 | #kern.* /dev/console 4 | 5 | # Log anything (except mail) of level info or higher. 6 | # Don't log private authentication messages! 7 | *.info;mail.none;authpriv.none;cron.none /var/log/messages 8 | 9 | # The authpriv file has restricted access. 10 | authpriv.* /var/log/secure 11 | 12 | # Log all the mail messages in one place. 13 | mail.* -/var/log/maillog 14 | 15 | 16 | # Log cron stuff 17 | cron.* /var/log/cron 18 | 19 | # Everybody gets emergency messages 20 | *.emerg * 21 | 22 | # Save news errors of level crit and higher in a special file. 23 | uucp,news.crit /var/log/spooler 24 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/syslog/augeas/broken: -------------------------------------------------------------------------------- 1 | # Log all kernel messages to the console. 2 | # Logging much else clutters up the screen. 3 | #kern.* /dev/console 4 | 5 | # Log anything (except mail) of level info or higher. 6 | # Don't log private authentication messages! 7 | *.info;mail.none;authpriv.none;cron.none /var/log/messages 8 | 9 | # The authpriv file has restricted access. 10 | authpriv.* /var/log/secure 11 | 12 | # Log all the mail messages in one place. 13 | mail.* -/var/log/maillog 14 | 15 | ;broken 16 | 17 | # Log cron stuff 18 | cron.* /var/log/cron 19 | 20 | # Everybody gets emergency messages 21 | *.emerg * 22 | 23 | # Save news errors of level crit and higher in a special file. 24 | uucp,news.crit /var/log/spooler 25 | 26 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | 4 | begin 5 | require 'voxpupuli/test/rake' 6 | rescue LoadError 7 | # only available if gem group test is installed 8 | end 9 | 10 | begin 11 | require 'voxpupuli/acceptance/rake' 12 | rescue LoadError 13 | # only available if gem group acceptance is installed 14 | end 15 | 16 | begin 17 | require 'voxpupuli/release/rake_tasks' 18 | rescue LoadError 19 | # only available if gem group releases is installed 20 | else 21 | GCGConfig.user = 'voxpupuli' 22 | GCGConfig.project = 'puppet-augeasproviders_syslog' 23 | end 24 | 25 | desc "Run main 'test' task and report merged results to coveralls" 26 | task test_with_coveralls: [:test] do 27 | if Dir.exist?(File.expand_path('../lib', __FILE__)) 28 | require 'coveralls/rake/task' 29 | Coveralls::RakeTask.new 30 | Rake::Task['coveralls:push'].invoke 31 | else 32 | puts 'Skipping reporting to coveralls. Module has no lib dir' 33 | end 34 | end 35 | 36 | # vim: syntax=ruby 37 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | # frozen_string_literal: true 2 | 3 | # Managed by modulesync - DO NOT EDIT 4 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 5 | 6 | # puppetlabs_spec_helper will set up coverage if the env variable is set. 7 | # We want to do this if lib exists and it hasn't been explicitly set. 8 | ENV['COVERAGE'] ||= 'yes' if Dir.exist?(File.expand_path('../lib', __dir__)) 9 | 10 | require 'voxpupuli/test/spec_helper' 11 | 12 | RSpec.configure do |c| 13 | c.facterdb_string_keys = false 14 | end 15 | 16 | add_mocked_facts! 17 | 18 | if File.exist?(File.join(__dir__, 'default_module_facts.yml')) 19 | facts = YAML.safe_load(File.read(File.join(__dir__, 'default_module_facts.yml'))) 20 | facts&.each do |name, value| 21 | add_custom_fact name.to_sym, value 22 | end 23 | end 24 | 25 | require 'fixtures/modules/augeasproviders_core/spec/support/spec/psh_fixtures' 26 | 27 | require 'augeas_spec' 28 | 29 | # augeasproviders: setting $LOAD_PATH to work around broken type autoloading 30 | 31 | $LOAD_PATH.unshift(File.join(__dir__, 'fixtures/modules/augeasproviders_core/lib')) 32 | Dir['./spec/support/spec/**/*.rb'].sort.each { |f| require f } 33 | -------------------------------------------------------------------------------- /.travis.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | set -xe 3 | 4 | # Clone submodules in tree 5 | git submodule update --init 6 | 7 | if [ -z $AUGEAS ]; then 8 | # Use latest version of lenses 9 | cd augeas && git pull origin master 10 | PKG_VERSION="" 11 | else 12 | if [ -z $LENSES ]; then 13 | # Use matching version of lenses 14 | cd augeas && git fetch && git checkout release-${AUGEAS} 15 | else 16 | cd augeas && git fetch && git checkout $LENSES 17 | fi 18 | 19 | PKG_VERSION="=${AUGEAS}*" 20 | # Add PPA 21 | sudo add-apt-repository -y ppa:raphink/augeas-1.0.0 22 | sudo add-apt-repository -y ppa:raphink/augeas-1.1.0 23 | sudo add-apt-repository -y ppa:raphink/augeas-1.2.0 24 | sudo add-apt-repository -y ppa:raphink/augeas-1.3.0 25 | fi 26 | sudo add-apt-repository -y ppa:raphink/augeas 27 | sudo apt-get update 28 | sudo apt-get install augeas-tools${PKG_VERSION} \ 29 | augeas-lenses${PKG_VERSION} \ 30 | libaugeas0${PKG_VERSION} \ 31 | libaugeas-dev${PKG_VERSION} \ 32 | libxml2-dev 33 | 34 | # Install gems 35 | gem install bundler 36 | bundle install 37 | 38 | # Reporting only 39 | bundle show 40 | puppet --version 41 | augtool --version 42 | -------------------------------------------------------------------------------- /lib/puppet/type/rsyslog_filter.rb: -------------------------------------------------------------------------------- 1 | # Manages filters in rsyslog.conf file 2 | # 3 | # Copyright (c) 2019 Raphaël Pinson 4 | # Licensed under the Apache License, Version 2.0 5 | 6 | Puppet::Type.newtype(:rsyslog_filter) do 7 | @doc = 'Manages filters in rsyslog.conf.' 8 | 9 | ensurable 10 | 11 | newparam(:name) do 12 | desc 'The name of the resource.' 13 | isnamevar 14 | end 15 | 16 | newparam(:property) do 17 | desc 'The filter property.' 18 | end 19 | 20 | newparam(:operation) do 21 | desc 'The filter operation.' 22 | end 23 | 24 | newparam(:value) do 25 | desc 'The filter value.' 26 | end 27 | 28 | newparam(:action_type) do 29 | desc 'The type of action: file, hostname, user or program.' 30 | end 31 | 32 | newparam(:action_protocol) do 33 | desc 'When action is hostname, the optional protocol.' 34 | newvalues :udp, :tcp, :'@', :'@@' 35 | 36 | munge do |value| 37 | case value 38 | when :udp, 'udp', :'@', '@' 39 | '@' 40 | when :tcp, 'tcp', :'@@', '@@' 41 | '@@' 42 | end 43 | end 44 | end 45 | 46 | newparam(:action_port) do 47 | desc 'When action is hostname, the optional port.' 48 | end 49 | 50 | newparam(:action) do 51 | desc 'The action for the entry.' 52 | end 53 | 54 | newparam(:target) do 55 | desc "The file in which to store the settings, defaults to 56 | `/etc/rsyslog.conf`." 57 | end 58 | 59 | newparam(:lens) do 60 | desc 'The augeas lens used to parse the file' 61 | end 62 | 63 | autorequire(:file) do 64 | self[:target] 65 | end 66 | end 67 | -------------------------------------------------------------------------------- /.overcommit.yml: -------------------------------------------------------------------------------- 1 | # Managed by modulesync - DO NOT EDIT 2 | # https://voxpupuli.org/docs/updating-files-managed-with-modulesync/ 3 | # 4 | # Hooks are only enabled if you take action. 5 | # 6 | # To enable the hooks run: 7 | # 8 | # ``` 9 | # bundle exec overcommit --install 10 | # # ensure .overcommit.yml does not harm to you and then 11 | # bundle exec overcommit --sign 12 | # ``` 13 | # 14 | # (it will manage the .git/hooks directory): 15 | # 16 | # Examples howto skip a test for a commit or push: 17 | # 18 | # ``` 19 | # SKIP=RuboCop git commit 20 | # SKIP=PuppetLint git commit 21 | # SKIP=RakeTask git push 22 | # ``` 23 | # 24 | # Don't invoke overcommit at all: 25 | # 26 | # ``` 27 | # OVERCOMMIT_DISABLE=1 git commit 28 | # ``` 29 | # 30 | # Read more about overcommit: https://github.com/brigade/overcommit 31 | # 32 | # To manage this config yourself in your module add 33 | # 34 | # ``` 35 | # .overcommit.yml: 36 | # unmanaged: true 37 | # ``` 38 | # 39 | # to your modules .sync.yml config 40 | --- 41 | PreCommit: 42 | RuboCop: 43 | enabled: true 44 | description: 'Runs rubocop on modified files only' 45 | command: ['bundle', 'exec', 'rubocop'] 46 | RakeTarget: 47 | enabled: true 48 | description: 'Runs lint on modified files only' 49 | targets: 50 | - 'lint' 51 | command: ['bundle', 'exec', 'rake'] 52 | YamlSyntax: 53 | enabled: true 54 | JsonSyntax: 55 | enabled: true 56 | TrailingWhitespace: 57 | enabled: true 58 | 59 | PrePush: 60 | RakeTarget: 61 | enabled: true 62 | description: 'Run rake targets' 63 | targets: 64 | - 'validate' 65 | - 'test' 66 | - 'rubocop' 67 | command: ['bundle', 'exec', 'rake'] 68 | -------------------------------------------------------------------------------- /metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "puppet-augeasproviders_syslog", 3 | "version": "3.0.1-rc0", 4 | "author": "Vox Pupuli", 5 | "summary": "Augeas-based syslog type and providers for Puppet", 6 | "license": "Apache-2.0", 7 | "source": "https://github.com/voxpupuli/puppet-augeasproviders_syslog", 8 | "project_page": "https://github.com/voxpupuli/puppet-augeasproviders_syslog", 9 | "issues_url": "https://github.com/voxpupuli/puppet-augeasproviders_syslog/issues", 10 | "description": "This module provides type/providers for syslog using the Augeas configuration API library.", 11 | "dependencies": [ 12 | { 13 | "name": "puppet/augeasproviders_core", 14 | "version_requirement": ">=2.4.0 <5.0.0" 15 | } 16 | ], 17 | "operatingsystem_support": [ 18 | { 19 | "operatingsystem": "Debian", 20 | "operatingsystemrelease": [ 21 | "7", 22 | "8", 23 | "9" 24 | ] 25 | }, 26 | { 27 | "operatingsystem": "Ubuntu", 28 | "operatingsystemrelease": [ 29 | "14.04", 30 | "16.04", 31 | "18.04", 32 | "18.10" 33 | ] 34 | }, 35 | { 36 | "operatingsystem": "RedHat", 37 | "operatingsystemrelease": [ 38 | "6", 39 | "7" 40 | ] 41 | }, 42 | { 43 | "operatingsystem": "CentOS", 44 | "operatingsystemrelease": [ 45 | "6", 46 | "7" 47 | ] 48 | }, 49 | { 50 | "operatingsystem": "OracleLinux", 51 | "operatingsystemrelease": [ 52 | "6", 53 | "7" 54 | ] 55 | } 56 | ], 57 | "requirements": [ 58 | { 59 | "name": "openvox", 60 | "version_requirement": ">= 8.19.0 < 9.0.0" 61 | } 62 | ] 63 | } 64 | -------------------------------------------------------------------------------- /lib/puppet/type/syslog.rb: -------------------------------------------------------------------------------- 1 | # Manages settings in syslog.conf file 2 | # 3 | # Copyright (c) 2012 Raphaël Pinson 4 | # Licensed under the Apache License, Version 2.0 5 | 6 | Puppet::Type.newtype(:syslog) do 7 | @doc = 'Manages settings in syslog.conf.' 8 | 9 | ensurable 10 | 11 | def munge_boolean(value) 12 | case value 13 | when true, 'true', :true 14 | :true 15 | when false, 'false', :false 16 | :false 17 | else 18 | raise('munge_boolean only takes booleans') 19 | end 20 | end 21 | 22 | newparam(:name) do 23 | desc 'The name of the resource.' 24 | isnamevar 25 | end 26 | 27 | newparam(:facility) do 28 | desc 'The syslog facility for the selector.' 29 | end 30 | 31 | newparam(:level) do 32 | desc 'The syslog level for the selector.' 33 | end 34 | 35 | newparam(:action_type) do 36 | desc 'The type of action: file, hostname, user or program.' 37 | end 38 | 39 | newparam(:action_protocol) do 40 | desc 'When action is hostname, the optional protocol.' 41 | newvalues :udp, :tcp, :'@', :'@@' 42 | 43 | munge do |value| 44 | case value 45 | when :udp, 'udp', :'@', '@' 46 | '@' 47 | when :tcp, 'tcp', :'@@', '@@' 48 | '@@' 49 | end 50 | end 51 | end 52 | 53 | newparam(:action_port) do 54 | desc 'When action is hostname, the optional port.' 55 | end 56 | 57 | newparam(:action) do 58 | desc 'The action for the entry.' 59 | end 60 | 61 | newproperty(:no_sync, boolean: true) do 62 | desc 'Whether to omit syncing the file after every logging, ony when action_type is file.' 63 | 64 | newvalue(:true) 65 | newvalue(:false) 66 | 67 | munge do |value| 68 | @resource.munge_boolean(value) 69 | end 70 | end 71 | 72 | newparam(:target) do 73 | desc "The file in which to store the settings, defaults to 74 | `/etc/syslog.conf`." 75 | end 76 | 77 | newparam(:lens) do 78 | desc 'The augeas lens used to parse the file' 79 | end 80 | 81 | autorequire(:file) do 82 | self[:target] 83 | end 84 | end 85 | -------------------------------------------------------------------------------- /.rubocop_todo.yml: -------------------------------------------------------------------------------- 1 | # This configuration was generated by 2 | # `rubocop --auto-gen-config` 3 | # on 2023-08-17 21:31:39 UTC using RuboCop version 1.50.2. 4 | # The point is for the user to remove these configuration records 5 | # one by one as the offenses are removed from the code base. 6 | # Note that changes in the inspected code, or installation of new 7 | # versions of RuboCop, may require this file to be generated again. 8 | 9 | # Offense count: 2 10 | # Configuration parameters: IgnoreLiteralBranches, IgnoreConstantBranches. 11 | Lint/DuplicateBranch: 12 | Exclude: 13 | - 'lib/puppet/provider/rsyslog_filter/augeas.rb' 14 | - 'lib/puppet/provider/syslog/augeas.rb' 15 | 16 | # Offense count: 18 17 | # This cop supports unsafe autocorrection (--autocorrect-all). 18 | RSpec/BeEq: 19 | Exclude: 20 | - 'spec/unit/puppet/provider/rsyslog_filter/augeas_spec.rb' 21 | - 'spec/unit/puppet/provider/syslog/augeas_spec.rb' 22 | - 'spec/unit/puppet/provider/syslog/rsyslog_spec.rb' 23 | 24 | # Offense count: 18 25 | # Configuration parameters: AssignmentOnly. 26 | RSpec/InstanceVariable: 27 | Exclude: 28 | - 'spec/unit/puppet/provider/rsyslog_filter/augeas_spec.rb' 29 | - 'spec/unit/puppet/provider/syslog/augeas_spec.rb' 30 | - 'spec/unit/puppet/provider/syslog/rsyslog_spec.rb' 31 | 32 | # Offense count: 3 33 | # This cop supports unsafe autocorrection (--autocorrect-all). 34 | # Configuration parameters: EnforcedStyle. 35 | # SupportedStyles: always, conditionals 36 | Style/AndOr: 37 | Exclude: 38 | - 'lib/puppet/provider/rsyslog_filter/augeas.rb' 39 | - 'lib/puppet/provider/syslog/augeas.rb' 40 | 41 | # Offense count: 5 42 | # Configuration parameters: AllowedChars. 43 | # AllowedChars: © 44 | Style/AsciiComments: 45 | Exclude: 46 | - 'lib/puppet/provider/rsyslog_filter/augeas.rb' 47 | - 'lib/puppet/provider/syslog/augeas.rb' 48 | - 'lib/puppet/provider/syslog/rsyslog.rb' 49 | - 'lib/puppet/type/rsyslog_filter.rb' 50 | - 'lib/puppet/type/syslog.rb' 51 | 52 | # Offense count: 8 53 | # This cop supports unsafe autocorrection (--autocorrect-all). 54 | # Configuration parameters: EnforcedStyle. 55 | # SupportedStyles: always, always_true, never 56 | Style/FrozenStringLiteralComment: 57 | Exclude: 58 | - 'lib/puppet/provider/rsyslog_filter/augeas.rb' 59 | - 'lib/puppet/provider/syslog/augeas.rb' 60 | - 'lib/puppet/provider/syslog/rsyslog.rb' 61 | - 'lib/puppet/type/rsyslog_filter.rb' 62 | - 'lib/puppet/type/syslog.rb' 63 | - 'spec/unit/puppet/provider/rsyslog_filter/augeas_spec.rb' 64 | - 'spec/unit/puppet/provider/syslog/augeas_spec.rb' 65 | - 'spec/unit/puppet/provider/syslog/rsyslog_spec.rb' 66 | 67 | # Offense count: 2 68 | # This cop supports unsafe autocorrection (--autocorrect-all). 69 | Style/RedundantInterpolation: 70 | Exclude: 71 | - 'lib/puppet/provider/rsyslog_filter/augeas.rb' 72 | - 'lib/puppet/provider/syslog/augeas.rb' 73 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/syslog/rsyslog/full: -------------------------------------------------------------------------------- 1 | # rsyslog v5 configuration file 2 | 3 | # For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html 4 | # If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html 5 | 6 | #### MODULES #### 7 | 8 | $ModLoad imuxsock # provides support for local system logging (e.g. via logger command) 9 | $ModLoad imklog # provides kernel logging support (previously done by rklogd) 10 | #$ModLoad immark # provides --MARK-- message capability 11 | 12 | # Provides UDP syslog reception 13 | #$ModLoad imudp 14 | #$UDPServerRun 514 15 | 16 | # Provides TCP syslog reception 17 | #$ModLoad imtcp 18 | #$InputTCPServerRun 514 19 | 20 | 21 | #### GLOBAL DIRECTIVES #### 22 | 23 | # Use default timestamp format 24 | $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat 25 | 26 | # File syncing capability is disabled by default. This feature is usually not required, 27 | # not useful and an extreme performance hit 28 | #$ActionFileEnableSync on 29 | 30 | # Include all config files in /etc/rsyslog.d/ 31 | $IncludeConfig /etc/rsyslog.d/*.conf 32 | 33 | 34 | #### RULES #### 35 | 36 | # Log all kernel messages to the console. 37 | # Logging much else clutters up the screen. 38 | #kern.* /dev/console 39 | 40 | # Log anything (except mail) of level info or higher. 41 | # Don't log private authentication messages! 42 | *.info;mail.none;authpriv.none;cron.none /var/log/messages 43 | 44 | # The authpriv file has restricted access. 45 | authpriv.* /var/log/secure 46 | 47 | # Log all the mail messages in one place. 48 | mail.* -/var/log/maillog 49 | 50 | 51 | # Log cron stuff 52 | cron.* /var/log/cron 53 | 54 | # Everybody gets emergency messages 55 | #*.emerg :omusrmsg:* 56 | 57 | # Save news errors of level crit and higher in a special file. 58 | uucp,news.crit /var/log/spooler 59 | 60 | # Save boot messages also to boot.log 61 | local7.* /var/log/boot.log 62 | 63 | 64 | # ### begin forwarding rule ### 65 | # The statement between the begin ... end define a SINGLE forwarding 66 | # rule. They belong together, do NOT split them. If you create multiple 67 | # forwarding rules, duplicate the whole block! 68 | # Remote Logging (we use TCP for reliable delivery) 69 | # 70 | # An on-disk queue is created for this action. If the remote host is 71 | # down, messages are spooled to disk and sent when it is up again. 72 | #$WorkDirectory /var/lib/rsyslog # where to place spool files 73 | #$ActionQueueFileName fwdRule1 # unique name prefix for spool files 74 | #$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) 75 | #$ActionQueueSaveOnShutdown on # save messages to disk on shutdown 76 | #$ActionQueueType LinkedList # run asynchronously 77 | #$ActionResumeRetryCount -1 # infinite retries if host is down 78 | # remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional 79 | #*.* @@remote-host:514 80 | # ### end of the forwarding rule ### 81 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/syslog/rsyslog/broken: -------------------------------------------------------------------------------- 1 | ;broken 2 | 3 | # rsyslog v5 configuration file 4 | 5 | # For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html 6 | # If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html 7 | 8 | #### MODULES #### 9 | 10 | $ModLoad imuxsock # provides support for local system logging (e.g. via logger command) 11 | $ModLoad imklog # provides kernel logging support (previously done by rklogd) 12 | #$ModLoad immark # provides --MARK-- message capability 13 | 14 | # Provides UDP syslog reception 15 | #$ModLoad imudp 16 | #$UDPServerRun 514 17 | 18 | # Provides TCP syslog reception 19 | #$ModLoad imtcp 20 | #$InputTCPServerRun 514 21 | 22 | 23 | #### GLOBAL DIRECTIVES #### 24 | 25 | # Use default timestamp format 26 | $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat 27 | 28 | # File syncing capability is disabled by default. This feature is usually not required, 29 | # not useful and an extreme performance hit 30 | #$ActionFileEnableSync on 31 | 32 | # Include all config files in /etc/rsyslog.d/ 33 | $IncludeConfig /etc/rsyslog.d/*.conf 34 | 35 | 36 | #### RULES #### 37 | 38 | # Log all kernel messages to the console. 39 | # Logging much else clutters up the screen. 40 | #kern.* /dev/console 41 | 42 | # Log anything (except mail) of level info or higher. 43 | # Don't log private authentication messages! 44 | *.info;mail.none;authpriv.none;cron.none /var/log/messages 45 | 46 | # The authpriv file has restricted access. 47 | authpriv.* /var/log/secure 48 | 49 | # Log all the mail messages in one place. 50 | mail.* -/var/log/maillog 51 | 52 | 53 | # Log cron stuff 54 | cron.* /var/log/cron 55 | 56 | # Everybody gets emergency messages 57 | *.emerg :omusrmsg:* 58 | 59 | # Save news errors of level crit and higher in a special file. 60 | uucp,news.crit /var/log/spooler 61 | 62 | # Save boot messages also to boot.log 63 | local7.* /var/log/boot.log 64 | 65 | 66 | # ### begin forwarding rule ### 67 | # The statement between the begin ... end define a SINGLE forwarding 68 | # rule. They belong together, do NOT split them. If you create multiple 69 | # forwarding rules, duplicate the whole block! 70 | # Remote Logging (we use TCP for reliable delivery) 71 | # 72 | # An on-disk queue is created for this action. If the remote host is 73 | # down, messages are spooled to disk and sent when it is up again. 74 | #$WorkDirectory /var/lib/rsyslog # where to place spool files 75 | #$ActionQueueFileName fwdRule1 # unique name prefix for spool files 76 | #$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) 77 | #$ActionQueueSaveOnShutdown on # save messages to disk on shutdown 78 | #$ActionQueueType LinkedList # run asynchronously 79 | #$ActionResumeRetryCount -1 # infinite retries if host is down 80 | # remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional 81 | #*.* @@remote-host:514 82 | # ### end of the forwarding rule ### 83 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/rsyslog_filter/augeas/broken: -------------------------------------------------------------------------------- 1 | ;broken 2 | 3 | # rsyslog v5 configuration file 4 | 5 | # For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html 6 | # If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html 7 | 8 | #### MODULES #### 9 | 10 | $ModLoad imuxsock # provides support for local system logging (e.g. via logger command) 11 | $ModLoad imklog # provides kernel logging support (previously done by rklogd) 12 | #$ModLoad immark # provides --MARK-- message capability 13 | 14 | # Provides UDP syslog reception 15 | #$ModLoad imudp 16 | #$UDPServerRun 514 17 | 18 | # Provides TCP syslog reception 19 | #$ModLoad imtcp 20 | #$InputTCPServerRun 514 21 | 22 | 23 | #### GLOBAL DIRECTIVES #### 24 | 25 | # Use default timestamp format 26 | $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat 27 | 28 | # File syncing capability is disabled by default. This feature is usually not required, 29 | # not useful and an extreme performance hit 30 | #$ActionFileEnableSync on 31 | 32 | # Include all config files in /etc/rsyslog.d/ 33 | $IncludeConfig /etc/rsyslog.d/*.conf 34 | 35 | 36 | #### RULES #### 37 | 38 | # Log all kernel messages to the console. 39 | # Logging much else clutters up the screen. 40 | #kern.* /dev/console 41 | 42 | # Log anything (except mail) of level info or higher. 43 | # Don't log private authentication messages! 44 | *.info;mail.none;authpriv.none;cron.none /var/log/messages 45 | 46 | # The authpriv file has restricted access. 47 | authpriv.* /var/log/secure 48 | 49 | # Log all the mail messages in one place. 50 | mail.* -/var/log/maillog 51 | 52 | 53 | # Log cron stuff 54 | cron.* /var/log/cron 55 | 56 | # Everybody gets emergency messages 57 | *.emerg :omusrmsg:* 58 | 59 | # Save news errors of level crit and higher in a special file. 60 | uucp,news.crit /var/log/spooler 61 | 62 | # Save boot messages also to boot.log 63 | local7.* /var/log/boot.log 64 | 65 | 66 | # ### begin forwarding rule ### 67 | # The statement between the begin ... end define a SINGLE forwarding 68 | # rule. They belong together, do NOT split them. If you create multiple 69 | # forwarding rules, duplicate the whole block! 70 | # Remote Logging (we use TCP for reliable delivery) 71 | # 72 | # An on-disk queue is created for this action. If the remote host is 73 | # down, messages are spooled to disk and sent when it is up again. 74 | #$WorkDirectory /var/lib/rsyslog # where to place spool files 75 | #$ActionQueueFileName fwdRule1 # unique name prefix for spool files 76 | #$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) 77 | #$ActionQueueSaveOnShutdown on # save messages to disk on shutdown 78 | #$ActionQueueType LinkedList # run asynchronously 79 | #$ActionResumeRetryCount -1 # infinite retries if host is down 80 | # remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional 81 | #*.* @@remote-host:514 82 | # ### end of the forwarding rule ### 83 | -------------------------------------------------------------------------------- /spec/fixtures/unit/puppet/provider/rsyslog_filter/augeas/full: -------------------------------------------------------------------------------- 1 | # rsyslog v5 configuration file 2 | 3 | # For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html 4 | # If you experience problems, see http://www.rsyslog.com/doc/troubleshoot.html 5 | 6 | #### MODULES #### 7 | 8 | $ModLoad imuxsock # provides support for local system logging (e.g. via logger command) 9 | $ModLoad imklog # provides kernel logging support (previously done by rklogd) 10 | #$ModLoad immark # provides --MARK-- message capability 11 | 12 | # Provides UDP syslog reception 13 | #$ModLoad imudp 14 | #$UDPServerRun 514 15 | 16 | # Provides TCP syslog reception 17 | #$ModLoad imtcp 18 | #$InputTCPServerRun 514 19 | 20 | 21 | #### GLOBAL DIRECTIVES #### 22 | 23 | # Use default timestamp format 24 | $ActionFileDefaultTemplate RSYSLOG_TraditionalFileFormat 25 | 26 | # File syncing capability is disabled by default. This feature is usually not required, 27 | # not useful and an extreme performance hit 28 | #$ActionFileEnableSync on 29 | 30 | # Include all config files in /etc/rsyslog.d/ 31 | $IncludeConfig /etc/rsyslog.d/*.conf 32 | 33 | 34 | #### RULES #### 35 | 36 | # Log all kernel messages to the console. 37 | # Logging much else clutters up the screen. 38 | #kern.* /dev/console 39 | 40 | # Log anything (except mail) of level info or higher. 41 | # Don't log private authentication messages! 42 | *.info;mail.none;authpriv.none;cron.none /var/log/messages 43 | 44 | # The authpriv file has restricted access. 45 | authpriv.* /var/log/secure 46 | 47 | # Log all the mail messages in one place. 48 | mail.* -/var/log/maillog 49 | 50 | 51 | # Log cron stuff 52 | cron.* /var/log/cron 53 | 54 | # Everybody gets emergency messages 55 | #*.emerg :omusrmsg:* 56 | 57 | # Save news errors of level crit and higher in a special file. 58 | uucp,news.crit /var/log/spooler 59 | 60 | # Save boot messages also to boot.log 61 | local7.* /var/log/boot.log 62 | 63 | :msg,contains,"sshd" @@logserver.dev:514 64 | 65 | # ### begin forwarding rule ### 66 | # The statement between the begin ... end define a SINGLE forwarding 67 | # rule. They belong together, do NOT split them. If you create multiple 68 | # forwarding rules, duplicate the whole block! 69 | # Remote Logging (we use TCP for reliable delivery) 70 | # 71 | # An on-disk queue is created for this action. If the remote host is 72 | # down, messages are spooled to disk and sent when it is up again. 73 | #$WorkDirectory /var/lib/rsyslog # where to place spool files 74 | #$ActionQueueFileName fwdRule1 # unique name prefix for spool files 75 | #$ActionQueueMaxDiskSpace 1g # 1gb space limit (use as much as possible) 76 | #$ActionQueueSaveOnShutdown on # save messages to disk on shutdown 77 | #$ActionQueueType LinkedList # run asynchronously 78 | #$ActionResumeRetryCount -1 # infinite retries if host is down 79 | # remote host is: name/ip:port, e.g. 192.168.0.1:514, port optional 80 | #*.* @@remote-host:514 81 | # ### end of the forwarding rule ### 82 | -------------------------------------------------------------------------------- /lib/puppet/provider/rsyslog_filter/augeas.rb: -------------------------------------------------------------------------------- 1 | # Alternative Augeas-based providers for Puppet 2 | # 3 | # Copyright (c) 2019 Raphaël Pinson 4 | # Licensed under the Apache License, Version 2.0 5 | 6 | raise('Missing augeasproviders_core dependency') if Puppet::Type.type(:augeasprovider).nil? 7 | 8 | Puppet::Type.type(:rsyslog_filter).provide(:augeas, parent: Puppet::Type.type(:augeasprovider).provider(:default)) do 9 | desc 'Uses Augeas API to update an rsyslog.conf filter entry' 10 | 11 | default_file { '/etc/rsyslog.conf' } 12 | 13 | lens do |resource| 14 | if resource and resource[:lens] 15 | resource[:lens] 16 | else 17 | 'Rsyslog.lns' 18 | end 19 | end 20 | 21 | confine feature: :augeas 22 | 23 | resource_path do |resource| 24 | property = resource[:property] 25 | operation = resource[:operation] 26 | value = resource[:value] 27 | action_type = resource[:action_type] 28 | action = resource[:action] 29 | "$target/filter[property='#{property}' and operation='#{operation}' and value='#{value}' and action/#{action_type}='#{action}']" 30 | end 31 | 32 | def protocol_supported 33 | return @protocol_supported unless @protocol_supported.nil? 34 | 35 | @protocol_supported = if Puppet::Util::Package.versioncmp(aug_version, '1.2.0') >= 0 36 | :stock 37 | elsif parsed_as?("*.* @syslog.far.away:123\n", 'entry/action/protocol') 38 | :stock 39 | elsif parsed_as?("*.* @@syslog.far.away:123\n", 'entry/action/protocol') 40 | :el7 41 | else 42 | false 43 | end 44 | end 45 | 46 | def self.instances 47 | augopen do |aug| 48 | resources = [] 49 | 50 | aug.match('$target/filter').each do |apath| 51 | property = aug.get("#{apath}/property") 52 | operation = aug.get("#{apath}/operation") 53 | value = aug.get("#{apath}/value") 54 | action_type = path_label(aug, "#{apath}/action/*[label() != 'protocol' and label() != 'port']") 55 | action_port = aug.get("#{apath}/action/port") 56 | action_protocol = aug.get("#{apath}/action/protocol") 57 | action = aug.get("#{apath}/action/#{action_type}") 58 | name = "#{property} #{operation} #{value}" 59 | name += action_protocol if action_type == 'hostname' 60 | name += "#{action}" 61 | entry = { ensure: :present, name: name, 62 | property: property, operation: operation, value: value, 63 | action_type: action_type, 64 | action_port: action_port, 65 | action_protocol: action_protocol, 66 | action: action } 67 | resources << new(entry) 68 | end 69 | 70 | resources 71 | end 72 | end 73 | 74 | def create 75 | property = resource[:property] 76 | operation = resource[:operation] 77 | value = resource[:value] 78 | action_type = resource[:action_type] 79 | action_port = resource[:action_port] 80 | action_protocol = resource[:action_protocol] 81 | action = resource[:action] 82 | 83 | augopen! do |aug| 84 | # TODO: make it case-insensitive 85 | aug.defnode('resource', resource_path, nil) 86 | aug.set('$resource/property', property) 87 | aug.set('$resource/operation', operation) 88 | aug.set('$resource/value', value) 89 | if action_protocol 90 | case protocol_supported 91 | when :stock 92 | aug.set('$resource/action/protocol', action_protocol) 93 | when :el7 94 | aug.set('$resource/action/protocol', action_protocol) if action_protocol == '@@' 95 | else 96 | raise(Puppet::Error, 'Protocol is not supported in this lens') 97 | end 98 | end 99 | aug.set("$resource/action/#{action_type}", action) 100 | aug.set('$resource/action/port', action_port) if action_port 101 | end 102 | end 103 | end 104 | -------------------------------------------------------------------------------- /lib/puppet/provider/syslog/augeas.rb: -------------------------------------------------------------------------------- 1 | # Alternative Augeas-based providers for Puppet 2 | # 3 | # Copyright (c) 2012 Raphaël Pinson 4 | # Licensed under the Apache License, Version 2.0 5 | 6 | raise('Missing augeasproviders_core dependency') if Puppet::Type.type(:augeasprovider).nil? 7 | 8 | Puppet::Type.type(:syslog).provide(:augeas, parent: Puppet::Type.type(:augeasprovider).provider(:default)) do 9 | desc 'Uses Augeas API to update a syslog.conf entry' 10 | 11 | default_file { '/etc/syslog.conf' } 12 | 13 | lens do |resource| 14 | if resource and resource[:lens] 15 | resource[:lens] 16 | else 17 | 'Syslog.lns' 18 | end 19 | end 20 | 21 | confine feature: :augeas 22 | 23 | resource_path do |resource| 24 | entry_path(resource) 25 | end 26 | 27 | def protocol_supported 28 | return @protocol_supported unless @protocol_supported.nil? 29 | 30 | @protocol_supported = if Puppet::Util::Package.versioncmp(aug_version, '1.2.0') >= 0 31 | :stock 32 | elsif parsed_as?("*.* @syslog.far.away:123\n", 'entry/action/protocol') 33 | :stock 34 | elsif parsed_as?("*.* @@syslog.far.away:123\n", 'entry/action/protocol') 35 | :el7 36 | else 37 | false 38 | end 39 | end 40 | 41 | # We need to define an entry_path method 42 | # so the rsyslog provider can use it 43 | def self.entry_path(resource) 44 | facility = resource[:facility] 45 | level = resource[:level] 46 | action_type = resource[:action_type] 47 | action = resource[:action] 48 | 49 | # TODO: make it case-insensitive 50 | "$target/entry[selector/facility='#{facility}' and selector/level='#{level}' and action/#{action_type}='#{action}']" 51 | end 52 | 53 | def self.instances 54 | augopen do |aug| 55 | resources = [] 56 | 57 | aug.match('$target/entry').each do |apath| 58 | aug.match("#{apath}/selector").each do |snode| 59 | aug.match("#{snode}/facility").each do |fnode| 60 | facility = aug.get(fnode) 61 | level = aug.get("#{snode}/level") 62 | no_sync = aug.match("#{apath}/action/no_sync").empty? ? :false : :true 63 | action_type_node = aug.match("#{apath}/action/*[label() != 'no_sync']") 64 | action_type = path_label(aug, action_type_node[0]) 65 | action_port = aug.get("#{apath}/action/port") 66 | action_protocol = aug.get("#{apath}/action/protocol") 67 | action = aug.get("#{apath}/action/#{action_type}") 68 | name = "#{facility}.#{level} " 69 | name += '-' if no_sync == :true 70 | name += action_protocol if action_type == 'hostname' 71 | name += "#{action}" 72 | entry = { ensure: :present, name: name, 73 | facility: facility, level: level, 74 | no_sync: no_sync, 75 | action_type: action_type, 76 | action_port: action_port, 77 | action_protocol: action_protocol, 78 | action: action } 79 | resources << new(entry) 80 | end 81 | end 82 | end 83 | 84 | resources 85 | end 86 | end 87 | 88 | def create 89 | facility = resource[:facility] 90 | level = resource[:level] 91 | no_sync = resource[:no_sync] 92 | action_type = resource[:action_type] 93 | action_port = resource[:action_port] 94 | action_protocol = resource[:action_protocol] 95 | action = resource[:action] 96 | augopen! do |aug| 97 | # TODO: make it case-insensitive 98 | aug.defnode('resource', resource_path, nil) 99 | aug.set('$resource/selector/facility', facility) 100 | aug.set('$resource/selector/level', level) 101 | aug.clear('$resource/action/no_sync') if no_sync == :true and action_type == 'file' 102 | if action_protocol 103 | case protocol_supported 104 | when :stock 105 | aug.set('$resource/action/protocol', action_protocol) 106 | when :el7 107 | aug.set('$resource/action/protocol', action_protocol) if action_protocol == '@@' 108 | else 109 | raise(Puppet::Error, 'Protocol is not supported in this lens') 110 | end 111 | end 112 | aug.set("$resource/action/#{action_type}", action) 113 | aug.set('$resource/action/port', action_port) if action_port 114 | end 115 | end 116 | 117 | def no_sync 118 | augopen do |aug| 119 | if aug.match('$resource/action/no_sync').empty? 120 | :false 121 | else 122 | :true 123 | end 124 | end 125 | end 126 | 127 | def no_sync=(no_sync) 128 | augopen! do |aug| 129 | if no_sync == :true 130 | if aug.match('$resource/action/no_sync').empty? 131 | # Insert a no_sync node before the action/file node 132 | aug.insert('$resource/action/file', 'no_sync', true) 133 | end 134 | else 135 | # Remove the no_sync tag 136 | aug.rm('$resource/action/no_sync') 137 | end 138 | end 139 | end 140 | end 141 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # syslog: types/providers for syslog files for Puppet 2 | 3 | [![License](https://img.shields.io/github/license/voxpupuli/puppet-augeasproviders_syslog.svg)](https://github.com/voxpupuli/puppet-augeasproviders_syslog/blob/master/LICENSE) 4 | [![Puppet Forge Version](http://img.shields.io/puppetforge/v/puppet/augeasproviders_syslog.svg)](https://forge.puppetlabs.com/puppet/augeasproviders_syslog) 5 | [![Puppet Forge Downloads](http://img.shields.io/puppetforge/dt/puppet/augeasproviders_syslog.svg)](https://forge.puppetlabs.com/puppet/augeasproviders_syslog) 6 | [![Build Status](https://github.com/voxpupuli/puppet-augeasproviders_syslog/workflows/CI/badge.svg)](https://github.com/voxpupuli/puppet-augeasproviders_syslog/actions?query=workflow%3ACI) 7 | [![Donated by Herculesteam](https://img.shields.io/badge/donated%20by-herculesteam-fb7047.svg)](#transfer-notice) 8 | 9 | # Features 10 | 11 | This module provides new types/providers for Puppet to read and modify syslog 12 | config files using the Augeas configuration library. 13 | 14 | The advantage of using Augeas over the default Puppet `parsedfile` 15 | implementations is that Augeas will go to great lengths to preserve file 16 | formatting and comments, while also failing safely when needed. 17 | 18 | This provider will hide *all* of the Augeas commands etc., you don't need to 19 | know anything about Augeas to make use of it. 20 | 21 | ## Requirements 22 | 23 | Ensure both Augeas and ruby-augeas 0.3.0+ bindings are installed and working as 24 | normal. 25 | 26 | See [Puppet/Augeas pre-requisites](http://docs.puppetlabs.com/guides/augeas.html#pre-requisites). 27 | 28 | ## Installing 29 | 30 | On Puppet 2.7.14+, the module can be installed easily ([documentation](http://docs.puppetlabs.com/puppet/latest/reference/modules_installing.html)): 31 | 32 | puppet module install herculesteam/augeasproviders_syslog 33 | 34 | You may see an error similar to this on Puppet 2.x ([#13858](http://projects.puppetlabs.com/issues/13858)): 35 | 36 | Error 400 on SERVER: Puppet::Parser::AST::Resource failed with error ArgumentError: Invalid resource type `syslog` at ... 37 | 38 | Ensure the module is present in your puppetmaster's own environment (it doesn't 39 | have to use it) and that the master has pluginsync enabled. Run the agent on 40 | the puppetmaster to cause the custom types to be synced to its local libdir 41 | (`puppet master --configprint libdir`) and then restart the puppetmaster so it 42 | loads them. 43 | 44 | ## Compatibility 45 | 46 | ### Puppet versions 47 | 48 | Minimum of Puppet 2.7. 49 | 50 | ### Augeas versions 51 | 52 | Augeas Versions | 0.10.0 | 1.0.0 | 1.1.0 | 1.2.0 | 53 | :-------------------------|:-------:|:-------:|:-------:|:-------:| 54 | **PROVIDERS** | 55 | syslog (augeas) | **yes** | **yes** | **yes** | **yes** | 56 | syslog (rsyslog) | no | **yes** | **yes** | **yes** | 57 | rsyslog\_filter (augeas) | no | **yes** | **yes** | **yes** | 58 | 59 | ## Documentation and examples 60 | 61 | Type documentation can be generated with `puppet doc -r type` or viewed on the 62 | [Puppet Forge page](http://forge.puppetlabs.com/voxpupuli/augeasproviders_syslog). 63 | 64 | A `syslog` provider handles basic syslog configs, while an `rsyslog` provider 65 | handles the extended rsyslog config (this requires Augeas 1.0.0). 66 | 67 | ### manage entry 68 | 69 | syslog { "my test": 70 | ensure => present, 71 | facility => "local2", 72 | level => "*", 73 | action_type => "file", 74 | action => "/var/log/test.log", 75 | } 76 | 77 | ### manage entry with no file sync 78 | 79 | syslog { "cron.*": 80 | ensure => present, 81 | facility => "cron", 82 | level => "*", 83 | action_type => "file", 84 | action => "/var/log/cron", 85 | no_sync => true, 86 | } 87 | 88 | ### manage remote hostname entry 89 | 90 | syslog { "my test": 91 | ensure => present, 92 | facility => "local2", 93 | level => "*", 94 | action_type => "hostname", 95 | action => "centralserver", 96 | } 97 | 98 | ### manage remote hostname entry with port and protocol 99 | 100 | syslog { "my test": 101 | ensure => present, 102 | facility => "local2", 103 | level => "*", 104 | action_type => "hostname", 105 | action_port => "514", 106 | action_protocol => "tcp", 107 | action => "centralserver", 108 | } 109 | 110 | ### manage user destination entry 111 | 112 | syslog { "my test": 113 | ensure => present, 114 | facility => "local2", 115 | level => "*", 116 | action_type => "user", 117 | action => "root", 118 | } 119 | 120 | ### manage program entry 121 | 122 | syslog { "my test": 123 | ensure => present, 124 | facility => "local2", 125 | level => "*", 126 | action_type => "program", 127 | action => "/usr/bin/foo", 128 | } 129 | 130 | ### delete entry 131 | 132 | syslog { "mail.*": 133 | ensure => absent, 134 | facility => "mail", 135 | level => "*", 136 | action_type => "file", 137 | action => "/var/log/maillog", 138 | } 139 | 140 | ### manage entry in rsyslog 141 | 142 | syslog { "my test": 143 | ensure => present, 144 | facility => "local2", 145 | level => "*", 146 | action_type => "file", 147 | action => "/var/log/test.log", 148 | provider => "rsyslog", 149 | } 150 | 151 | ### manage entry in another syslog location 152 | 153 | syslog { "my test": 154 | ensure => present, 155 | facility => "local2", 156 | level => "*", 157 | action_type => "file", 158 | action => "/var/log/test.log", 159 | target => "/etc/mysyslog.conf", 160 | } 161 | 162 | ## Issues 163 | 164 | Please file any issues or suggestions [on GitHub](https://github.com/voxpupuli/augeasproviders_syslog/issues). 165 | 166 | ## Supported OS 167 | 168 | See [metadata.json](metadata.json) for supported OS versions. 169 | 170 | ## Dependencies 171 | 172 | See [metadata.json](metadata.json) for dependencies. 173 | 174 | ## Puppet 175 | 176 | The supported Puppet versions are listed in the [metadata.json](metadata.json) 177 | 178 | ## REFERENCES 179 | 180 | Please see [REFERENCE.md](https://github.com/voxpupuli/puppet-augeasproviders_syslog/blob/master/REFERENCE.md) for more details. 181 | 182 | ## Contributing 183 | 184 | Please report bugs and feature request using [GitHub issue 185 | tracker](https://github.com/voxpupuli/puppet-augeasproviders_syslog/issues). 186 | 187 | For pull requests, it is very much appreciated to check your Puppet manifest 188 | with [puppet-lint](https://github.com/puppetlabs/puppet-lint/) to follow the recommended Puppet style guidelines from the 189 | [Puppet Labs style guide](https://www.puppet.com/docs/puppet/latest/style_guide.html). 190 | 191 | ## Transfer Notice 192 | 193 | This plugin was originally authored by [Hercules Team](https://github.com/hercules-team). 194 | The maintainer preferred that Puppet Community take ownership of the module for future improvement and maintenance. 195 | Existing pull requests and issues were transferred over, please fork and continue to contribute here instead of Hercules Team. 196 | -------------------------------------------------------------------------------- /spec/unit/puppet/provider/rsyslog_filter/augeas_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | provider_class = Puppet::Type.type(:rsyslog_filter).provider(:augeas) 3 | 4 | describe provider_class do 5 | let(:protocol_supported) { subject.protocol_supported } 6 | 7 | context 'with empty file' do 8 | let(:tmptarget) { aug_fixture('empty') } 9 | let(:target) { tmptarget.path } 10 | 11 | it 'creates new entry with file' do 12 | allow(FileTest).to receive(:exist?).and_return(false) 13 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 14 | allow(FileTest).to receive(:exist?).and_return(false) 15 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 16 | 17 | apply!(Puppet::Type.type(:rsyslog_filter).new( 18 | name: 'my test', 19 | property: 'msg', 20 | operation: 'contains', 21 | value: 'IPTables-Dropped: ', 22 | action_type: 'file', 23 | action: '/var/log/iptables.log', 24 | target: target, 25 | provider: 'augeas', 26 | ensure: 'present' 27 | )) 28 | 29 | aug_open(target, 'Rsyslog.lns') do |aug| 30 | expect(aug.match('filter').size).to eq(1) 31 | expect(aug.get('filter/value')).to eq('IPTables-Dropped: ') 32 | expect(aug.get('filter/action/file')).to eq('/var/log/iptables.log') 33 | end 34 | end 35 | 36 | it 'creates new entry with protocol/hostname/port' do 37 | allow(FileTest).to receive(:exist?).and_return(false) 38 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 39 | allow(FileTest).to receive(:exist?).and_return(false) 40 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 41 | 42 | apply!(Puppet::Type.type(:rsyslog_filter).new( 43 | name: 'my test', 44 | property: 'msg', 45 | operation: 'contains', 46 | value: 'IPTables-Dropped: ', 47 | action_type: 'hostname', 48 | action: 'logs.local', 49 | action_protocol: '@@', 50 | action_port: '514', 51 | target: target, 52 | provider: 'augeas', 53 | ensure: 'present' 54 | )) 55 | 56 | aug_open(target, 'Rsyslog.lns') do |aug| 57 | expect(aug.match('filter').size).to eq(1) 58 | expect(aug.get('filter/value')).to eq('IPTables-Dropped: ') 59 | expect(aug.get('filter/action/hostname')).to eq('logs.local') 60 | end 61 | end 62 | end 63 | 64 | context 'with full file' do 65 | let(:tmptarget) { aug_fixture('full') } 66 | let(:target) { tmptarget.path } 67 | 68 | it 'lists instances' do 69 | allow(FileTest).to receive(:exist?).and_return(false) 70 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 71 | allow(FileTest).to receive(:exist?).and_return(false) 72 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 73 | 74 | allow(provider_class).to receive(:target).and_return(target) 75 | inst = provider_class.instances.map do |p| 76 | { 77 | name: p.get(:name), 78 | ensure: p.get(:ensure), 79 | property: p.get(:property), 80 | operation: p.get(:operation), 81 | value: p.get(:value), 82 | action_type: p.get(:action_type), 83 | action_protocol: p.get(:action_protocol), 84 | action_port: p.get(:action_port), 85 | action: p.get(:action), 86 | } 87 | end 88 | 89 | expect(inst.size).to eq(1) 90 | expect(inst[0]).to eq({ 91 | ensure: :present, 92 | name: 'msg contains sshd@@logserver.dev', 93 | property: 'msg', 94 | operation: 'contains', 95 | value: 'sshd', 96 | action_type: 'hostname', 97 | action_protocol: '@@', 98 | action_port: '514', 99 | action: 'logserver.dev', 100 | }) 101 | end 102 | 103 | describe 'when creating settings' do 104 | it 'creates a simple new entry' do 105 | allow(FileTest).to receive(:exist?).and_return(false) 106 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 107 | allow(FileTest).to receive(:exist?).and_return(false) 108 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 109 | 110 | apply!(Puppet::Type.type(:rsyslog_filter).new( 111 | name: 'my test', 112 | property: 'msg', 113 | operation: 'contains', 114 | value: 'IPTables-Dropped: ', 115 | action_type: 'file', 116 | action: '/var/log/iptables.log', 117 | target: target, 118 | provider: 'augeas', 119 | ensure: 'present' 120 | )) 121 | 122 | aug_open(target, 'Rsyslog.lns') do |aug| 123 | expect(aug.get('filter/action/file')).to eq('/var/log/iptables.log') 124 | end 125 | end 126 | end 127 | 128 | describe 'when modifying settings' do 129 | it 'uses file' do 130 | allow(FileTest).to receive(:exist?).and_return(false) 131 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 132 | allow(FileTest).to receive(:exist?).and_return(false) 133 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 134 | 135 | apply!(Puppet::Type.type(:rsyslog_filter).new( 136 | name: 'ssh', 137 | property: 'msg', 138 | operation: 'contains', 139 | value: 'sshd', 140 | action_type: 'file', 141 | action: '/var/log/sshd.log', 142 | target: target, 143 | provider: 'augeas', 144 | ensure: 'present' 145 | )) 146 | 147 | aug_open(target, 'Rsyslog.lns') do |aug| 148 | expect(aug.get('filter/action/file')).to eq('/var/log/sshd.log') 149 | end 150 | end 151 | end 152 | 153 | describe 'when removing settings' do 154 | it 'removes the entry' do 155 | allow(FileTest).to receive(:exist?).and_return(false) 156 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 157 | allow(FileTest).to receive(:exist?).and_return(false) 158 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 159 | 160 | apply!(Puppet::Type.type(:rsyslog_filter).new( 161 | name: 'ssh', 162 | property: 'msg', 163 | operation: 'contains', 164 | value: 'sshd', 165 | action_type: 'file', 166 | action: '/var/log/sshd.log', 167 | target: target, 168 | provider: 'augeas', 169 | ensure: 'absent' 170 | )) 171 | 172 | aug_open(target, 'Syslog.lns') do |aug| 173 | expect(aug.match("entry[selector/facility='mail' and level='*']").size).to eq(0) 174 | end 175 | end 176 | end 177 | end 178 | 179 | context 'with broken file' do 180 | let(:tmptarget) { aug_fixture('broken') } 181 | let(:target) { tmptarget.path } 182 | 183 | it 'fails to load' do 184 | allow(FileTest).to receive(:exist?).and_return(false) 185 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 186 | allow(FileTest).to receive(:exist?).and_return(false) 187 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 188 | 189 | txn = apply(Puppet::Type.type(:rsyslog_filter).new( 190 | name: 'ssh', 191 | property: 'msg', 192 | operation: 'contains', 193 | value: 'sshd', 194 | action_type: 'file', 195 | action: '/var/log/sshd.log', 196 | target: target, 197 | provider: 'augeas', 198 | ensure: 'absent' 199 | )) 200 | 201 | expect(txn.any_failed?).not_to eq(nil) 202 | expect(@logs.first.level).to eq(:err) 203 | expect(@logs.first.message.include?(target)).to eq(true) 204 | end 205 | end 206 | end 207 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All notable changes to this project will be documented in this file. 4 | Each new release typically also includes the latest modulesync defaults. 5 | These should not affect the functionality of the module. 6 | 7 | ## [v3.0.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v3.0.0) (2024-04-09) 8 | 9 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/2.3.0...v3.0.0) 10 | 11 | **Breaking changes:** 12 | 13 | - Drop Puppet 6 support [\#15](https://github.com/voxpupuli/puppet-augeasproviders_syslog/pull/15) ([bastelfreak](https://github.com/bastelfreak)) 14 | 15 | **Implemented enhancements:** 16 | 17 | - Update readme and metadata to facilitate migration [\#18](https://github.com/voxpupuli/puppet-augeasproviders_syslog/pull/18) ([zilchms](https://github.com/zilchms)) 18 | - migrate dependency to voxpupuli; puppet/augeasproviders\_core: allow 4.x [\#17](https://github.com/voxpupuli/puppet-augeasproviders_syslog/pull/17) ([zilchms](https://github.com/zilchms)) 19 | - Add Puppet 8 support [\#16](https://github.com/voxpupuli/puppet-augeasproviders_syslog/pull/16) ([bastelfreak](https://github.com/bastelfreak)) 20 | 21 | **Merged pull requests:** 22 | 23 | - Fix broken Apache-2 license [\#14](https://github.com/voxpupuli/puppet-augeasproviders_syslog/pull/14) ([bastelfreak](https://github.com/bastelfreak)) 24 | 25 | ## [2.3.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/2.3.0) (2019-03-13) 26 | 27 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/2.2.1...2.3.0) 28 | 29 | **Closed issues:** 30 | 31 | - Can this be updated to work on Puppet 4.10 [\#8](https://github.com/voxpupuli/puppet-augeasproviders_syslog/issues/8) 32 | 33 | **Merged pull requests:** 34 | 35 | - Add type and provider for rsyslog\_filter [\#11](https://github.com/voxpupuli/puppet-augeasproviders_syslog/pull/11) ([raphink](https://github.com/raphink)) 36 | 37 | ## [2.2.1](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/2.2.1) (2019-03-01) 38 | 39 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/2.2.0...2.2.1) 40 | 41 | ## [2.2.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/2.2.0) (2019-03-01) 42 | 43 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/2.1.1...2.2.0) 44 | 45 | **Closed issues:** 46 | 47 | - Is the 'augeas' submodule needed? [\#6](https://github.com/voxpupuli/puppet-augeasproviders_syslog/issues/6) 48 | 49 | **Merged pull requests:** 50 | 51 | - Support Puppet 6 [\#10](https://github.com/voxpupuli/puppet-augeasproviders_syslog/pull/10) ([raphink](https://github.com/raphink)) 52 | - Raise exception on missing augeasproviders\_core [\#7](https://github.com/voxpupuli/puppet-augeasproviders_syslog/pull/7) ([igalic](https://github.com/igalic)) 53 | 54 | ## [2.1.1](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/2.1.1) (2014-12-09) 55 | 56 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/2.1.0...2.1.1) 57 | 58 | ## [2.1.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/2.1.0) (2014-11-24) 59 | 60 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v2.1.1...2.1.0) 61 | 62 | **Merged pull requests:** 63 | 64 | - TCP syslog config [\#1](https://github.com/voxpupuli/puppet-augeasproviders_syslog/pull/1) ([rlex](https://github.com/rlex)) 65 | 66 | ## [v2.1.1](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v2.1.1) (2014-11-17) 67 | 68 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v2.0.0...v2.1.1) 69 | 70 | ## [v2.0.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v2.0.0) (2014-08-13) 71 | 72 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/2.0.0...v2.0.0) 73 | 74 | ## [2.0.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/2.0.0) (2014-08-11) 75 | 76 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v1.2.0...2.0.0) 77 | 78 | ## [v1.2.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v1.2.0) (2014-06-10) 79 | 80 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v1.1.0...v1.2.0) 81 | 82 | ## [v1.1.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v1.1.0) (2014-05-05) 83 | 84 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v1.0.2...v1.1.0) 85 | 86 | ## [v1.0.2](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v1.0.2) (2013-10-28) 87 | 88 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v1.0.1...v1.0.2) 89 | 90 | ## [v1.0.1](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v1.0.1) (2013-10-05) 91 | 92 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v1.0.0...v1.0.1) 93 | 94 | ## [v1.0.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v1.0.0) (2013-08-23) 95 | 96 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.7.0...v1.0.0) 97 | 98 | ## [v0.7.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.7.0) (2013-06-03) 99 | 100 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.6.1...v0.7.0) 101 | 102 | ## [v0.6.1](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.6.1) (2013-04-20) 103 | 104 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.6.0...v0.6.1) 105 | 106 | ## [v0.6.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.6.0) (2013-04-01) 107 | 108 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.5.3...v0.6.0) 109 | 110 | ## [v0.5.3](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.5.3) (2013-03-20) 111 | 112 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.5.2...v0.5.3) 113 | 114 | ## [v0.5.2](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.5.2) (2013-02-23) 115 | 116 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.5.1...v0.5.2) 117 | 118 | ## [v0.5.1](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.5.1) (2012-12-04) 119 | 120 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.5.0...v0.5.1) 121 | 122 | ## [v0.5.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.5.0) (2012-12-01) 123 | 124 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.4.0...v0.5.0) 125 | 126 | ## [v0.4.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.4.0) (2012-11-08) 127 | 128 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.3.1...v0.4.0) 129 | 130 | ## [v0.3.1](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.3.1) (2012-09-25) 131 | 132 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.3.0...v0.3.1) 133 | 134 | ## [v0.3.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.3.0) (2012-09-09) 135 | 136 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.2.0...v0.3.0) 137 | 138 | ## [v0.2.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.2.0) (2012-08-26) 139 | 140 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.1.1...v0.2.0) 141 | 142 | ## [v0.1.1](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.1.1) (2012-07-21) 143 | 144 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.1.0...v0.1.1) 145 | 146 | ## [v0.1.0](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.1.0) (2012-07-14) 147 | 148 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.0.4...v0.1.0) 149 | 150 | ## [v0.0.4](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.0.4) (2012-07-01) 151 | 152 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.0.3...v0.0.4) 153 | 154 | ## [v0.0.3](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.0.3) (2012-03-05) 155 | 156 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.0.2...v0.0.3) 157 | 158 | ## [v0.0.2](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.0.2) (2012-03-04) 159 | 160 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/v0.0.1...v0.0.2) 161 | 162 | ## [v0.0.1](https://github.com/voxpupuli/puppet-augeasproviders_syslog/tree/v0.0.1) (2012-03-04) 163 | 164 | [Full Changelog](https://github.com/voxpupuli/puppet-augeasproviders_syslog/compare/0e3a07236052ad797f75649552bfbcea8b0b7ffb...v0.0.1) 165 | 166 | 167 | 168 | \* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)* 169 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /spec/unit/puppet/provider/syslog/rsyslog_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | provider_class = Puppet::Type.type(:syslog).provider(:rsyslog) 4 | def valid_lens? 5 | # This lens breaks on Augeas 0.10.0 6 | Puppet::Util::Package.versioncmp(Puppet::Type.type(:syslog).provider(:augeas).aug_version, '0.10.0') > 0 7 | end 8 | 9 | describe provider_class, if: valid_lens? do 10 | let(:protocol_supported) { subject.protocol_supported } 11 | 12 | context 'with empty file' do 13 | let(:tmptarget) { aug_fixture('empty') } 14 | let(:target) { tmptarget.path } 15 | 16 | it 'creates simple new entry' do 17 | allow(FileTest).to receive(:exist?).and_return(false) 18 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 19 | allow(FileTest).to receive(:exist?).and_return(false) 20 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 21 | 22 | apply!(Puppet::Type.type(:syslog).new( 23 | name: 'my test', 24 | facility: 'local2', 25 | level: '*', 26 | action_type: 'file', 27 | action: '/var/log/test.log', 28 | target: target, 29 | provider: 'rsyslog', 30 | ensure: 'present' 31 | )) 32 | 33 | aug_open(target, 'Rsyslog.lns') do |aug| 34 | expect(aug.match('entry').size).to eq(1) 35 | expect(aug.get('entry/action/file')).to eq('/var/log/test.log') 36 | expect(aug.match('entry/action/no_sync').size).to eq(0) 37 | end 38 | end 39 | 40 | it 'creates hostname entry with tcp protocol' do 41 | allow(FileTest).to receive(:exist?).and_return(false) 42 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 43 | allow(FileTest).to receive(:exist?).and_return(false) 44 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 45 | 46 | if protocol_supported 47 | apply!(Puppet::Type.type(:syslog).new( 48 | name: 'hostname test', 49 | facility: '*', 50 | level: '*', 51 | action_type: 'hostname', 52 | action_protocol: 'tcp', 53 | action: 'remote-host', 54 | target: target, 55 | provider: 'rsyslog', 56 | ensure: 'present' 57 | )) 58 | 59 | aug_open(target, 'Rsyslog.lns') do |aug| 60 | expect(aug.match('entry').size).to eq(1) 61 | expect(aug.get('entry/action/protocol')).to eq('@@') 62 | expect(aug.match('entry/action/port').size).to eq(0) 63 | end 64 | else 65 | txn = apply(Puppet::Type.type(:syslog).new( 66 | name: 'hostname test', 67 | facility: '*', 68 | level: '*', 69 | action_type: 'hostname', 70 | action_protocol: 'tcp', 71 | action: 'remote-host', 72 | target: target, 73 | provider: 'rsyslog', 74 | ensure: 'present' 75 | )) 76 | expect(txn.any_failed?).not_to eq(nil) 77 | expect(@logs[0].level).to eq(:err) 78 | expect(@logs[0].message.include?('Protocol is not supported')).to eq(true) 79 | end 80 | end 81 | 82 | it 'creates hostname entry with udp protocol' do 83 | allow(FileTest).to receive(:exist?).and_return(false) 84 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 85 | allow(FileTest).to receive(:exist?).and_return(false) 86 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 87 | 88 | if protocol_supported == :stock 89 | apply!(Puppet::Type.type(:syslog).new( 90 | name: 'hostname test', 91 | facility: '*', 92 | level: '*', 93 | action_type: 'hostname', 94 | action_protocol: 'udp', 95 | action: 'remote-host', 96 | target: target, 97 | provider: 'rsyslog', 98 | ensure: 'present' 99 | )) 100 | 101 | aug_open(target, 'Rsyslog.lns') do |aug| 102 | expect(aug.match('entry').size).to eq(1) 103 | expect(aug.get('entry/action/protocol')).to eq('@') 104 | expect(aug.match('entry/action/port').size).to eq(0) 105 | end 106 | elsif protocol_supported == :el7 107 | apply!(Puppet::Type.type(:syslog).new( 108 | name: 'hostname test', 109 | facility: '*', 110 | level: '*', 111 | action_type: 'hostname', 112 | action_protocol: 'udp', 113 | action: 'remote-host', 114 | target: target, 115 | provider: 'rsyslog', 116 | ensure: 'present' 117 | )) 118 | 119 | aug_open(target, 'Rsyslog.lns') do |aug| 120 | expect(aug.match('entry').size).to eq(1) 121 | expect(aug.match('entry/action/protocol').size).to eq(0) 122 | expect(aug.match('entry/action/port').size).to eq(0) 123 | end 124 | else 125 | txn = apply(Puppet::Type.type(:syslog).new( 126 | name: 'hostname test', 127 | facility: '*', 128 | level: '*', 129 | action_type: 'hostname', 130 | action_protocol: 'udp', 131 | action: 'remote-host', 132 | target: target, 133 | provider: 'rsyslog', 134 | ensure: 'present' 135 | )) 136 | expect(txn.any_failed?).not_to eq(nil) 137 | expect(@logs[0].level).to eq(:err) 138 | expect(@logs[0].message.include?('Protocol is not supported')).to eq(true) 139 | end 140 | end 141 | 142 | it 'creates hostname entry with port' do 143 | allow(FileTest).to receive(:exist?).and_return(false) 144 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 145 | allow(FileTest).to receive(:exist?).and_return(false) 146 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 147 | 148 | if protocol_supported # port requires protocol 149 | apply!(Puppet::Type.type(:syslog).new( 150 | name: 'hostname test', 151 | facility: '*', 152 | level: '*', 153 | action_type: 'hostname', 154 | action_port: '514', 155 | action_protocol: 'tcp', 156 | action: 'remote-host', 157 | target: target, 158 | provider: 'rsyslog', 159 | ensure: 'present' 160 | )) 161 | 162 | aug_open(target, 'Rsyslog.lns') do |aug| 163 | expect(aug.match('entry').size).to eq(1) 164 | expect(aug.get('entry/action/protocol')).to eq('@@') 165 | expect(aug.get('entry/action/port')).to eq('514') 166 | end 167 | else 168 | txn = apply(Puppet::Type.type(:syslog).new( 169 | name: 'hostname test', 170 | facility: '*', 171 | level: '*', 172 | action_type: 'hostname', 173 | action_port: '514', 174 | action_protocol: 'tcp', 175 | action: 'remote-host', 176 | target: target, 177 | provider: 'rsyslog', 178 | ensure: 'present' 179 | )) 180 | expect(txn.any_failed?).not_to eq(nil) 181 | expect(@logs[0].level).to eq(:err) 182 | expect(@logs[0].message.include?('Protocol is not supported')).to eq(true) 183 | end 184 | end 185 | end 186 | 187 | context 'with full file' do 188 | let(:tmptarget) { aug_fixture('full') } 189 | let(:target) { tmptarget.path } 190 | 191 | it 'lists instances' do 192 | allow(FileTest).to receive(:exist?).and_return(false) 193 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 194 | allow(FileTest).to receive(:exist?).and_return(false) 195 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 196 | 197 | allow(provider_class).to receive(:target).and_return(target) 198 | inst = provider_class.instances.map do |p| 199 | { 200 | name: p.get(:name), 201 | ensure: p.get(:ensure), 202 | facility: p.get(:facility), 203 | level: p.get(:level), 204 | no_sync: p.get(:no_sync), 205 | action_type: p.get(:action_type), 206 | action_port: p.get(:action_port), 207 | action_protocol: p.get(:action_protocol), 208 | action: p.get(:action), 209 | } 210 | end 211 | 212 | expect(inst.size).to eq(10) 213 | expect(inst[0]).to eq({ name: '*.info /var/log/messages', ensure: :present, facility: '*', level: 'info', no_sync: :false, action_type: 'file', action: '/var/log/messages', action_port: :absent, action_protocol: :absent }) 214 | expect(inst[1]).to eq({ name: 'mail.none /var/log/messages', ensure: :present, facility: 'mail', level: 'none', no_sync: :false, action_type: 'file', action: '/var/log/messages', action_port: :absent, action_protocol: :absent }) 215 | expect(inst[5]).to eq({ name: 'mail.* -/var/log/maillog', ensure: :present, facility: 'mail', level: '*', no_sync: :true, action_type: 'file', action: '/var/log/maillog', action_port: :absent, action_protocol: :absent }) 216 | expect(inst[8]).to eq({ name: 'news.crit /var/log/spooler', ensure: :present, facility: 'news', level: 'crit', no_sync: :false, action_type: 'file', action: '/var/log/spooler', action_port: :absent, action_protocol: :absent }) 217 | expect(inst[9]).to eq({ name: 'local7.* /var/log/boot.log', ensure: :present, facility: 'local7', level: '*', no_sync: :false, action_type: 'file', action: '/var/log/boot.log', action_port: :absent, action_protocol: :absent }) 218 | end 219 | 220 | describe 'when creating settings' do 221 | it 'creates a simple new entry' do 222 | apply!(Puppet::Type.type(:syslog).new( 223 | name: 'my test', 224 | facility: 'local2', 225 | level: 'info', 226 | action_type: 'file', 227 | action: '/var/log/test.log', 228 | target: target, 229 | provider: 'rsyslog', 230 | ensure: 'present' 231 | )) 232 | 233 | aug_open(target, 'Rsyslog.lns') do |aug| 234 | expect(aug.get("entry[selector/facility='local2']/action/file")).to eq('/var/log/test.log') 235 | expect(aug.match("entry[selector/facility='local2']/action/no_sync").size).to eq(0) 236 | end 237 | end 238 | end 239 | 240 | describe 'when modifying settings' do 241 | it 'adds a no_sync flag' do 242 | allow(FileTest).to receive(:exist?).and_return(false) 243 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 244 | allow(FileTest).to receive(:exist?).and_return(false) 245 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 246 | 247 | apply!(Puppet::Type.type(:syslog).new( 248 | name: 'cron.*', 249 | facility: 'cron', 250 | level: '*', 251 | action_type: 'file', 252 | action: '/var/log/cron', 253 | target: target, 254 | no_sync: :true, 255 | provider: 'rsyslog', 256 | ensure: 'present' 257 | )) 258 | 259 | aug_open(target, 'Rsyslog.lns') do |aug| 260 | expect(aug.match("entry[selector/facility='cron']/action/no_sync").size).to eq(1) 261 | end 262 | end 263 | 264 | it 'removes the no_sync flag' do 265 | allow(FileTest).to receive(:exist?).and_return(false) 266 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 267 | allow(FileTest).to receive(:exist?).and_return(false) 268 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 269 | 270 | apply!(Puppet::Type.type(:syslog).new( 271 | name: 'mail.*', 272 | facility: 'mail', 273 | level: '*', 274 | action_type: 'file', 275 | action: '/var/log/maillog', 276 | target: target, 277 | no_sync: :false, 278 | provider: 'rsyslog', 279 | ensure: 'present' 280 | )) 281 | 282 | aug_open(target, 'Rsyslog.lns') do |aug| 283 | expect(aug.match("entry[selector/facility='mail']/action/no_sync").size).to eq(0) 284 | end 285 | end 286 | end 287 | 288 | describe 'when removing settings' do 289 | it 'removes the entry' do 290 | allow(FileTest).to receive(:exist?).and_return(false) 291 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 292 | allow(FileTest).to receive(:exist?).and_return(false) 293 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 294 | 295 | apply!(Puppet::Type.type(:syslog).new( 296 | name: 'mail.*', 297 | facility: 'mail', 298 | level: '*', 299 | action_type: 'file', 300 | action: '/var/log/maillog', 301 | target: target, 302 | provider: 'rsyslog', 303 | ensure: 'absent' 304 | )) 305 | 306 | aug_open(target, 'Rsyslog.lns') do |aug| 307 | expect(aug.match("entry[selector/facility='mail' and level='*']").size).to eq(0) 308 | end 309 | end 310 | end 311 | end 312 | 313 | context 'with broken file' do 314 | let(:tmptarget) { aug_fixture('broken') } 315 | let(:target) { tmptarget.path } 316 | 317 | it 'fails to load' do 318 | allow(FileTest).to receive(:exist?).and_return(false) 319 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 320 | allow(FileTest).to receive(:exist?).and_return(false) 321 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 322 | 323 | txn = apply(Puppet::Type.type(:syslog).new( 324 | name: 'mail.*', 325 | facility: 'mail', 326 | level: '*', 327 | action_type: 'file', 328 | action: '/var/log/maillog', 329 | target: target, 330 | provider: 'rsyslog', 331 | ensure: 'present' 332 | )) 333 | 334 | expect(txn.any_failed?).not_to eq(nil) 335 | expect(@logs.first.level).to eq(:err) 336 | expect(@logs.first.message.include?(target)).to eq(true) 337 | end 338 | end 339 | end 340 | -------------------------------------------------------------------------------- /spec/unit/puppet/provider/syslog/augeas_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | provider_class = Puppet::Type.type(:syslog).provider(:augeas) 3 | 4 | describe provider_class do 5 | let(:protocol_supported) { subject.protocol_supported } 6 | 7 | context 'with empty file' do 8 | let(:tmptarget) { aug_fixture('empty') } 9 | let(:target) { tmptarget.path } 10 | 11 | it 'creates simple new entry' do 12 | allow(FileTest).to receive(:exist?).and_return(false) 13 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 14 | allow(FileTest).to receive(:exist?).and_return(false) 15 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 16 | 17 | apply!(Puppet::Type.type(:syslog).new( 18 | name: 'my test', 19 | facility: 'local2', 20 | level: '*', 21 | action_type: 'file', 22 | action: '/var/log/test.log', 23 | target: target, 24 | provider: 'augeas', 25 | ensure: 'present' 26 | )) 27 | 28 | aug_open(target, 'Syslog.lns') do |aug| 29 | expect(aug.match('entry').size).to eq(1) 30 | expect(aug.get('entry/action/file')).to eq('/var/log/test.log') 31 | expect(aug.match('entry/action/no_sync').size).to eq(0) 32 | end 33 | end 34 | 35 | it 'creates hostname entry with tcp protocol' do 36 | allow(FileTest).to receive(:exist?).and_return(false) 37 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 38 | allow(FileTest).to receive(:exist?).and_return(false) 39 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 40 | 41 | if protocol_supported 42 | apply!(Puppet::Type.type(:syslog).new( 43 | name: 'hostname test', 44 | facility: '*', 45 | level: '*', 46 | action_type: 'hostname', 47 | action_protocol: 'tcp', 48 | action: 'remote-host', 49 | target: target, 50 | provider: 'augeas', 51 | ensure: 'present' 52 | )) 53 | 54 | aug_open(target, 'Syslog.lns') do |aug| 55 | expect(aug.match('entry').size).to eq(1) 56 | expect(aug.get('entry/action/protocol')).to eq('@@') 57 | expect(aug.match('entry/action/port').size).to eq(0) 58 | end 59 | else 60 | txn = apply(Puppet::Type.type(:syslog).new( 61 | name: 'hostname test', 62 | facility: '*', 63 | level: '*', 64 | action_type: 'hostname', 65 | action_protocol: 'tcp', 66 | action: 'remote-host', 67 | target: target, 68 | provider: 'augeas', 69 | ensure: 'present' 70 | )) 71 | expect(txn.any_failed?).not_to eq(nil) 72 | expect(@logs[0].level).to eq(:err) 73 | expect(@logs[0].message.include?('Protocol is not supported')).to eq(true) 74 | end 75 | end 76 | 77 | it 'creates hostname entry with udp protocol' do 78 | allow(FileTest).to receive(:exist?).and_return(false) 79 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 80 | allow(FileTest).to receive(:exist?).and_return(false) 81 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 82 | 83 | if protocol_supported == :stock 84 | apply!(Puppet::Type.type(:syslog).new( 85 | name: 'hostname test', 86 | facility: '*', 87 | level: '*', 88 | action_type: 'hostname', 89 | action_protocol: 'udp', 90 | action: 'remote-host', 91 | target: target, 92 | provider: 'augeas', 93 | ensure: 'present' 94 | )) 95 | 96 | aug_open(target, 'Syslog.lns') do |aug| 97 | expect(aug.match('entry').size).to eq(1) 98 | expect(aug.get('entry/action/protocol')).to eq('@') 99 | expect(aug.match('entry/action/port').size).to eq(0) 100 | end 101 | elsif protocol_supported == :el7 102 | apply!(Puppet::Type.type(:syslog).new( 103 | name: 'hostname test', 104 | facility: '*', 105 | level: '*', 106 | action_type: 'hostname', 107 | action_protocol: 'udp', 108 | action: 'remote-host', 109 | target: target, 110 | provider: 'augeas', 111 | ensure: 'present' 112 | )) 113 | 114 | aug_open(target, 'Syslog.lns') do |aug| 115 | expect(aug.match('entry').size).to eq(1) 116 | expect(aug.match('entry/action/protocol').size).to eq(0) 117 | expect(aug.match('entry/action/port').size).to eq(0) 118 | end 119 | else 120 | txn = apply(Puppet::Type.type(:syslog).new( 121 | name: 'hostname test', 122 | facility: '*', 123 | level: '*', 124 | action_type: 'hostname', 125 | action_protocol: 'udp', 126 | action: 'remote-host', 127 | target: target, 128 | provider: 'augeas', 129 | ensure: 'present' 130 | )) 131 | expect(txn.any_failed?).not_to eq(nil) 132 | expect(@logs[0].level).to eq(:err) 133 | expect(@logs[0].message.include?('Protocol is not supported')).to eq(true) 134 | end 135 | end 136 | 137 | it 'creates hostname entry with port' do 138 | allow(FileTest).to receive(:exist?).and_return(false) 139 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 140 | allow(FileTest).to receive(:exist?).and_return(false) 141 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 142 | 143 | if protocol_supported # port requires protocol 144 | apply!(Puppet::Type.type(:syslog).new( 145 | name: 'hostname test', 146 | facility: '*', 147 | level: '*', 148 | action_type: 'hostname', 149 | action_port: '514', 150 | action_protocol: 'tcp', 151 | action: 'remote-host', 152 | target: target, 153 | provider: 'augeas', 154 | ensure: 'present' 155 | )) 156 | 157 | aug_open(target, 'Syslog.lns') do |aug| 158 | expect(aug.match('entry').size).to eq(1) 159 | expect(aug.get('entry/action/protocol')).to eq('@@') 160 | expect(aug.get('entry/action/port')).to eq('514') 161 | end 162 | else 163 | txn = apply(Puppet::Type.type(:syslog).new( 164 | name: 'hostname test', 165 | facility: '*', 166 | level: '*', 167 | action_type: 'hostname', 168 | action_port: '514', 169 | action_protocol: 'tcp', 170 | action: 'remote-host', 171 | target: target, 172 | provider: 'augeas', 173 | ensure: 'present' 174 | )) 175 | expect(txn.any_failed?).not_to eq(nil) 176 | expect(@logs[0].level).to eq(:err) 177 | expect(@logs[0].message.include?('Protocol is not supported')).to eq(true) 178 | end 179 | end 180 | end 181 | 182 | context 'with full file' do 183 | let(:tmptarget) { aug_fixture('full') } 184 | let(:target) { tmptarget.path } 185 | 186 | it 'lists instances' do 187 | allow(FileTest).to receive(:exist?).and_return(false) 188 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 189 | allow(FileTest).to receive(:exist?).and_return(false) 190 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 191 | 192 | allow(provider_class).to receive(:target).and_return(target) 193 | inst = provider_class.instances.map do |p| 194 | { 195 | name: p.get(:name), 196 | ensure: p.get(:ensure), 197 | facility: p.get(:facility), 198 | level: p.get(:level), 199 | no_sync: p.get(:no_sync), 200 | action_type: p.get(:action_type), 201 | action_port: p.get(:action_port), 202 | action_protocol: p.get(:action_protocol), 203 | action: p.get(:action), 204 | } 205 | end 206 | 207 | expect(inst.size).to eq(10) 208 | expect(inst[0]).to eq({ name: '*.info /var/log/messages', ensure: :present, facility: '*', level: 'info', no_sync: :false, action_type: 'file', action: '/var/log/messages', action_port: :absent, action_protocol: :absent }) 209 | expect(inst[1]).to eq({ name: 'mail.none /var/log/messages', ensure: :present, facility: 'mail', level: 'none', no_sync: :false, action_type: 'file', action: '/var/log/messages', action_port: :absent, action_protocol: :absent }) 210 | expect(inst[5]).to eq({ name: 'mail.* -/var/log/maillog', ensure: :present, facility: 'mail', level: '*', no_sync: :true, action_type: 'file', action: '/var/log/maillog', action_port: :absent, action_protocol: :absent }) 211 | expect(inst[8]).to eq({ name: 'uucp.crit /var/log/spooler', ensure: :present, facility: 'uucp', level: 'crit', no_sync: :false, action_type: 'file', action: '/var/log/spooler', action_port: :absent, action_protocol: :absent }) 212 | expect(inst[9]).to eq({ name: 'news.crit /var/log/spooler', ensure: :present, facility: 'news', level: 'crit', no_sync: :false, action_type: 'file', action: '/var/log/spooler', action_port: :absent, action_protocol: :absent }) 213 | end 214 | 215 | describe 'when creating settings' do 216 | it 'creates a simple new entry' do 217 | allow(FileTest).to receive(:exist?).and_return(false) 218 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 219 | allow(FileTest).to receive(:exist?).and_return(false) 220 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 221 | 222 | apply!(Puppet::Type.type(:syslog).new( 223 | name: 'my test', 224 | facility: 'local2', 225 | level: 'info', 226 | action_type: 'file', 227 | action: '/var/log/test.log', 228 | target: target, 229 | provider: 'augeas', 230 | ensure: 'present' 231 | )) 232 | 233 | aug_open(target, 'Syslog.lns') do |aug| 234 | expect(aug.get("entry[selector/facility='local2']/action/file")).to eq('/var/log/test.log') 235 | expect(aug.match("entry[selector/facility='local2']/action/no_sync").size).to eq(0) 236 | end 237 | end 238 | end 239 | 240 | describe 'when modifying settings' do 241 | it 'adds a no_sync flag' do 242 | allow(FileTest).to receive(:exist?).and_return(false) 243 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 244 | allow(FileTest).to receive(:exist?).and_return(false) 245 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 246 | 247 | apply!(Puppet::Type.type(:syslog).new( 248 | name: 'cron.*', 249 | facility: 'cron', 250 | level: '*', 251 | action_type: 'file', 252 | action: '/var/log/cron', 253 | target: target, 254 | no_sync: :true, 255 | provider: 'augeas', 256 | ensure: 'present' 257 | )) 258 | 259 | aug_open(target, 'Syslog.lns') do |aug| 260 | expect(aug.match("entry[selector/facility='cron']/action/no_sync").size).to eq(1) 261 | end 262 | end 263 | 264 | it 'removes the no_sync flag' do 265 | allow(FileTest).to receive(:exist?).and_return(false) 266 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 267 | allow(FileTest).to receive(:exist?).and_return(false) 268 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 269 | 270 | apply!(Puppet::Type.type(:syslog).new( 271 | name: 'mail.*', 272 | facility: 'mail', 273 | level: '*', 274 | action_type: 'file', 275 | action: '/var/log/maillog', 276 | target: target, 277 | no_sync: :false, 278 | provider: 'augeas', 279 | ensure: 'present' 280 | )) 281 | 282 | aug_open(target, 'Syslog.lns') do |aug| 283 | expect(aug.match("entry[selector/facility='mail']/action/no_sync").size).to eq(0) 284 | end 285 | end 286 | end 287 | 288 | describe 'when removing settings' do 289 | it 'removes the entry' do 290 | allow(FileTest).to receive(:exist?).and_return(false) 291 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 292 | allow(FileTest).to receive(:exist?).and_return(false) 293 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 294 | 295 | apply!(Puppet::Type.type(:syslog).new( 296 | name: 'mail.*', 297 | facility: 'mail', 298 | level: '*', 299 | action_type: 'file', 300 | action: '/var/log/maillog', 301 | target: target, 302 | provider: 'augeas', 303 | ensure: 'absent' 304 | )) 305 | 306 | aug_open(target, 'Syslog.lns') do |aug| 307 | expect(aug.match("entry[selector/facility='mail' and level='*']").size).to eq(0) 308 | end 309 | end 310 | end 311 | end 312 | 313 | context 'with broken file' do 314 | let(:tmptarget) { aug_fixture('broken') } 315 | let(:target) { tmptarget.path } 316 | 317 | it 'fails to load' do 318 | allow(FileTest).to receive(:exist?).and_return(false) 319 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 320 | allow(FileTest).to receive(:exist?).and_return(false) 321 | allow(FileTest).to receive(:exist?).with('/etc/rsyslog.conf').and_return(true) 322 | 323 | txn = apply(Puppet::Type.type(:syslog).new( 324 | name: 'mail.*', 325 | facility: 'mail', 326 | level: '*', 327 | action_type: 'file', 328 | action: '/var/log/maillog', 329 | target: target, 330 | provider: 'augeas', 331 | ensure: 'present' 332 | )) 333 | 334 | expect(txn.any_failed?).not_to eq(nil) 335 | expect(@logs.first.level).to eq(:err) 336 | expect(@logs.first.message.include?(target)).to eq(true) 337 | end 338 | end 339 | end 340 | --------------------------------------------------------------------------------