Class: Fluent::CloudWatchTransOutput
- Inherits:
-
Output
- Object
- Output
- Fluent::CloudWatchTransOutput
- Defined in:
- lib/fluent/plugin/out_cloudwatch_transform.rb
Instance Method Summary collapse
-
#configure(conf) ⇒ Object
This method is called before starting.
-
#emit(tag, es, chain) ⇒ Object
This method is called when an event reaches Fluentd.
-
#shutdown ⇒ Object
This method is called when shutting down.
-
#start ⇒ Object
This method is called when starting.
Instance Method Details
#configure(conf) ⇒ Object
This method is called before starting.
11 12 13 |
# File 'lib/fluent/plugin/out_cloudwatch_transform.rb', line 11 def configure(conf) super end |
#emit(tag, es, chain) ⇒ Object
This method is called when an event reaches Fluentd. ‘es’ is a Fluent::EventStream object that includes multiple events. You can use ‘es.each {|time,record| … }’ to retrieve events. ‘chain’ is an object that manages transactions. Call ‘chain.next’ at appropriate points and rollback if it raises an exception.
NOTE! This method is called by Fluentd’s main thread so you should not write slow routine here. It causes Fluentd’s performance degression.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/fluent/plugin/out_cloudwatch_transform.rb', line 32 def emit(tag, es, chain) #tag_parts = tag.split('.') tag_parts = tag.scan( /([^".]+)|"([^"]+)"/ ).flatten.compact # the prefix of tag should be like alert.cloudwatch.raw.*** # so start from tag_parts[3] regionAZ = tag_parts[3] application_name = tag_parts[4] runbook_url = tag_parts[5] chain.next es.each {|time,record| newhash = Hash.new # though there is just one key-value pair in cloudwatch alert record, we use a loop to add context for it. record.each_pair do |singlekey, singlevalue| newhash["event_name"] = singlekey newhash["value"] = singlevalue.to_s newhash["raw"] ={singlekey => singlevalue} end # add more information for the cloudwatch alert = Engine.now # Should be receive_time_input newhash["receive_time_input"]=.to_s newhash["application_name"] = application_name newhash["intermediary_source"] = regionAZ newhash["runbook"] = runbook_url newhash["event_type"] = "alert.cloudwatch" #log the transformed message and emit it $log.info "Tranformed message #{newhash}" Fluent::Engine.emit @tag, time.to_i, newhash } end |
#shutdown ⇒ Object
This method is called when shutting down.
21 22 23 |
# File 'lib/fluent/plugin/out_cloudwatch_transform.rb', line 21 def shutdown super end |
#start ⇒ Object
This method is called when starting.
16 17 18 |
# File 'lib/fluent/plugin/out_cloudwatch_transform.rb', line 16 def start super end |