reacter 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/lib/reacter/agents/filter.rb +48 -7
  2. metadata +9 -9
@@ -5,18 +5,59 @@ require 'reacter/agent'
5
5
 
6
6
  class Reacter
7
7
  class FilterAgent < Agent
8
+ def initialize()
9
+ super
10
+ @@_rxcache = {}
11
+ end
12
+
8
13
  def received(message)
9
- if @config['sources']
10
- sources = @config['sources'].keys()
14
+ if @config['sources'].is_a?(Hash)
15
+ # config not found, drop
16
+ return false if @config['sources'].empty?
17
+
18
+ @config['sources'].each do |sources, metrics|
19
+ sources = [*sources]
20
+ metrics = [*metrics]
11
21
 
12
- # fall through if neither default nor our host specifically is named
13
- return false unless (@config['sources'].include?('default') or @config['sources'].include?(message.source))
14
22
 
15
- # fall through if the metric is not in either default our the current source's filter
16
- return false unless (@config['sources']['default'].include?(message.metric) or @config['sources'][message.source].include?(message.metric))
23
+ sources.each do |source|
24
+ if source === 'default' or _property_match?(message.source, source)
25
+ # no metrics means all metrics!
26
+ return message if metrics.nil? or metrics.first === true or metrics.empty?
27
+
28
+ metrics.each do |metric|
29
+ if _property_match?(message.metric, metric)
30
+ return message
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
17
36
  end
18
37
 
19
- return message
38
+ return false
20
39
  end
40
+
41
+ private
42
+ def _property_match?(data, test)
43
+ if test.is_a?(String)
44
+ # regex
45
+ if test[0] == '/' and test[-1] == '/'
46
+ @@_rxcache[test[1..-2]] ||= Regexp.new(test[1..-2])
47
+
48
+ if data =~ @@_rxcache[test[1..-2]]
49
+ return true
50
+ end
51
+
52
+ # exact match
53
+ else
54
+ if data === test
55
+ return true
56
+ end
57
+ end
58
+ end
59
+
60
+ return false
61
+ end
21
62
  end
22
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: reacter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2013-03-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: eventmachine
16
- requirement: &20751620 !ruby/object:Gem::Requirement
16
+ requirement: &15680680 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *20751620
24
+ version_requirements: *15680680
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: deep_merge
27
- requirement: &20750220 !ruby/object:Gem::Requirement
27
+ requirement: &16230460 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *20750220
35
+ version_requirements: *16230460
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: hashlib
38
- requirement: &20748940 !ruby/object:Gem::Requirement
38
+ requirement: &15070420 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *20748940
46
+ version_requirements: *15070420
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hiredis
49
- requirement: &20748020 !ruby/object:Gem::Requirement
49
+ requirement: &13732680 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *20748020
57
+ version_requirements: *13732680
58
58
  description: A utility for consuming, transforming, and routing monitoring data from
59
59
  various sources
60
60
  email: ghetzel@outbrain.com