Class: Spanx::Actor::Analyzer
- Inherits:
-
Object
- Object
- Spanx::Actor::Analyzer
- Includes:
- Helper::Timing
- Defined in:
- lib/spanx/actor/analyzer.rb
Instance Attribute Summary collapse
-
#blocked_ips ⇒ Object
Returns the value of attribute blocked_ips.
-
#config ⇒ Object
Returns the value of attribute config.
-
#notifiers ⇒ Object
Returns the value of attribute notifiers.
Instance Method Summary collapse
-
#analyze_all_ips ⇒ Object
Look through every IP on the stack.
-
#initialize(config) ⇒ Analyzer
constructor
A new instance of Analyzer.
- #run ⇒ Object
Methods included from Helper::Timing
Constructor Details
#initialize(config) ⇒ Analyzer
Returns a new instance of Analyzer.
16 17 18 19 20 21 22 23 24 |
# File 'lib/spanx/actor/analyzer.rb', line 16 def initialize config @config = config @audit_file = config[:audit_file] @notifiers = [] initialize_notifiers(config) if config[:analyzer][:blocked_ip_notifiers] @blocked_ips = [] @previously_blocked_ips = [] end |
Instance Attribute Details
#blocked_ips ⇒ Object
Returns the value of attribute blocked_ips.
14 15 16 |
# File 'lib/spanx/actor/analyzer.rb', line 14 def blocked_ips @blocked_ips end |
#config ⇒ Object
Returns the value of attribute config.
14 15 16 |
# File 'lib/spanx/actor/analyzer.rb', line 14 def config @config end |
#notifiers ⇒ Object
Returns the value of attribute notifiers.
14 15 16 |
# File 'lib/spanx/actor/analyzer.rb', line 14 def notifiers @notifiers end |
Instance Method Details
#analyze_all_ips ⇒ Object
Look through every IP on the stack. IPs that fulfill a PeriodCheck are pushed onto a redis block list.
39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/spanx/actor/analyzer.rb', line 39 def analyze_all_ips return unless Spanx::IPChecker.enabled? @previously_blocked_ips = Spanx::IPChecker.rate_limited_identifiers ips = Spanx::IPChecker.tracked_identifiers Logger.logging "analyzed #{ips.size} IPs" do ips.each do |ip| blocked_ip = Spanx::IPChecker.new(ip).analyze blocked_ips << blocked_ip if blocked_ip end end Logger.log "blocking [#{blocked_ips.size}] ips" unless blocked_ips.empty? call_notifiers(blocked_ips) blocked_ips.clear end |
#run ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/spanx/actor/analyzer.rb', line 26 def run Thread.new do Thread.current[:name] = "analyzer" Logger.log "starting analyzer loop..." loop do analyze_all_ips() sleep config[:analyzer][:analyze_interval] end end end |