sensu 0.9.9.beta.3 → 0.9.9.beta.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  module Sensu
2
2
  unless defined?(Sensu::VERSION)
3
- VERSION = '0.9.9.beta.3'
3
+ VERSION = '0.9.9.beta.4'
4
4
 
5
5
  DEFAULT_OPTIONS = {
6
6
  :config_file => '/etc/sensu/config.json',
@@ -0,0 +1,11 @@
1
+ module Sensu
2
+ module Sandbox
3
+ def self.eval(expression, value=nil)
4
+ result = Proc.new do
5
+ $SAFE = 4
6
+ Kernel.eval(expression)
7
+ end
8
+ result.call
9
+ end
10
+ end
11
+ end
data/lib/sensu/server.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require File.join(File.dirname(__FILE__), 'base')
2
2
  require File.join(File.dirname(__FILE__), 'redis')
3
3
  require File.join(File.dirname(__FILE__), 'socket')
4
+ require File.join(File.dirname(__FILE__), 'sandbox')
4
5
 
5
6
  module Sensu
6
7
  class Server
@@ -121,10 +122,30 @@ module Sensu
121
122
  subdue && subdue_at == (check[:subdue][:at] || 'handler').to_sym
122
123
  end
123
124
 
125
+ def filter_attributes_match?(hash_one, hash_two)
126
+ hash_one.keys.all? do |key|
127
+ case
128
+ when hash_one[key] == hash_two[key]
129
+ true
130
+ when hash_one[key].is_a?(Hash) && hash_two[key].is_a?(Hash)
131
+ filter_attributes_match?(hash_one[key], hash_two[key])
132
+ when hash_one[key].is_a?(String) && hash_one[key].start_with?('eval: ')
133
+ begin
134
+ expression = hash_one[key].gsub(/^eval:(\s+)?/, '')
135
+ !!Sandbox.eval(expression, hash_two[key])
136
+ rescue
137
+ false
138
+ end
139
+ else
140
+ false
141
+ end
142
+ end
143
+ end
144
+
124
145
  def event_filtered?(filter_name, event)
125
146
  if @settings.filter_exists?(filter_name)
126
147
  filter = @settings[:filters][filter_name]
127
- matched = hash_values_equal?(filter[:attributes], event)
148
+ matched = filter_attributes_match?(filter[:attributes], event)
128
149
  filter[:negate] ? matched : !matched
129
150
  else
130
151
  @logger.error('unknown filter', {
@@ -57,19 +57,5 @@ module Sensu
57
57
  diff
58
58
  end
59
59
  end
60
-
61
- def hash_values_equal?(hash_one, hash_two)
62
- hash_one.keys.all? do |key|
63
- if hash_one[key] == hash_two[key]
64
- true
65
- else
66
- if hash_one[key].is_a?(Hash) && hash_two[key].is_a?(Hash)
67
- hash_values_equal?(hash_one[key], hash_two[key])
68
- else
69
- false
70
- end
71
- end
72
- end
73
- end
74
60
  end
75
61
  end
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu
3
3
  version: !ruby/object:Gem::Version
4
- hash: 2679144457
4
+ hash: 1725596175
5
5
  prerelease: true
6
6
  segments:
7
7
  - 0
8
8
  - 9
9
9
  - 9
10
10
  - beta
11
- - 3
12
- version: 0.9.9.beta.3
11
+ - 4
12
+ version: 0.9.9.beta.4
13
13
  platform: ruby
14
14
  authors:
15
15
  - Sean Porter
@@ -18,7 +18,7 @@ autorequire:
18
18
  bindir: bin
19
19
  cert_chain: []
20
20
 
21
- date: 2013-01-11 00:00:00 -08:00
21
+ date: 2013-01-13 00:00:00 -08:00
22
22
  default_executable:
23
23
  dependencies:
24
24
  - !ruby/object:Gem::Dependency
@@ -192,6 +192,7 @@ files:
192
192
  - lib/sensu/socket.rb
193
193
  - lib/sensu/constants.rb
194
194
  - lib/sensu/api.rb
195
+ - lib/sensu/sandbox.rb
195
196
  - lib/sensu/settings.rb
196
197
  - lib/sensu/redis.rb
197
198
  - lib/sensu/server.rb