Class: Fluent::AppdynamicsInput
- Inherits:
-
Input
- Object
- Input
- Fluent::AppdynamicsInput
- Defined in:
- lib/fluent/plugin/in_appdynamics.rb
Overview
Read trap messages as events in to fluentd
Instance Method Summary collapse
- #appdynamicsEnd(startTime, endTime) ⇒ Object
- #appdynamicsEntEnd(entityId) ⇒ Object
-
#configure(conf) ⇒ Object
Load internal and external configs.
-
#initialize ⇒ AppdynamicsInput
constructor
Initialize and bring in dependencies.
-
#input ⇒ Object
Start appdynamics Trap listener Add the code to run this.
- #run ⇒ Object
-
#shutdown ⇒ Object
Stop Listener and cleanup any open connections.
-
#start ⇒ Object
def configure.
-
#to_utf8(str) ⇒ Object
function to UTF8 encode.
Constructor Details
#initialize ⇒ AppdynamicsInput
Initialize and bring in dependencies
26 27 28 29 30 31 32 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 26 def initialize super require 'json' require 'rest-client' require 'pp' # Add any other dependencies end |
Instance Method Details
#appdynamicsEnd(startTime, endTime) ⇒ Object
38 39 40 41 42 43 44 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 38 def appdynamicsEnd(startTime,endTime) # Setup URL Resource # Sample https://ep/controller/rest/applications/Prod/problems/healthrule-violations?time-range-type=BETWEEN_TIMES&output=JSON&start-time=1426270552990&end-time=1426270553000 @url = @endpoint.to_s + "problems/healthrule-violations?time-range-type=BETWEEN_TIMES&output=JSON" + "&start-time=" + startTime.to_s + "&end-time=" + endTime.to_s $log.info @url RestClient::Resource.new(@url,@user+"@"+@account,@pass) end |
#appdynamicsEntEnd(entityId) ⇒ Object
45 46 47 48 49 50 51 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 45 def appdynamicsEntEnd(entityId) # Setup URL Resource # Sample https://ep/controller/rest/applications/Prod/nodes/81376?output=JSON @urlEntity = @endpoint.to_s + "nodes/" + entityId.to_s + "?output=JSON" $log.info @urlEntity RestClient::Resource.new(@urlEntity,@user+"@"+@account,@pass) end |
#configure(conf) ⇒ Object
Load internal and external configs
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 35 def configure(conf) super @conf = conf def appdynamicsEnd(startTime,endTime) # Setup URL Resource # Sample https://ep/controller/rest/applications/Prod/problems/healthrule-violations?time-range-type=BETWEEN_TIMES&output=JSON&start-time=1426270552990&end-time=1426270553000 @url = @endpoint.to_s + "problems/healthrule-violations?time-range-type=BETWEEN_TIMES&output=JSON" + "&start-time=" + startTime.to_s + "&end-time=" + endTime.to_s $log.info @url RestClient::Resource.new(@url,@user+"@"+@account,@pass) end def appdynamicsEntEnd(entityId) # Setup URL Resource # Sample https://ep/controller/rest/applications/Prod/nodes/81376?output=JSON @urlEntity = @endpoint.to_s + "nodes/" + entityId.to_s + "?output=JSON" $log.info @urlEntity RestClient::Resource.new(@urlEntity,@user+"@"+@account,@pass) end # TO DO Add code to choke if config parameters are not there end |
#input ⇒ Object
Start appdynamics Trap listener Add the code to run this
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 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 78 def input alertStartTime = (Engine.now.to_f * 1000).to_i - @interval.to_i $log.info "appdynamics :: Polling alerts for time period: #{alertStartTime.to_i} - #{(Engine.now.to_f * 1000).to_i}" # Post to Appdynamics and parse results begin responsePost=appdynamicsEnd(alertStartTime,(Engine.now.to_f * 1000).to_i).get rescue Exception => e $log.info e. $log.info e.backtrace.inspect end # body is an array of hashes body = JSON.parse(responsePost.body) body.each_with_index {|val, index| #pp val $log.debug val if @include_raw.to_s == "true" # Deep copy rawObj=val.clone #val << { "raw" => "#rawObj" } val["raw"]=rawObj end # Need to do another call to get the hostname if ((val["affectedEntityDefinition"] || {})["entityId"] != nil) then begin responsePostAffEnt=appdynamicsEntEnd(val["affectedEntityDefinition"]["entityId"]).get bodyAffEntity = JSON.parse(responsePostAffEnt.body) val["AffectedEntityName"]=bodyAffEntity[0]["name"] rescue Exception => e $log.info e. $log.info e.backtrace.inspect val["TrigerredEntityName"]="" end #pp bodyAffEntity["name"] #val["AffectedEntityName"]=bodyAffEntity["name"] end if ((val["triggeredEntityDefinition"] || {})["entityId"] != nil) then begin responsePostTrigEnt=appdynamicsEntEnd(val["triggeredEntityDefinition"]["entityId"]).get bodyTrigEnt = JSON.parse(responsePostTrigEnt.body) val["TrigerredEntityName"]=bodyTrigEnt[0]["name"] rescue Exception => e $log.info e. $log.info e.backtrace.inspect val["TrigerredEntityName"]="" end #val["TrigerredEntityName"]=bodyTrigEnt["name"] end #puts "#{val} => #{index}" $log.info val Engine.emit(@tag, val['startTimeInMillis'].to_i,val) } #pp body.class end |
#run ⇒ Object
71 72 73 74 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 71 def run @loop.run $log.info "Running appdynamics Input" end |
#shutdown ⇒ Object
Stop Listener and cleanup any open connections.
65 66 67 68 69 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 65 def shutdown super @loop.stop @thread.join end |
#start ⇒ Object
def configure
55 56 57 58 59 60 61 62 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 55 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 appdynamics poller, interval #{@interval}" end |
#to_utf8(str) ⇒ Object
function to UTF8 encode
19 20 21 22 23 |
# File 'lib/fluent/plugin/in_appdynamics.rb', line 19 def to_utf8(str) str = str.force_encoding('UTF-8') return str if str.valid_encoding? str.encode("UTF-8", 'binary', invalid: :replace, undef: :replace, replace: '') end |