Class: Fluent::IronioInput
- Inherits:
-
Input
- Object
- Input
- Fluent::IronioInput
- Defined in:
- lib/fluent/plugin/in_ironio.rb
Overview
Read trap messages as events in to fluentd
Instance Method Summary collapse
-
#configure(conf) ⇒ Object
Load internal and external configs.
-
#initialize ⇒ IronioInput
constructor
Initialize and bring in dependencies.
-
#input ⇒ Object
Start SNMP Trap listener.
- #run ⇒ Object
-
#shutdown ⇒ Object
Stop Listener and cleanup any open connections.
-
#start ⇒ Object
def configure.
Constructor Details
#initialize ⇒ IronioInput
Initialize and bring in dependencies
21 22 23 24 25 26 27 |
# File 'lib/fluent/plugin/in_ironio.rb', line 21 def initialize super require 'json' require 'daemons' require 'iron_mq' require 'pp' end |
Instance Method Details
#configure(conf) ⇒ Object
Load internal and external configs
30 31 32 33 34 |
# File 'lib/fluent/plugin/in_ironio.rb', line 30 def configure(conf) super @conf = conf # TO DO Add code to choke if config parameters are not there end |
#input ⇒ Object
Start SNMP Trap listener
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/fluent/plugin/in_ironio.rb', line 58 def input @ironmq = IronMQ::Client.new(token: @token, project_id: @projectId) # do |event| # Get a Queue object @queue = @ironmq.queue(@endpointQueue) # Put a message on the queue #msg = @queue.post("hello world!") # Get a message msg = @queue.get() # Convert to a proper json #rawMsg=CGI::unescape(msg.raw.to_json).gsub(/"alert=/,'').gsub(/}","timeout/, '},"timeout') #rawMsg=CGI::unescape(jsonhtmlencodedraw).gsub(/"alert=/,'').gsub(/}","timeout/, '},"timeout') # Convert to hash #jsonhtmlencodedraw=JSON.parse(rawMsg, :quirks_mode => false) # => "50's & 60's" jsonhtmlencodedraw=JSON.parse(URI.decode((msg.body.split("="))[1])) #argosHash=Hash.new {} #argosHash['newraw']=jsonhtmlencodedraw # Add raw json jsonhtmlencodedraw.merge!('newraw'=>URI.decode((msg.body.split("="))[1])) #jsonhtmlencodedraw.store('newraw', jsonhtmlencodedraw) #pp argosHash # Add evet_type, intermediary_source, received_time #tag = @tag = Engine.now # Should be received_time_input jsonhtmlencodedraw['receive_time_input']=.to_s jsonhtmlencodedraw['event_type']=@tag.to_s jsonhtmlencodedraw['intermediary_source']=jsonhtmlencodedraw['alert_url'] #jsonhtmlencodedraw.each do |key, value| # jsonhtmlencodedraw[:key]='"' + value + '"' #end $log.info "Incoming message #{jsonhtmlencodedraw}" # Try catch #record = {"value"=> jsonhtmlencodedraw, argosHash.to_json,"tags"=>{"type"=>"alert","application_name"=>jsonhtmlencodedraw["body"]["application_name"]}} begin #Engine.emit('"' + @tag.to_s + '"', '"' + timestamp.to_s + '"' , jsonrawstr) Engine.emit( @tag.to_s , .to_i , jsonhtmlencodedraw) rescue Exception => e puts e. puts e.backtrace.inspect end # Delete the message. Make this configurable if @readOnly == "false" res = msg.delete # or @queue.delete(msg.id) end end |
#run ⇒ Object
52 53 54 55 |
# File 'lib/fluent/plugin/in_ironio.rb', line 52 def run @loop.run $log.info "Running Ironio Input" end |
#shutdown ⇒ Object
Stop Listener and cleanup any open connections.
46 47 48 49 50 |
# File 'lib/fluent/plugin/in_ironio.rb', line 46 def shutdown super @loop.stop @thread.join end |
#start ⇒ Object
def configure
36 37 38 39 40 41 42 43 |
# File 'lib/fluent/plugin/in_ironio.rb', line 36 def start super @loop = Coolio::Loop.new timer_trigger = TimerWatcher.new(@interval, true, &method(:input)) timer_trigger.attach(@loop) @thread = Thread.new(&method(:run)) $log.info "starting ironio poller, interval #{@interval}" end |