Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- convert sentry-raven to use sentry-ruby #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 31 additions & 34 deletions lib/puppet/reports/sentry.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
require 'puppet'
require 'yaml'
# require 'pp'

begin
require 'rubygems'
Expand All @@ -9,23 +8,22 @@
end

begin
require 'raven'
require 'sentry-ruby'
rescue LoadError => e
Puppet.err "You need the `sentry-raven` gem installed on the puppetmaster to send reports to Sentry"
Puppet.err "You need the `sentry-ruby` gem installed on the puppetmaster to send reports to Sentry"
end


Puppet::Reports.register_report(:sentry) do
# Description
desc = 'Puppet reporter designed to send failed runs to a sentry server'
desc = 'Puppet reporter designed to send failed runs to a Sentry server'

# Those are the log levels used by Puppet::Util::Log
# @levels = [:debug,:info,:notice,:warning,:err,:alert,:emerg,:crit]
# (https://github.com/puppetlabs/puppet/blob/3f1bbd2ec31bc7be8a7626c23de8089ee638bad4/lib/puppet/util/log.rb#L16)
# Those are the log levels we want to have alerts for:
# Nothing that is less that :info should go to Sentry
# Nothing that is less than :info should go to Sentry
ALERT_ON = [:warning,:err,:alert,:emerg,:crit]

# Load the config else error
# The file sentry.yaml should be in the root of the environment
config_path = File.join([File.dirname(Puppet.settings[:config]), "sentry.yaml"])
Expand Down Expand Up @@ -58,7 +56,7 @@ def process
@host = self.host
end


if self.respond_to?(:puppet_version)
@puppet_version = self.puppet_version
end
Expand All @@ -67,29 +65,28 @@ def process
@status = self.status
end

# Configure raven
Raven.configure do |config|
config.dsn = CONFIG[:sentry_dsn]
config.current_environment = @environment
end

# Get the important looking stuff to sentry
# pp self
self.logs.each do |log|
if ALERT_ON.include? log.level
Raven.captureMessage(log.message, {
:server_name => @host,
:tags => {
'status' => @status,
'version' => @puppet_version,
},
:extra => {
'source' => log.source,
'line' => log.line,
'file' => log.file,
},
})
end
end
end
# Initialize Sentry with DSN and current environment
Sentry.init do |config|
config.dsn = CONFIG[:sentry_dsn]
config.environment = @environment
end

# Get the important looking stuff to Sentry
self.logs.each do |log|
if ALERT_ON.include?(log.level)
Sentry.capture_message(log.message, {
server_name: @host,
tags: {
'status' => @status,
'version' => @puppet_version
},
extra: {
'source' => log.source,
'line' => log.line,
'file' => log.file
}
})
end
end
end
end