Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
  • 4 commits
  • 2 files changed
  • 0 commit comments
  • 1 contributor
Showing with 57 additions and 2 deletions.
  1. +12 −2 lib/puppet/reports/logstash.rb
  2. +45 −0 spec/lib/report_logstash_spec.rb
View
14 lib/puppet/reports/logstash.rb
@@ -44,12 +44,22 @@ def process
event["@fields"]["status"] = self.status
#event["@fields"]["start_time"] = log.time
event["@fields"]["end_time"] = time_now
- event["@fields"]["metrics"] = metrics || {}
+ event["@fields"]["metrics"] = {}
+ metrics.each do |k,v|
+ event["@fields"]["metrics"][k] = {}
+ v.values.each do |val|
+ event["@fields"]["metrics"][k][val[1]] = val[2]
+ end
+ # event["@fields"]["metrics"][k] = v.values
+ # event["@fields"]["metrics"][k] = {
+ # v.name => v.values
+ # }
+ end
event["@fields"]["logs"] = msgs
event["@message"] = "puppet run on #{self.host}"
begin
- report_results event.to_json
+ report_results JSON.pretty_generate(event)
rescue Exception => e
Puppet.err "Failed to write to logstash: #{e.message}"
end
View
45 spec/lib/report_logstash_spec.rb
@@ -0,0 +1,45 @@
+require 'rspec-puppet'
+require 'rspec/mocks'
+require 'rspec/mocks/standalone'
+require 'puppet/reports'
+require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'puppet', 'reports', 'logstash.rb')
+
+logstash = Puppet::Reports.report(:logstash)
+
+module MockLogStashReport
+ attr_reader :report_results_calls
+ attr_reader :report_result
+ def report_results(event)
+ @report_result = event
+ super(event)
+ @report_results_calls = @report_results_calls||0 + 1
+ end
+ def time_now
+ "Mon Mar 04 16:27:40 +0000 2013"
+ end
+end
+
+describe logstash do
+ def report_data
+ JSON.parse(@processor.report_result)
+ end
+
+ before(:each) do
+ @processor = Puppet::Transaction::Report.new("apply")
+ @processor.extend(Puppet::Reports.report(:logstash))
+ @processor.extend(MockLogStashReport)
+ end
+ it 'should be able to process' do
+ @processor.process
+ @processor.report_results_calls.should eql(1)
+ exp = {
+ "@fields" => {"report_format"=>3, "metrics"=>{}, "puppet_version"=>"3.1.0", "logs"=>[], "status"=>"failed", "end_time"=>"Mon Mar 04 16:27:40 +0000 2013", "environment"=>nil},
+ "@source" => "puppet://ldn-dev-tdoran.youdevise.com",
+ "@source_host" => "ldn-dev-tdoran.youdevise.com",
+ "@source_path" => "/home/tdoran/code/git/puppet/modules/puppetmaster/spec/lib/../../lib/puppet/reports/logstash.rb",
+ "@tags" => ["puppet-apply"]
+ }
+ report_data.should == exp
+ end
+end
+

No commit comments for this range

Something went wrong with that request. Please try again.