Class: Sqreen::Rules::CrawlerUserAgentMatchesMetricsCB

Inherits:
MatcherRuleCB show all
Defined in:
lib/sqreen/rules/crawler_user_agent_matches_metrics_cb.rb

Overview

Look for crawlers and post them in metrics

Constant Summary collapse

CRAWLER_CATEGORY =
'crawler'.freeze

Constants included from Matcher

Matcher::ANYWHERE_OPT, Matcher::MATCH_PREDICATE

Constants inherited from RuleCB

RuleCB::DEFAULT_PAYLOAD

Constants included from CallCountable

CallCountable::COUNT_CALLS, CallCountable::FAILING, CallCountable::POST, CallCountable::PRE

Constants inherited from CB

CB::DEFAULT_PRIORITY

Instance Attribute Summary

Attributes included from Matcher

#min_size

Attributes inherited from RuleCB

#block, #payload_tpl, #test

Attributes included from CallCountable

#call_count_interval, #call_counts

Attributes inherited from FrameworkCB

#framework

Attributes inherited from CB

#klass, #method, #overtimeable

Instance Method Summary collapse

Methods inherited from MatcherRuleCB

#initialize

Methods included from Matcher

#match, #prepare, prepare_re_pattern

Methods inherited from RuleCB

#advise_action, #initialize, #overtime!, #priority, #record_event, #record_exception, #rule_name, #rulespack_id

Methods included from CallCountable

#count_callback_calls, #failing_with_count, #post_with_count, #pre_with_count

Methods included from Conditionable

#condition_callbacks, #failing_with_conditions, #post_with_conditions, #pre_with_conditions

Methods inherited from FrameworkCB

#record_observation, #whitelisted?

Methods inherited from CB

#failing?, #framework, #initialize, #overtime!, #post?, #pre?, #priority, #to_s, #whitelisted?

Constructor Details

This class inherits a constructor from Sqreen::Rules::MatcherRuleCB

Instance Method Details

#pre(_inst, _args, _budget = nil, &_block) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/sqreen/rules/crawler_user_agent_matches_metrics_cb.rb', line 15

def pre(_inst, _args, _budget = nil, &_block)
  ua = framework.client_user_agent
  return unless ua
  found = match(ua)
  return unless found
  Sqreen.log.debug { "Found UA #{ua} - found: #{found}" }
  record_observation(CRAWLER_CATEGORY, ua, 1)
  advise_action(nil)
end