├── .rspec ├── spec ├── fixtures │ ├── logstash.yaml │ └── report2.6.x.yaml ├── classes │ ├── 099_coverage_spec.rb │ └── logstash_reporter_init_spec.rb ├── acceptance │ └── nodesets │ │ ├── opensuse-121-x64.yml │ │ ├── sles-11sp3-x64.yml │ │ ├── opensuse-131-x64.yml │ │ ├── centos-7-x64.yml │ │ ├── centos-6-x64.yml │ │ ├── ubuntu-server-1404-x64.yml │ │ ├── ubuntu-server-1204-x64.yml │ │ ├── ubuntu-server-1210-x64.yml │ │ ├── ubuntu-server-1304-x64.yml │ │ ├── ubuntu-server-1310-x64.yml │ │ ├── debian-8-x64.yml │ │ ├── debian-7-x64.yml │ │ └── debian-6-x64.yml ├── spec_helper.rb └── unit │ └── logstash_reporter_spec.rb ├── .pmtignore ├── .fixtures.yml ├── templates └── logstash.yaml.erb ├── .gitignore ├── CHANGELOG.md ├── LICENSE ├── Rakefile ├── Gemfile ├── manifests ├── params.pp └── init.pp ├── metadata.json ├── lib └── puppet │ └── reports │ └── logstash.rb └── README.md /.rspec: -------------------------------------------------------------------------------- 1 | --format 2 | d 3 | -------------------------------------------------------------------------------- /spec/fixtures/logstash.yaml: -------------------------------------------------------------------------------- 1 | --- 2 | :host: localhost 3 | :port: 5999 4 | -------------------------------------------------------------------------------- /.pmtignore: -------------------------------------------------------------------------------- 1 | spec/ 2 | Rakefile 3 | junit/ 4 | logs/ 5 | Gemfile 6 | Gemfile.lock 7 | -------------------------------------------------------------------------------- /spec/classes/099_coverage_spec.rb: -------------------------------------------------------------------------------- 1 | at_exit { RSpec::Puppet::Coverage.report! } 2 | -------------------------------------------------------------------------------- /.fixtures.yml: -------------------------------------------------------------------------------- 1 | fixtures: 2 | symlinks: 3 | logstash_reporter: "#{source_dir}" 4 | 5 | -------------------------------------------------------------------------------- /templates/logstash.yaml.erb: -------------------------------------------------------------------------------- 1 | --- 2 | :host: <%= scope.lookupvar('logstash_host') %> 3 | :port: <%= scope.lookupvar('logstash_port') %> 4 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .swp 2 | spec/fixtures/manifests 3 | spec/fixtures/modules 4 | .bundle 5 | .vendor 6 | .vagrant 7 | .ruby-version 8 | pkg/ 9 | spec/reports/ 10 | spec/logs 11 | log 12 | *.lock 13 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ##0.1.0( Jun 05, 2015 ) 2 | 3 | ###Summary 4 | 5 | First official public release of the logstash reporter 6 | 7 | ####Features 8 | 9 | ####Bugfixes 10 | 11 | ####Changes 12 | 13 | ####Testing changes 14 | 15 | ####Known bugs 16 | 17 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/opensuse-121-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | opensuse-121-x64: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: sles-12-x64 8 | box: opensuse-121-x64 9 | box_url: https://s3.amazonaws.com/circlejtp/OpenSuseVagrant/OpenSuse12_1x64_July14.box 10 | hypervisor: vagrant 11 | CONFIG: 12 | type: foss 13 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/sles-11sp3-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | sles-11-x64: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: sles-11-x86_64 8 | box: sles-11sp3-x64 9 | box_url: https://s3-eu-west-1.amazonaws.com/users.eu.elasticsearch.org/electrical/sles-11sp3-x64.box 10 | hypervisor: vagrant 11 | CONFIG: 12 | type: foss 13 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/opensuse-131-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | opensuse-131-x64: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: sles-13-x64 8 | box: opensuse-13.1-test 9 | box_url: https://s3-eu-west-1.amazonaws.com/users.eu.elasticsearch.org/electrical/opensuse-131.box 10 | hypervisor: vagrant 11 | CONFIG: 12 | type: foss 13 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/centos-7-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | centos-7-x64: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: el-7-x86_64 8 | image: electrical/centos:7 9 | hypervisor: docker 10 | docker_cmd: '["/usr/sbin/init"]' 11 | docker_image_commands: 12 | - 'yum install -y wget ntpdate rubygems ruby-devel augeas-devel ruby-augeas tar' 13 | docker_preserve_image: true 14 | CONFIG: 15 | type: foss 16 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'puppetlabs_spec_helper/module_spec_helper' 2 | require 'rspec-puppet-facts' 3 | include RspecPuppetFacts 4 | 5 | def fixture_path 6 | File.expand_path(File.join(__FILE__, '..', 'fixtures')) 7 | end 8 | 9 | $LOAD_PATH.unshift(File.expand_path(File.dirname(__FILE__) + '/../')) 10 | 11 | RSpec.configure do |c| 12 | c.add_setting :fixture_path, :default => fixture_path 13 | c.mock_with(:rspec) 14 | Puppet[:config] = File.join(fixture_path,'puppet.conf') 15 | end 16 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/centos-6-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | centos-6-x64: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: el-6-x86_64 8 | image: electrical/centos:6.4 9 | hypervisor: docker 10 | docker_cmd: '["/sbin/init"]' 11 | docker_image_commands: 12 | - 'yum install -y wget ntpdate rubygems ruby-augeas ruby-devel augeas-devel' 13 | - 'touch /etc/sysconfig/network' 14 | docker_preserve_image: true 15 | CONFIG: 16 | type: foss 17 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/ubuntu-server-1404-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-14-04: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: ubuntu-14.04-amd64 8 | image: electrical/ubuntu:14.04 9 | hypervisor: docker 10 | docker_cmd: '["/sbin/init"]' 11 | docker_image_commands: 12 | - 'apt-get install -yq ruby ruby1.9.1-dev libaugeas-dev libaugeas-ruby lsb-release wget net-tools curl' 13 | docker_preserve_image: true 14 | CONFIG: 15 | type: foss 16 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/ubuntu-server-1204-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-12-04: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: ubuntu-12.04-amd64 8 | image: electrical/ubuntu:12.04 9 | hypervisor: docker 10 | docker_cmd: '["/sbin/init"]' 11 | docker_image_commands: 12 | - 'apt-get install -yq ruby1.8-dev libaugeas-dev libaugeas-ruby ruby rubygems lsb-release wget net-tools curl' 13 | docker_preserve_image: true 14 | CONFIG: 15 | type: foss 16 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/ubuntu-server-1210-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-12-10: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: ubuntu-12.10-amd64 8 | image: electrical/ubuntu:12.10 9 | hypervisor: docker 10 | docker_cmd: '["/sbin/init"]' 11 | docker_image_commands: 12 | - 'apt-get install -yq ruby1.8-dev libaugeas-dev libaugeas-ruby ruby rubygems lsb-release wget net-tools curl' 13 | docker_preserve_image: true 14 | CONFIG: 15 | type: foss 16 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/ubuntu-server-1304-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-13-04: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: ubuntu-13.04-amd64 8 | image: electrical/ubuntu:13.04 9 | hypervisor: docker 10 | docker_cmd: '["/sbin/init"]' 11 | docker_image_commands: 12 | - 'apt-get install -yq ruby1.8-dev libaugeas-dev libaugeas-ruby ruby rubygems lsb-release wget net-tools curl' 13 | docker_preserve_image: true 14 | CONFIG: 15 | type: foss 16 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/ubuntu-server-1310-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | ubuntu-13-10: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: ubuntu-13.10-amd64 8 | image: electrical/ubuntu:13.10 9 | hypervisor: docker 10 | docker_cmd: '["/sbin/init"]' 11 | docker_image_commands: 12 | - 'apt-get install -yq ruby1.8-dev libaugeas-dev libaugeas-ruby ruby rubygems lsb-release wget net-tools curl' 13 | docker_preserve_image: true 14 | CONFIG: 15 | type: foss 16 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/debian-8-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | debian-8: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: debian-8-amd64 8 | image: electrical/debian:8 9 | hypervisor: docker 10 | docker_cmd: '["/sbin/init"]' 11 | docker_image_commands: 12 | - 'apt-get install -yq ruby ruby-dev lsb-release wget net-tools libaugeas-dev libaugeas-ruby ntpdate locales-all' 13 | - 'REALLY_GEM_UPDATE_SYSTEM=1 gem update --system --no-ri --no-rdoc' 14 | docker_preserve_image: true 15 | CONFIG: 16 | type: foss 17 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/debian-7-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | debian-7: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: debian-7-amd64 8 | image: electrical/debian:7.3 9 | hypervisor: docker 10 | docker_cmd: '["/sbin/init"]' 11 | docker_image_commands: 12 | - 'apt-get install -yq lsb-release wget net-tools ruby rubygems ruby1.8-dev libaugeas-dev libaugeas-ruby ntpdate locales-all' 13 | - 'REALLY_GEM_UPDATE_SYSTEM=1 gem update --system --no-ri --no-rdoc' 14 | docker_preserve_image: true 15 | CONFIG: 16 | type: foss 17 | -------------------------------------------------------------------------------- /spec/acceptance/nodesets/debian-6-x64.yml: -------------------------------------------------------------------------------- 1 | HOSTS: 2 | debian-6: 3 | roles: 4 | - master 5 | - database 6 | - dashboard 7 | platform: debian-6-amd64 8 | image: electrical/debian:6.0.8 9 | hypervisor: docker 10 | docker_cmd: '["/sbin/init"]' 11 | docker_image_commands: 12 | - 'apt-get install -yq lsb-release wget net-tools ruby rubygems ruby1.8-dev libaugeas-dev libaugeas-ruby ntpdate locales-all' 13 | - 'REALLY_GEM_UPDATE_SYSTEM=1 gem update --system --no-ri --no-rdoc' 14 | docker_preserve_image: true 15 | CONFIG: 16 | type: foss 17 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2016 Elasticsearch 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"); 4 | you may not use this file except in compliance with the License. 5 | You may obtain a copy of the License at 6 | 7 | http://www.apache.org/licenses/LICENSE-2.0 8 | 9 | Unless required by applicable law or agreed to in writing, software 10 | distributed under the License is distributed on an "AS IS" BASIS, 11 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | See the License for the specific language governing permissions and 13 | limitations under the License. 14 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'puppetlabs_spec_helper/rake_tasks' 3 | 4 | exclude_paths = [ 5 | "pkg/**/*", 6 | "vendor/**/*", 7 | "spec/**/*", 8 | ] 9 | 10 | require 'puppet-doc-lint/rake_task' 11 | PuppetDocLint.configuration.ignore_paths = exclude_paths 12 | 13 | require 'puppet-lint/tasks/puppet-lint' 14 | require 'puppet-syntax/tasks/puppet-syntax' 15 | 16 | PuppetSyntax.exclude_paths = exclude_paths 17 | PuppetSyntax.future_parser = true if ENV['FUTURE_PARSER'] == 'true' 18 | 19 | disable_checks = [ 20 | '80chars', 21 | 'class_inherits_from_params_class', 22 | 'class_parameter_defaults', 23 | 'documentation', 24 | 'single_quote_string_with_variables' 25 | ].each { |check| PuppetLint.configuration.send("disable_#{check}") } 26 | 27 | PuppetLint.configuration.ignore_paths = exclude_paths 28 | PuppetLint.configuration.log_format = "%{path}:%{linenumber}:%{check}:%{KIND}:%{message}" 29 | -------------------------------------------------------------------------------- /spec/classes/logstash_reporter_init_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe 'logstash_reporter', :type => :class do 4 | 5 | context 'default' do 6 | let(:facts) { { :puppetversion => '3.7.5'} } 7 | it { should contain_class('logstash_reporter') } 8 | it { should contain_class('logstash_reporter::params') } 9 | it { should contain_file('/etc/puppet/logstash.yaml').with(:owner => 'puppet') } 10 | end 11 | 12 | context 'pe' do 13 | let(:facts) { { :is_pe => true } } 14 | it { should contain_class('logstash_reporter') } 15 | it { should contain_class('logstash_reporter::params') } 16 | it { should contain_file('/etc/puppetlabs/puppet/logstash.yaml').with(:owner => 'pe-puppet') } 17 | end 18 | 19 | context 'puppet 4' do 20 | let(:facts) { { :puppetversion => '4.0.0', :is_pe => false } } 21 | it { should contain_class('logstash_reporter') } 22 | it { should contain_class('logstash_reporter::params') } 23 | it { should contain_file('/etc/puppetlabs/puppet/logstash.yaml').with(:owner => 'puppet') } 24 | end 25 | end 26 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | puppetversion = ENV['PUPPET_VERSION'] || '~> 3.8.0' 4 | gem 'puppet', puppetversion, :require => false 5 | 6 | gem 'beaker' 7 | gem 'beaker-rspec' 8 | gem 'metadata-json-lint' 9 | gem 'rspec-puppet', '2.2.0' 10 | 11 | gem 'pry' 12 | gem 'docker-api', '~> 1.0' 13 | gem 'rubysl-securerandom' 14 | gem 'ci_reporter_rspec' 15 | gem 'rspec', '~> 3.0' 16 | gem 'rake' 17 | gem 'puppet-doc-lint' 18 | gem 'puppet-lint' 19 | gem 'puppetlabs_spec_helper' 20 | gem 'puppet-syntax' 21 | gem 'rspec-puppet-facts' 22 | gem 'webmock' 23 | 24 | # Extra Puppet-lint gems 25 | gem 'puppet-lint-appends-check', :require => false 26 | gem 'puppet-lint-version_comparison-check', :require => false 27 | gem 'puppet-lint-unquoted_string-check', :require => false 28 | gem 'puppet-lint-undef_in_function-check', :require => false 29 | gem 'puppet-lint-trailing_comma-check', :require => false 30 | gem 'puppet-lint-leading_zero-check', :require => false 31 | gem 'puppet-lint-file_ensure-check', :require => false 32 | gem 'puppet-lint-empty_string-check', :require => false 33 | -------------------------------------------------------------------------------- /manifests/params.pp: -------------------------------------------------------------------------------- 1 | # == Class: logstash_reporter::params 2 | # 3 | # This class exists to 4 | # 1. Declutter the default value assignment for class parameters. 5 | # 2. Manage internally used module variables in a central place. 6 | # 7 | # Therefore, many operating system dependent differences (names, paths, ...) 8 | # are addressed in here. 9 | # 10 | # 11 | # === Parameters 12 | # 13 | # This class does not provide any parameters. 14 | # 15 | # 16 | # === Examples 17 | # 18 | # This class is not intended to be used directly. 19 | # 20 | # 21 | # === Links 22 | # 23 | # * {Puppet Docs: Using Parameterized Classes}[http://j.mp/nVpyWY] 24 | # 25 | # 26 | # === Authors 27 | # 28 | # * Richard Pijnenburg 29 | # 30 | class logstash_reporter::params { 31 | 32 | if( $::is_pe == true ) { 33 | $config_file = '/etc/puppetlabs/puppet/logstash.yaml' 34 | $config_owner = 'pe-puppet' 35 | $config_group = 'pe-puppet' 36 | } elsif versioncmp($::puppetversion, '4.0.0') >= 0 { 37 | $config_file = '/etc/puppetlabs/puppet/logstash.yaml' 38 | $config_owner = 'puppet' 39 | $config_group = 'puppet' 40 | } else { 41 | $config_file = '/etc/puppet/logstash.yaml' 42 | $config_owner = 'puppet' 43 | $config_group = 'puppet' 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /manifests/init.pp: -------------------------------------------------------------------------------- 1 | # == Class: logstash_reporter 2 | # 3 | # This class deploys and configures a puppet reporter to send reports to logstash 4 | # 5 | # 6 | # === Parameters 7 | # 8 | # [*logstash_host*] 9 | # String. Logstash host to write reports to 10 | # Default: 127.0.0.1 11 | # 12 | # [*logstash_port*] 13 | # Integer. Port logstash is listening for tcp connections on 14 | # Default: 5999 15 | # 16 | # [*config_file*] 17 | # String. Path to write the config file to 18 | # Default: /etc/puppet/logstash.yaml 19 | # 20 | # [*config_owner*] 21 | # String. Owner of the config file 22 | # 23 | # [*config_group*] 24 | # String. Group of the config file 25 | # 26 | # === Examples 27 | # 28 | # * Installation: 29 | # class { 'logstash_reporter': } 30 | # 31 | # === Authors 32 | # 33 | # * John E. Vincent 34 | # * Justin Lambert 35 | # * Richard Pijnenburg 36 | # 37 | class logstash_reporter ( 38 | $logstash_host = '127.0.0.1', 39 | $logstash_port = 5999, 40 | $config_file = $::logstash_reporter::params::config_file, 41 | $config_owner = $::logstash_reporter::params::config_owner, 42 | $config_group = $::logstash_reporter::params::config_group, 43 | ) inherits logstash_reporter::params { 44 | 45 | file { $config_file: 46 | ensure => file, 47 | owner => $config_owner, 48 | group => $config_group, 49 | mode => '0444', 50 | content => template('logstash_reporter/logstash.yaml.erb'), 51 | } 52 | 53 | } 54 | 55 | -------------------------------------------------------------------------------- /spec/unit/logstash_reporter_spec.rb: -------------------------------------------------------------------------------- 1 | #! /usr/bin/env ruby 2 | require 'spec_helper' 3 | 4 | require 'puppet/reports' 5 | require 'time' 6 | require 'pathname' 7 | require 'tempfile' 8 | require 'fileutils' 9 | 10 | processor = Puppet::Reports.report(:logstash) 11 | 12 | describe processor do 13 | describe "#process" do 14 | 15 | after :each do 16 | @server.close 17 | end 18 | 19 | before :each do 20 | @server = TCPServer.new 5999 21 | @report = YAML.load_file(File.join(fixture_path, 'report2.6.x.yaml')).extend processor 22 | 23 | end 24 | 25 | it "should send the right data to the remote server" do 26 | 27 | @report.process 28 | client = @server.accept() 29 | resp = client.read() 30 | data = JSON.parse(resp) 31 | expect(data).not_to be_empty 32 | expect(data['@version']).to eq(1) 33 | expect(data['@timestamp']).to eq(Time.now.utc.iso8601) 34 | 35 | expect(data).to include("environment", "report_format", "puppet_version", "status", "start_time", "end_time", "tags") 36 | 37 | 38 | end 39 | 40 | it "rejects invalid hostnames" do 41 | @report.host = ".." 42 | expect { @report.process }.to raise_error(ArgumentError, /Invalid node/) 43 | end 44 | end 45 | 46 | describe "::validate_host" do 47 | ['..', 'hello/', '/hello', 'he/llo', 'hello/..', '.'].each do |node| 48 | it "rejects #{node.inspect}" do 49 | expect { processor.validate_host(node) }.to raise_error(ArgumentError, /Invalid node/) 50 | end 51 | end 52 | 53 | ['.hello', 'hello.', '..hi', 'hi..'].each do |node| 54 | it "accepts #{node.inspect}" do 55 | processor.validate_host(node) 56 | end 57 | end 58 | end 59 | end 60 | -------------------------------------------------------------------------------- /metadata.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "elasticsearch-logstash_reporter", 3 | "version": "0.1.0", 4 | "source": "https://github.com/elastic/puppet-logstash-reporter", 5 | "author": "elasticsearch", 6 | "license": "Apache-2.0", 7 | "summary": "Install and configure Logstash reporter for Puppet", 8 | "description": "Install and configure Logstash reporter for Puppet", 9 | "project_page": "https://github.com/elastic/puppet-logstash-reporter", 10 | "issues_url": "https://github.com/elastic/puppet-logtash-reporter/issues", 11 | "dependencies": [ 12 | ], 13 | "operatingsystem_support": [ 14 | { 15 | "operatingsystem": "RedHat", 16 | "operatingsystemrelease": [ 17 | "5", 18 | "6", 19 | "7" 20 | ] 21 | }, 22 | { 23 | "operatingsystem": "CentOS", 24 | "operatingsystemrelease": [ 25 | "5", 26 | "6", 27 | "7" 28 | ] 29 | }, 30 | { 31 | "operatingsystem": "OracleLinux", 32 | "operatingsystemrelease": [ 33 | "5", 34 | "6", 35 | "7" 36 | ] 37 | }, 38 | { 39 | "operatingsystem": "Scientific", 40 | "operatingsystemrelease": [ 41 | "5", 42 | "6", 43 | "7" 44 | ] 45 | }, 46 | { 47 | "operatingsystem": "Debian", 48 | "operatingsystemrelease": [ 49 | "6", 50 | "7", 51 | "8" 52 | ] 53 | }, 54 | { 55 | "operatingsystem": "Ubuntu", 56 | "operatingsystemrelease": [ 57 | "10.04", 58 | "12.04", 59 | "14.04" 60 | ] 61 | }, 62 | { 63 | "operatingsystem": "OpenSuSE", 64 | "operatingsystemrelease": [ 65 | "12", 66 | "13" 67 | ] 68 | } 69 | ], 70 | "requirements": [ 71 | { 72 | "name": "pe", 73 | "version_requirement": ">= 3.2.2" 74 | }, 75 | { 76 | "name": "puppet", 77 | "version_requirement": ">=3.2.0 <4.0.0" 78 | } 79 | ] 80 | } 81 | -------------------------------------------------------------------------------- /lib/puppet/reports/logstash.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' if RUBY_VERSION < '1.9.0' 2 | require 'puppet' 3 | require 'socket' 4 | require 'timeout' 5 | require 'json' 6 | require 'yaml' 7 | require 'time' 8 | 9 | unless Puppet.version >= '2.6.5' 10 | fail "This report processor requires Puppet version 2.6.5 or later" 11 | end 12 | 13 | SEPARATOR = [Regexp.escape(File::SEPARATOR.to_s), Regexp.escape(File::ALT_SEPARATOR.to_s)].join 14 | 15 | Puppet::Reports.register_report(:logstash) do 16 | 17 | config_file = File.join([File.dirname(Puppet.settings[:config]), "logstash.yaml"]) 18 | unless File.exist?(config_file) 19 | raise(Puppet::ParseError, "Logstash report config file #{config_file} missing or not readable") 20 | end 21 | CONFIG = YAML.load_file(config_file) 22 | 23 | desc <<-DESCRIPTION 24 | Reports status of Puppet Runs to a Logstash TCP input 25 | DESCRIPTION 26 | 27 | def process 28 | 29 | validate_host(self.host) 30 | 31 | # Push all log lines as a single message 32 | logs = [] 33 | self.logs.each do |log| 34 | logs << log 35 | end 36 | 37 | event = Hash.new 38 | event["host"] = self.host 39 | event["@timestamp"] = Time.now.utc.iso8601 40 | event["@version"] = 1 41 | event["tags"] = ["puppet-#{self.kind}"] 42 | event["message"] = "Puppet run on #{self.host} #{self.status}" 43 | event["logs"] = logs 44 | event["environment"] = self.environment 45 | event["report_format"] = self.report_format 46 | event["puppet_version"] = self.puppet_version 47 | event["configuration_version"] = self.configuration_version 48 | event["status"] = self.status 49 | event["start_time"] = self.logs.first.time.utc.iso8601 50 | event["end_time"] = self.logs.last.time.utc.iso8601 51 | event["metrics"] = {} 52 | metrics.each do |k,v| 53 | event["metrics"][k] = {} 54 | v.values.each do |val| 55 | event["metrics"][k][val[1].tr('[A-Z ]', '[a-z_]')] = val[2] 56 | end 57 | end 58 | 59 | begin 60 | Timeout::timeout(CONFIG[:timeout]) do 61 | json = event.to_json 62 | ls = TCPSocket.new "#{CONFIG[:host]}" , CONFIG[:port] 63 | ls.puts json 64 | ls.close 65 | end 66 | rescue Exception => e 67 | Puppet.err("Failed to write to #{CONFIG[:host]} on port #{CONFIG[:port]}: #{e.message}") 68 | end 69 | end 70 | 71 | def validate_host(host) 72 | if host =~ Regexp.union(/[#{SEPARATOR}]/, /\A\.\.?\Z/) 73 | raise ArgumentError, "Invalid node name #{host.inspect}" 74 | end 75 | end 76 | module_function :validate_host 77 | end 78 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ARCHIVED 2 | 3 | This project is no longer maintained. 4 | 5 | #Logstash Reporter Puppet module 6 | 7 | ####Table of Contents 8 | 9 | 1. [Overview](#overview) 10 | 2. [Module description - What the module does and why it is useful](#module-description) 11 | 3. [Setup - The basics of getting started with the Logstash Reporter](#setup) 12 | * [The module manages the following](#the-module-manages-the-following) 13 | * [Requirements](#requirements) 14 | 4. [Usage - Configuration options and additional functionality](#usage) 15 | 6. [Limitations - OS compatibility, etc.](#limitations) 16 | 7. [Development - Guide for contributing to the module](#development) 17 | 8. [Support - When you need help with this module](#support) 18 | 9. [Credits](#credits) 19 | 20 | 21 | 22 | ##Overview 23 | 24 | This module manages the Logstash reporter which sends puppet reports to Logstash ( http://www.elasticsearch.org/overview/logstash/ ) 25 | 26 | ##Module description 27 | 28 | The logstash_reporter module sets up and configures the reporter 29 | 30 | ##Setup 31 | 32 | ###The module manages the following 33 | 34 | * reporter configuration file. 35 | 36 | ###Requirements 37 | 38 | * `json` 39 | * `yaml` 40 | * Master puppet.conf needs to use the logstash reporter. 41 | ``` 42 | [master] 43 | report = true 44 | reports = logstash 45 | pluginsync = true 46 | ``` 47 | * Agent puppet.conf needs to send the reports to master. 48 | ``` 49 | [agent] 50 | report = true 51 | pluginsync = true 52 | ``` 53 | 54 | ##Usage 55 | 56 | ###Main class 57 | 58 | ####Basic usesage 59 | 60 | ```puppet 61 | class { 'logstash_reporter': 62 | } 63 | ``` 64 | 65 | And have a TCP input configured in logstash 66 | 67 | ``` 68 | input { 69 | tcp { 70 | type => "puppet-report" 71 | port => 5999 72 | codec => json 73 | } 74 | } 75 | ``` 76 | 77 | ####Separate logstash host and port 78 | 79 | ```puppet 80 | class { 'logstash_reporter': 81 | logstash_host => '123.123.123.123', 82 | logstash_port => 1234, 83 | } 84 | ``` 85 | 86 | ##Limitations 87 | 88 | This module has been built on and tested against Puppet 3.2 and higher. 89 | 90 | The module has been tested on: 91 | 92 | * Debian 6/7/8 93 | * CentOS 6/7 94 | * Ubuntu 12.04, 14.04 95 | * OpenSuSE 13.x 96 | 97 | Other distro's that have been reported to work: 98 | 99 | * RHEL 6 100 | * OracleLinux 6 101 | * Scientific 6 102 | 103 | Testing on other platforms has been light and cannot be guaranteed. 104 | 105 | ##Development 106 | 107 | ##Support 108 | 109 | Need help? Join us in [#logstash](https://webchat.freenode.net?channels=%23logstash) on Freenode IRC or go to our [Discuss](http://discuss.elastic.co/) groups 110 | 111 | ##Credits 112 | 113 | This module was originally posted by John Vincent at https://github.com/lusis/puppet-logstash-reporter 114 | -------------------------------------------------------------------------------- /spec/fixtures/report2.6.x.yaml: -------------------------------------------------------------------------------- 1 | --- !ruby/object:Puppet::Transaction::Report 2 | external_times: 3 | !ruby/sym config_retrieval: 0.170313835144043 4 | host: ubuntu1004desktop.localdomain 5 | logs: 6 | - !ruby/object:Puppet::Util::Log 7 | level: !ruby/sym debug 8 | message: Using cached certificate for ca 9 | source: Puppet 10 | tags: 11 | - debug 12 | time: 2010-09-23 15:44:06.244173 -07:00 13 | version: &id001 2.6.1 14 | - !ruby/object:Puppet::Util::Log 15 | level: !ruby/sym debug 16 | message: Using cached certificate for ubuntu1004desktop.localdomain 17 | source: Puppet 18 | tags: 19 | - debug 20 | time: 2010-09-23 15:44:06.244764 -07:00 21 | version: *id001 22 | - !ruby/object:Puppet::Util::Log 23 | level: !ruby/sym debug 24 | message: Using cached certificate_revocation_list for ca 25 | source: Puppet 26 | tags: 27 | - debug 28 | time: 2010-09-23 15:44:06.245677 -07:00 29 | version: *id001 30 | - !ruby/object:Puppet::Util::Log 31 | level: !ruby/sym debug 32 | message: "catalog supports formats: b64_zlib_yaml dot marshal pson raw yaml; using pson" 33 | source: Puppet 34 | tags: 35 | - debug 36 | time: 2010-09-23 15:44:06.247069 -07:00 37 | version: *id001 38 | - !ruby/object:Puppet::Util::Log 39 | level: !ruby/sym info 40 | message: Caching catalog for ubuntu1004desktop.localdomain 41 | source: Puppet 42 | tags: 43 | - info 44 | time: 2010-09-23 15:44:06.409109 -07:00 45 | version: *id001 46 | - !ruby/object:Puppet::Util::Log 47 | level: !ruby/sym debug 48 | message: Creating default schedules 49 | source: Puppet 50 | tags: 51 | - debug 52 | time: 2010-09-23 15:44:06.418755 -07:00 53 | version: *id001 54 | - !ruby/object:Puppet::Util::Log 55 | level: !ruby/sym debug 56 | message: Loaded state in 0.00 seconds 57 | source: Puppet 58 | tags: 59 | - debug 60 | time: 2010-09-23 15:44:06.427441 -07:00 61 | version: *id001 62 | - !ruby/object:Puppet::Util::Log 63 | level: !ruby/sym info 64 | message: Applying configuration version '1285281846' 65 | source: Puppet 66 | tags: 67 | - info 68 | time: 2010-09-23 15:44:06.429532 -07:00 69 | version: *id001 70 | metrics: 71 | time: !ruby/object:Puppet::Util::Metric 72 | label: Time 73 | name: time 74 | values: 75 | - - config_retrieval 76 | - Config retrieval 77 | - 0.170313835144043 78 | - - schedule 79 | - Schedule 80 | - 0.00077 81 | - - filebucket 82 | - Filebucket 83 | - 0.000166 84 | resources: !ruby/object:Puppet::Util::Metric 85 | label: Resources 86 | name: resources 87 | values: 88 | - - !ruby/sym total 89 | - Total 90 | - 7 91 | events: !ruby/object:Puppet::Util::Metric 92 | label: Events 93 | name: events 94 | values: 95 | - - !ruby/sym total 96 | - Total 97 | - 0 98 | changes: !ruby/object:Puppet::Util::Metric 99 | label: Changes 100 | name: changes 101 | values: 102 | - - !ruby/sym total 103 | - Total 104 | - 0 105 | resource_statuses: 106 | "Schedule[monthly]": !ruby/object:Puppet::Resource::Status 107 | evaluation_time: 0.000121 108 | events: [] 109 | file: 110 | line: 111 | resource: "Schedule[monthly]" 112 | source_description: "/Schedule[monthly]" 113 | tags: 114 | - schedule 115 | - monthly 116 | time: 2010-09-23 15:44:06.430577 -07:00 117 | version: 1285281846 118 | "Filebucket[puppet]": !ruby/object:Puppet::Resource::Status 119 | evaluation_time: 0.000166 120 | events: [] 121 | file: 122 | line: 123 | resource: "Filebucket[puppet]" 124 | source_description: "/Filebucket[puppet]" 125 | tags: 126 | - filebucket 127 | - puppet 128 | time: 2010-09-23 15:44:06.430998 -07:00 129 | version: 1285281846 130 | "Schedule[never]": !ruby/object:Puppet::Resource::Status 131 | evaluation_time: 0.000119 132 | events: [] 133 | file: 134 | line: 135 | resource: "Schedule[never]" 136 | source_description: "/Schedule[never]" 137 | tags: 138 | - schedule 139 | - never 140 | time: 2010-09-23 15:44:06.433034 -07:00 141 | version: 1285281846 142 | "Schedule[weekly]": !ruby/object:Puppet::Resource::Status 143 | evaluation_time: 0.000118 144 | events: [] 145 | file: 146 | line: 147 | resource: "Schedule[weekly]" 148 | source_description: "/Schedule[weekly]" 149 | tags: 150 | - schedule 151 | - weekly 152 | time: 2010-09-23 15:44:06.431443 -07:00 153 | version: 1285281846 154 | "Schedule[puppet]": !ruby/object:Puppet::Resource::Status 155 | evaluation_time: 0.000129 156 | events: [] 157 | file: 158 | line: 159 | resource: "Schedule[puppet]" 160 | source_description: "/Schedule[puppet]" 161 | tags: 162 | - schedule 163 | - puppet 164 | time: 2010-09-23 15:44:06.432626 -07:00 165 | version: 1285281846 166 | "Schedule[daily]": !ruby/object:Puppet::Resource::Status 167 | evaluation_time: 0.000154 168 | events: [] 169 | file: 170 | line: 171 | resource: "Schedule[daily]" 172 | source_description: "/Schedule[daily]" 173 | tags: 174 | - schedule 175 | - daily 176 | time: 2010-09-23 15:44:06.430130 -07:00 177 | version: 1285281846 178 | "Schedule[hourly]": !ruby/object:Puppet::Resource::Status 179 | evaluation_time: 0.000129 180 | events: [] 181 | file: 182 | line: 183 | resource: "Schedule[hourly]" 184 | source_description: "/Schedule[hourly]" 185 | tags: 186 | - schedule 187 | - hourly 188 | time: 2010-09-23 15:44:06.432185 -07:00 189 | version: 1285281846 190 | time: 2010-09-23 15:44:05.894401 -07:00 191 | --------------------------------------------------------------------------------