Gergő Tisza has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/263027

Change subject: Improve sentry plugin
......................................................................

Improve sentry plugin

Clean up whitespace + make parameters less cumbersome

Bug: T85239
Change-Id: I74e63e6b41af13389ba7be888f25286b3a508ec2
---
M logstash/outputs/sentry.rb
1 file changed, 37 insertions(+), 50 deletions(-)


  git pull 
ssh://gerrit.wikimedia.org:29418/operations/software/logstash/plugins 
refs/changes/27/263027/1

diff --git a/logstash/outputs/sentry.rb b/logstash/outputs/sentry.rb
index 584918b..e3e673f 100644
--- a/logstash/outputs/sentry.rb
+++ b/logstash/outputs/sentry.rb
@@ -9,44 +9,33 @@
 # Sentry is a modern error logging and aggregation platform.
 # * https://getsentry.com/
 #
-# It’s important to note that Sentry should not be thought of as a log stream, 
but as an aggregator. 
+# It’s important to note that Sentry should not be thought of as a log stream, 
but as an aggregator.
 # It fits somewhere in-between a simple metrics solution (such as Graphite) 
and a full-on log stream aggregator (like Logstash).
 #
 # Generate and inform your client key (Settings -> Client key)
-# The client key has this form  * https://[key]:[secret]@[host]/[project_id] *
 #
-# More informations : 
+# More informations :
 # * https://sentry.readthedocs.org/en/latest/
 
 
 class LogStash::Outputs::Sentry < LogStash::Outputs::Base
- 
+
   config_name 'sentry'
-  
-  
-  # The key of the client key 
-  config :key, :validate => :string, :required => true
-  
-  # The secret  of the client key
-  config :secret, :validate => :string, :required => true
-  
-  # The project id of the client key
-  config :project_id, :validate => :string, :required => true
-  
-  # The Sentry host 
-  config :host, :validate => :string, :default => "https://app.getsentry.com";, 
:required => false 
-  
+
+  # The Sentry DSN
+  config :dsn, :validate => :string, :required => true
+
   # This sets the message value in Sentry (the title of your event)
   config :msg, :validate => :string, :default => "Message from logstash", 
:required => false
-  
+
   # This sets the level value in Sentry (the level tag)
   config :level_tag, :validate => :string, :default => "error", :required => 
false
-  
-  # Is the protocole https ? By default yes (host is 
"https://app.getsentry.com";) 
-  # If you have installed Sentry in your own machine, maybe you do use http, 
-  # so you have to disable ssl ( "use_ssl" => false ) 
-  config :use_ssl, :validate => :boolean, :default => true, :required => false 
-  
+
+  # Is the protocole https ? By default yes (host is 
"https://app.getsentry.com";)
+  # If you have installed Sentry in your own machine, maybe you do use http,
+  # so you have to disable ssl ( "use_ssl" => false )
+  config :use_ssl, :validate => :boolean, :default => true, :required => false
+
   # If set to true automatically map all logstash defined fields to Sentry 
extra fields.
   # As an example, the logstash event:
   # [source,ruby]
@@ -69,67 +58,65 @@
   #      "nested_field": {
   #                        "key": "value"
   #                      }
-  #    }   
+  #    }
   config :fields_to_tags, :validate => :boolean, :default => false, :required 
=> false
- 
+
   public
   def register
     require 'net/https'
     require 'uri'
-    
-    @url = "#{host}/api/#{project_id}/store/"
-    @uri = URI.parse(@url)
+
+    @uri = URI.parse(@sentry_dsn)
 
     @client = Net::HTTP.new(@uri.host, @uri.port)
-    @client.use_ssl = use_ssl
+    @client.use_ssl = @uri.scheme.downcase === 'https'
     @client.verify_mode = OpenSSL::SSL::VERIFY_NONE
- 
-   @logger.debug("Client", :client => @client.inspect)
+
+    @logger.debug("Client", :client => @client.inspect)
   end
- 
+
   public
   def receive(event)
     return unless output?(event)
- 
+
     require 'securerandom'
- 
+
     packet = {
       :event_id => SecureRandom.uuid.gsub('-', ''),
       :timestamp => event['@timestamp'],
       :message => event["#{msg}"] || "#{msg}"
    }
 
-    packet[:level] = "#{level_tag}" 
+    packet[:level] = "#{level_tag}"
     packet[:platform] = 'logstash'
-    packet[:server_name] = event['host']    
-    packet[:extra] = event.to_hash   
-   
+    packet[:server_name] = event['host']
+    packet[:extra] = event.to_hash
+
     if fields_to_tags == true 
        packet[:tags] = event.to_hash
-    end 
+    end
 
     @logger.debug("Sentry packet", :sentry_packet => packet)
- 
+
     auth_header = "Sentry sentry_version=5," +
       "sentry_client=raven_logstash/1.0," +
       "sentry_timestamp=#{event['@timestamp'].to_i}," +
-      "sentry_key=#{@key}," +
-      "sentry_secret=#{@secret}"
- 
+      "sentry_key=#{@uri.user}," +
+      "sentry_secret=#{@uri.password}"
+
     request = Net::HTTP::Post.new(@uri.path)
- 
+
     begin
       request.body = packet.to_json
       request.add_field('X-Sentry-Auth', auth_header)
- 
+
       response = @client.request(request)
- 
+
       @logger.info("Sentry response", :request => request.inspect, :response 
=> response.inspect)
- 
+
       raise unless response.code == '200'
     rescue Exception => e
       @logger.warn("Unhandled exception", :request => request.inspect, 
:response => response.inspect, :exception => e.inspect)
     end
   end
 end
-

-- 
To view, visit https://gerrit.wikimedia.org/r/263027
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I74e63e6b41af13389ba7be888f25286b3a508ec2
Gerrit-PatchSet: 1
Gerrit-Project: operations/software/logstash/plugins
Gerrit-Branch: master
Gerrit-Owner: Gergő Tisza <gti...@wikimedia.org>

_______________________________________________
MediaWiki-commits mailing list
MediaWiki-commits@lists.wikimedia.org
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to