threshold 0.1.2 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/threshold/event_filter.rb +4 -7
- data/lib/threshold/rate_filter.rb +5 -0
- data/lib/threshold/standalone.rb +11 -0
- data/lib/threshold/suppression.rb +5 -0
- data/lib/threshold/thresholds.rb +42 -6
- data/lib/threshold/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4b015463dff88e20e4d903cb380d5e0301b841ee
|
4
|
+
data.tar.gz: 89c5bb791bd7d1899d61b000e68deaa8453d9e07
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 949126bde1abdf49df5489e011d415ca99d1e74c8cbc79ee84ac5f5a8e7807e7b804783d3f76ef881a693044daa2416fe86d6d54ddd9a612b74daf784458f067
|
7
|
+
data.tar.gz: 4804ed44bc0233eec2bf2bdada4d31db030549c060ec4414ec0ab6337aef2a806cbfb75e2ea23056e58cdb43d0748c1aded21008a50c1c2e72c0ed1206ed982c
|
@@ -62,13 +62,6 @@ module Threshold
|
|
62
62
|
entity.comment
|
63
63
|
end
|
64
64
|
|
65
|
-
def track_by_set?(entity)
|
66
|
-
entity.track_by
|
67
|
-
end
|
68
|
-
|
69
|
-
def type_set?(type)
|
70
|
-
entity.type
|
71
|
-
end
|
72
65
|
end
|
73
66
|
|
74
67
|
class EventFilter
|
@@ -97,6 +90,10 @@ module Threshold
|
|
97
90
|
|
98
91
|
private
|
99
92
|
|
93
|
+
def state
|
94
|
+
[@gid, @sid, @type, @track_by, @count, @seconds]
|
95
|
+
end
|
96
|
+
|
100
97
|
def transform(result)
|
101
98
|
begin
|
102
99
|
self.gid = result["GID"].compact.first.to_i
|
@@ -130,6 +130,11 @@ module Threshold
|
|
130
130
|
|
131
131
|
private
|
132
132
|
|
133
|
+
#State does not track comments
|
134
|
+
def state
|
135
|
+
[@gid, @sid, @track_by, @count, @seconds, @new_action, @timeout, @apply_to]
|
136
|
+
end
|
137
|
+
|
133
138
|
def transform(result)
|
134
139
|
begin
|
135
140
|
self.gid = result["GID"].compact.first.to_i
|
data/lib/threshold/standalone.rb
CHANGED
@@ -14,6 +14,17 @@ module Threshold
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
+
# Equality Methods
|
18
|
+
def ==(an0ther)
|
19
|
+
an0ther.class == self.class && an0ther.hash == hash
|
20
|
+
end
|
21
|
+
|
22
|
+
alias_method :eql?, :==
|
23
|
+
|
24
|
+
def hash
|
25
|
+
state.hash
|
26
|
+
end
|
27
|
+
|
17
28
|
#Comparable
|
18
29
|
def <=>(anOther)
|
19
30
|
#gid <=> anOther.gid
|
data/lib/threshold/thresholds.rb
CHANGED
@@ -20,11 +20,11 @@ module Threshold
|
|
20
20
|
|
21
21
|
# Write changes to the file
|
22
22
|
def flush
|
23
|
+
|
23
24
|
begin
|
24
25
|
valid_existing_file?(@file)
|
25
26
|
raise ReadOnlyThresholdsFile if @readonly
|
26
27
|
hash = current_hash
|
27
|
-
|
28
28
|
file = File.open(@file, 'w+')
|
29
29
|
raise ThresholdAtomicLockFailure, 'The @file state/hash changed before we could flush the file' unless stored_hash == hash
|
30
30
|
file.write self.sort.to_s
|
@@ -32,11 +32,12 @@ module Threshold
|
|
32
32
|
|
33
33
|
rescue NonExistantThresholdFile
|
34
34
|
raise ReadOnlyThresholdsFile if @readonly
|
35
|
-
|
36
35
|
file = File.open(@file, 'w')
|
37
36
|
file.write self.sort.to_s
|
38
37
|
file.close
|
39
38
|
end
|
39
|
+
|
40
|
+
stored_hash=current_hash
|
40
41
|
return true
|
41
42
|
end
|
42
43
|
|
@@ -60,6 +61,7 @@ module Threshold
|
|
60
61
|
|
61
62
|
end
|
62
63
|
|
64
|
+
# Check if all objects in the Threshold Instance report .valid?
|
63
65
|
def valid?
|
64
66
|
begin
|
65
67
|
self.each do |threshold|
|
@@ -75,6 +77,8 @@ module Threshold
|
|
75
77
|
end
|
76
78
|
end
|
77
79
|
|
80
|
+
# Printer
|
81
|
+
# Pass (true) to_s to skip the printing of InternalObjects.comment
|
78
82
|
def to_s(skip = false)
|
79
83
|
output = ""
|
80
84
|
|
@@ -86,27 +90,36 @@ module Threshold
|
|
86
90
|
return output
|
87
91
|
end
|
88
92
|
|
93
|
+
# The calculated hash of the threshold.conf file at load time.
|
89
94
|
def stored_hash
|
90
95
|
@stored_hash
|
91
96
|
end
|
92
97
|
|
98
|
+
def to_a
|
99
|
+
@thresholds
|
100
|
+
end
|
101
|
+
|
93
102
|
## Forwardable Corrections:
|
94
103
|
## Corrected for forwardable due to Core Array returning new Arrays on the methods.
|
95
104
|
|
96
105
|
# Array(@thresholds) Creates a new Array on @threshold.sort so.. direct forwardable delegation fails.
|
97
106
|
|
107
|
+
# Returns a new Threshold Object
|
98
108
|
def sort
|
99
109
|
Thresholds.new(@thresholds.sort)
|
100
110
|
end
|
101
111
|
|
112
|
+
# Returns a new Threshold Object
|
102
113
|
def reverse
|
103
114
|
Thresholds.new(@thresholds.reverse)
|
104
115
|
end
|
105
116
|
|
117
|
+
# Returns a new Threshold Object
|
106
118
|
def shuffle
|
107
119
|
Thresholds.new(@thresholds.shuffle)
|
108
120
|
end
|
109
121
|
|
122
|
+
# Returns a new Threshold Object
|
110
123
|
def reject(&blk)
|
111
124
|
if block_given?
|
112
125
|
Thresholds.new(@thresholds.reject(&blk))
|
@@ -115,6 +128,7 @@ module Threshold
|
|
115
128
|
end
|
116
129
|
end
|
117
130
|
|
131
|
+
# Returns a new Threshold Object
|
118
132
|
def select(&blk)
|
119
133
|
if block_given?
|
120
134
|
Thresholds.new(@thresholds.select(&blk))
|
@@ -124,6 +138,7 @@ module Threshold
|
|
124
138
|
end
|
125
139
|
|
126
140
|
#Uniques by default to printable output
|
141
|
+
# Returns a new Threshold Object
|
127
142
|
def uniq(&blk)
|
128
143
|
if block_given?
|
129
144
|
Thresholds.new(@thresholds.uniq(&blk))
|
@@ -132,11 +147,32 @@ module Threshold
|
|
132
147
|
end
|
133
148
|
end
|
134
149
|
|
135
|
-
## Complex Methods
|
136
|
-
## &(union), | (intersect), + (concat)
|
150
|
+
## Complex SET Methods
|
151
|
+
## &(union), | (intersect), + (concat), - (Difference)
|
152
|
+
|
153
|
+
# + (concat)
|
154
|
+
# Returns a new Threshold Object
|
155
|
+
def +(an0ther)
|
156
|
+
Thresholds.new(@thresholds + an0ther.to_a)
|
157
|
+
end
|
137
158
|
|
138
|
-
|
139
|
-
|
159
|
+
# | (intersect)
|
160
|
+
# Returns a new Threshold Object
|
161
|
+
def |(an0ther)
|
162
|
+
Thresholds.new(@thresholds | an0ther.to_a)
|
163
|
+
end
|
164
|
+
|
165
|
+
# & (union)
|
166
|
+
# Returns a new Threshold Object
|
167
|
+
def &(an0ther)
|
168
|
+
Thresholds.new(@thresholds & an0ther.to_a)
|
169
|
+
end
|
170
|
+
|
171
|
+
# - (Difference)
|
172
|
+
# Returns a new Threshold Object
|
173
|
+
def -(an0ther)
|
174
|
+
Thresholds.new(@thresholds - an0ther.to_a)
|
175
|
+
end
|
140
176
|
|
141
177
|
private
|
142
178
|
|
data/lib/threshold/version.rb
CHANGED