Class: LogglyOutput
- Inherits:
-
Fluent::Output
- Object
- Fluent::Output
- LogglyOutput
- Defined in:
- lib/fluent/plugin/out_loggly.rb
Overview
Copyright © 2012 Patrik Antonsson
Licensed to the Apache Software Foundation (ASF) under one
or more contributor license agreements. See the NOTICE file
distributed with this work for additional information
regarding copyright ownership. The ASF licenses this file
to you under the Apache License, Version 2.0 (the
"License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing,
software distributed under the License is distributed on an
"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express or implied. See the License for the
specific language governing permissions and limitations
under the License.
Instance Method Summary collapse
- #configure(conf) ⇒ Object
- #emit(tag, es, chain) ⇒ Object
- #pick_uri(record) ⇒ Object
- #shutdown ⇒ Object
- #start ⇒ Object
Instance Method Details
#configure(conf) ⇒ Object
28 29 30 31 |
# File 'lib/fluent/plugin/out_loggly.rb', line 28 def configure(conf) super $log.debug "Configured loggly url: #{@loggly_url}" end |
#emit(tag, es, chain) ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
# File 'lib/fluent/plugin/out_loggly.rb', line 58 def emit(tag, es, chain) chain.next es.each {|time,record| record_json = Yajl::Encoder.encode(record) $log.debug "Record sent #{record_json}" uri = pick_uri(record) post = Net::HTTP::Post.new uri.path post.body = record_json begin response = @http.request uri, post $log.debug "HTTP Response code #{response.code}" if response.code != '200' $log.error "Received HTTP #{response.code} from #{uri}: #{response.body}" end rescue => e $log.error "Error posting to #{uri}: #{e}" end } end |
#pick_uri(record) ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/fluent/plugin/out_loggly.rb', line 40 def pick_uri(record) # if kubernetes pod has loggly url as annotation, use it if record.dig('kubernetes', 'annotations', 'solarwinds_io/loggly_url') url = record['kubernetes']['annotations']['solarwinds_io/loggly_url'] # else if kubernetes namespace has papertrail destination as annotation, use it elsif record.dig('kubernetes', 'namespace_annotations', 'solarwinds_io/loggly_url') url = record['kubernetes']['namespace_annotations']['solarwinds_io/loggly_url'] # else use pre-configured destination else url = @loggly_url end URI url end |
#shutdown ⇒ Object
54 55 56 |
# File 'lib/fluent/plugin/out_loggly.rb', line 54 def shutdown super end |
#start ⇒ Object
33 34 35 36 37 38 |
# File 'lib/fluent/plugin/out_loggly.rb', line 33 def start super require 'net/http/persistent' @http = Net::HTTP::Persistent.new 'fluentd-plugin-loggly', :ENV @http.headers['Content-Type'] = 'application/json' end |