├── .github └── pull_request_template.md ├── .gitignore ├── CONTRIBUTORS ├── Gemfile ├── LICENSE ├── README.md ├── Rakefile ├── lib └── logstash │ └── outputs │ └── rollbar.rb ├── logstash-output-rollbar.gemspec └── spec └── outputs └── rollbar_spec.rb /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | ## Description of the change 2 | 3 | > Please include a summary of the change and which issues are fixed. 4 | > Please also include relevant motivation and context. 5 | 6 | ## Type of change 7 | 8 | - [ ] Bug fix (non-breaking change that fixes an issue) 9 | - [ ] New feature (non-breaking change that adds functionality) 10 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 11 | - [ ] Maintenance 12 | - [ ] New release 13 | 14 | ## Related issues 15 | 16 | > ClubHouse stories and GitHub issues (delete irrelevant) 17 | 18 | - Fix [ch] 19 | - Fix #1 20 | 21 | ## Checklists 22 | 23 | ### Development 24 | 25 | - [ ] Lint rules pass locally 26 | - [ ] The code changed/added as part of this pull request has been covered with tests 27 | - [ ] All tests related to the changed code pass in development 28 | 29 | ### Code review 30 | 31 | - [ ] This pull request has a descriptive title and information useful to a reviewer. There may be a screenshot or screencast attached 32 | - [ ] "Ready for review" label attached to the PR and reviewers assigned 33 | - [ ] Issue from task tracker has a link to this pull request 34 | - [ ] Changes have been reviewed by at least one other engineer 35 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | Gemfile.lock 3 | .bundle 4 | vendor 5 | -------------------------------------------------------------------------------- /CONTRIBUTORS: -------------------------------------------------------------------------------- 1 | The following is a list of people who have contributed ideas, code, bug 2 | reports, or in general have helped logstash along its way. 3 | 4 | Contributors: 5 | * Colin Surprenant (colinsurprenant) 6 | * John E. Vincent (lusis) 7 | * Jordan Sissel (jordansissel) 8 | * Kurt Hurtado (kurtado) 9 | * Pier-Hugues Pellerin (ph) 10 | * Richard Pijnenburg (electrical) 11 | 12 | Note: If you've sent us patches, bug reports, or otherwise contributed to 13 | Logstash, and you aren't on the list above and want to be, please let us know 14 | and we'll make sure you're here. Contributions from folks like you are what make 15 | open source awesome. 16 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | gemspec 3 | gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5" 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2012-2015 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 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Logstash Plugin 2 | 3 | This is a plugin for [Logstash](https://github.com/elasticsearch/logstash) that sends events to the [Rollbar](https://www.rollbar.com) error monitoring service. 4 | 5 | It is fully free and fully open source. The license is Apache 2.0, meaning you are pretty much free to use it however you want in whatever way. 6 | 7 | ## Documentation 8 | 9 | Logstash provides infrastructure to automatically generate documentation for this plugin. We use the asciidoc format to write documentation so any comments in the source code will be first converted into asciidoc and then into html. All plugin documentation are placed under one [central location](http://www.elasticsearch.org/guide/en/logstash/current/). 10 | 11 | - For formatting code or config example, you can use the asciidoc `[source,ruby]` directive 12 | - For more asciidoc formatting tips, see the excellent reference here https://github.com/elasticsearch/docs#asciidoc-guide 13 | 14 | ## Need Help? 15 | 16 | Need help? Try #logstash on freenode IRC or the logstash-users@googlegroups.com mailing list. 17 | 18 | ## Developing 19 | 20 | ### 1. Plugin Developement and Testing 21 | 22 | #### Code 23 | - To get started, you'll need JRuby with the Bundler gem installed. 24 | 25 | - Create a new plugin or clone and existing from the GitHub [logstash-plugins](https://github.com/logstash-plugins) organization. 26 | 27 | - Install dependencies 28 | ```sh 29 | bundle install 30 | ``` 31 | 32 | #### Test 33 | 34 | ```sh 35 | bundle exec rspec 36 | ``` 37 | 38 | The Logstash code required to run the tests/specs is specified in the `Gemfile` by the line similar to: 39 | ```ruby 40 | gem "logstash", :github => "elasticsearch/logstash", :branch => "1.5" 41 | ``` 42 | To test against another version or a local Logstash, edit the `Gemfile` to specify an alternative location, for example: 43 | ```ruby 44 | gem "logstash", :github => "elasticsearch/logstash", :ref => "master" 45 | ``` 46 | ```ruby 47 | gem "logstash", :path => "/your/local/logstash" 48 | ``` 49 | 50 | Then update your dependencies and run your tests: 51 | 52 | ```sh 53 | bundle install 54 | bundle exec rspec 55 | ``` 56 | 57 | ### 2. Running your unpublished Plugin in Logstash 58 | 59 | #### 2.1 Run in a local Logstash clone 60 | 61 | - Edit Logstash `tools/Gemfile` and add the local plugin path, for example: 62 | ```ruby 63 | gem "logstash-filter-awesome", :path => "/your/local/logstash-filter-awesome" 64 | ``` 65 | - Update Logstash dependencies 66 | ```sh 67 | rake vendor:gems 68 | ``` 69 | - Run Logstash with your plugin 70 | ```sh 71 | bin/logstash -e 'filter {awesome {}}' 72 | ``` 73 | At this point any modifications to the plugin code will be applied to this local Logstash setup. After modifying the plugin, simply rerun Logstash. 74 | 75 | #### 2.2 Run in an installed Logstash 76 | 77 | - Build your plugin gem 78 | ```sh 79 | gem build logstash-filter-awesome.gemspec 80 | ``` 81 | - Install the plugin from the Logstash home 82 | ```sh 83 | bin/plugin install /your/local/plugin/logstash-filter-awesome.gem 84 | ``` 85 | - Start Logstash and proceed to test the plugin 86 | 87 | ## Contributing 88 | 89 | All contributions are welcome: ideas, patches, documentation, bug reports, complaints, and even something you drew up on a napkin. 90 | 91 | Programming is not a required skill. Whatever you've seen about open source and maintainers or community members saying "send patches or die" - you will not see that here. 92 | 93 | It is more important to me that you are able to contribute. 94 | 95 | For more information about contributing, see the [CONTRIBUTING](https://github.com/elasticsearch/logstash/blob/master/CONTRIBUTING.md) file. 96 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | @files=[] 2 | 3 | task :default do 4 | system("rake -T") 5 | end 6 | 7 | require "logstash/devutils/rake" 8 | -------------------------------------------------------------------------------- /lib/logstash/outputs/rollbar.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | require "logstash/outputs/base" 3 | require "logstash/namespace" 4 | require "json" 5 | 6 | # The Rollbar output will send events to the Rollbar event monitoring service. 7 | # The only required field is a Rollbar project access token with post_server_item 8 | # permissions. If you're already using Rollbar to report errors directly from your 9 | # applications, you can use the same token. 10 | class LogStash::Outputs::Rollbar < LogStash::Outputs::Base 11 | config_name "rollbar" 12 | 13 | # Each of these config values can be specified in the plugin configuration section, in which 14 | # case they'll apply to all events, or you can override them on an event by event basis. 15 | # 16 | # Your default Rollbar access token. You can override this for a specific event by adding 17 | # a "[rollbar][access_token]" field to that event 18 | config :access_token, :validate => :password, :required => true 19 | 20 | # The default Rollbar environment. You can override this for a specific event by adding 21 | # a "[rollbar][environment]" field to that event 22 | config :environment, :validate => :string, :default => 'production' 23 | 24 | # The default level for Rollbar events (info, warning, error) You can override this for a specific 25 | # event by adding a "[rollbar][level]" field to that event 26 | config :level, :validate => ['debug', 'info', 'warning', 'error', 'critical'] , :default => 'info' 27 | 28 | # The default format for the Rollbar "message" or item title. In most cases you'll want to override 29 | # this and build up a message with specific fields from the event. You can override this for a specific 30 | # event by adding a "[rollbar][format]" field to that event. 31 | config :format, :validate => :string, :default => "%{message}" 32 | 33 | # Rollbar API URL endpoint. You shouldn't need to change this. 34 | config :endpoint, :validate => :string, :default => 'https://api.rollbar.com/api/1/item/' 35 | 36 | def hash_recursive 37 | Hash.new do |hash, key| 38 | hash[key] = hash_recursive 39 | end 40 | end 41 | 42 | public 43 | def register 44 | require 'net/https' 45 | require 'uri' 46 | @rb_uri = URI.parse(@endpoint) 47 | @client = Net::HTTP.new(@rb_uri.host, @rb_uri.port) 48 | if @rb_uri.scheme == "https" 49 | @client.use_ssl = true 50 | @client.verify_mode = OpenSSL::SSL::VERIFY_PEER 51 | end 52 | end # def register 53 | 54 | public 55 | def receive(event) 56 | return unless output?(event) 57 | 58 | rb_item = hash_recursive 59 | 60 | # We'll want to remove fields from data without removing them from the original event 61 | data = JSON.parse(event.to_json) 62 | 63 | # 64 | # If logstash has created 'rollbar' fields, we'll use those to populate the item... 65 | # 66 | if data['rollbar'] 67 | 68 | merge_keys = %w{access_token client context environment fingerprint format framework 69 | language level person platform request server title uuid } 70 | merge_keys.each do |key| 71 | data['rollbar'][key] && rb_item['data'][key] = data['rollbar'][key] 72 | end 73 | data.delete('rollbar') 74 | end 75 | 76 | # ...then put whatever's left in 'custom'... 77 | rb_item['data']['custom'] = data 78 | 79 | # ...and finally override the fields that have a specific meaning 80 | rb_item['data']['timestamp'] = event.timestamp.to_i 81 | rb_item['data']['level'] = @level unless rb_item['data'].has_key?('level') 82 | rb_item['data']['environment'] = @environment unless rb_item['data'].has_key?('environment') 83 | 84 | rb_item['data']['notifier']['name'] = 'logstash' 85 | rb_item['data']['notifier']['version'] = Gem.loaded_specs["logstash-output-rollbar"].version 86 | 87 | # Construct the message body using either: 88 | # 89 | # - The default format string defined above "%{message}" 90 | # - The format string specified in the rollbar plugin config section 91 | # - The format string specified in the [rollbar][format] event field 92 | # 93 | format = rb_item['data'].has_key?('format') ? rb_item['data']['format'] : @format 94 | rb_item['data']['body']['message']['body'] = event.sprintf(format) 95 | 96 | # Treat the [rollbar][access_token] field as a special case, since we don't need to 97 | # include it more than once in the Rollbar item 98 | # 99 | if rb_item['data'].has_key?('access_token') 100 | rb_item['access_token'] = rb_item['data']['access_token'] 101 | rb_item['data'].delete('access_token') 102 | else 103 | rb_item['access_token'] = @access_token.value 104 | end 105 | 106 | 107 | @logger.debug("Rollbar Item", :rb_item => rb_item) 108 | 109 | begin 110 | request = Net::HTTP::Post.new(@rb_uri.path) 111 | request.body = JSON.dump(rb_item) 112 | @logger.debug("Rollbar Request", :request => request.body) 113 | response = @client.request(request) 114 | @logger.debug("Rollbar Response", :response => response.body) 115 | 116 | rescue Exception => e 117 | @logger.warn("Rollbar Exception", :rb_error => e.backtrace) 118 | end 119 | end # def receive 120 | end # class LogStash::Outputs::Rollbar 121 | -------------------------------------------------------------------------------- /logstash-output-rollbar.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | 3 | s.name = 'logstash-output-rollbar' 4 | s.version = '0.2.0' 5 | s.licenses = ['Apache License (2.0)'] 6 | s.summary = "The Rollbar Logstash output sends events to the Rollbar error monitoring service." 7 | s.description = "This gem is a logstash plugin. Install using: $LS_HOME/bin/plugin install gemname. This gem is not a stand-alone program" 8 | s.authors = ["Rollbar"] 9 | s.email = 'support@rollbar.com' 10 | s.homepage = "https://github.com/rollbar/logstash-output-rollbar" 11 | s.require_paths = ["lib"] 12 | 13 | # Files 14 | s.files = `git ls-files`.split($\)+::Dir.glob('vendor/*') 15 | 16 | # Tests 17 | s.test_files = s.files.grep(%r{^(test|spec|features)/}) 18 | 19 | # Special flag to let us know this is actually a logstash plugin 20 | s.metadata = { "logstash_plugin" => "true", "logstash_group" => "output" } 21 | 22 | # Gem dependencies 23 | s.add_runtime_dependency 'logstash-core', '>= 1.4.0', '< 2.0.0' 24 | 25 | s.add_development_dependency 'logstash-devutils' 26 | end 27 | 28 | -------------------------------------------------------------------------------- /spec/outputs/rollbar_spec.rb: -------------------------------------------------------------------------------- 1 | require "logstash/devutils/rspec/spec_helper" 2 | --------------------------------------------------------------------------------