drone_collectd 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,153 @@
1
+ require 'bindata'
2
+
3
+ module DroneCollectd
4
+
5
+ class CollectdPacket
6
+
7
+ # part type
8
+ HOST = 0x0000
9
+ TIME = 0x0001
10
+ PLUGIN = 0x0002
11
+ PLUGIN_INSTANCE = 0x0003
12
+ TYPE = 0x0004
13
+ TYPE_INSTANCE = 0x0005
14
+ VALUES = 0x0006
15
+ INTERVAL = 0x0007
16
+ MESSAGE = 0x0100
17
+ SEVERITY = 0x0101
18
+
19
+ STRING_TYPES = [HOST, PLUGIN, PLUGIN_INSTANCE, TYPE, TYPE_INSTANCE, MESSAGE].freeze
20
+ INTEGER_TYPES = [TIME, INTERVAL, SEVERITY].freeze
21
+
22
+ class ValuePartData < BinData::Record
23
+ COUNTER = 0
24
+ GAUGE = 1
25
+ DERIVE = 2
26
+ ABSOLUTE = 3
27
+
28
+ mandatory_parameter :data_type
29
+
30
+ register_self
31
+
32
+ endian :big
33
+ choice :val, :selection => proc{ data_type }, :choices => {
34
+ COUNTER => :uint64,
35
+ GAUGE => :double_le,
36
+ DERIVE => :int64,
37
+ ABSOLUTE => :uint64
38
+ }
39
+
40
+ end
41
+
42
+ class ValuePart < BinData::Record
43
+ endian :big
44
+
45
+ int16 :values_count, :value => lambda{ self.vals.size }
46
+
47
+ array :vals_type, :type => :uint8
48
+ array :vals do
49
+ value_part_data
50
+ end
51
+
52
+ def last_type
53
+ self.vals_type[-1]
54
+ end
55
+
56
+ register_self
57
+ end
58
+
59
+
60
+
61
+ class Part < BinData::Record
62
+ endian :big
63
+
64
+ register_self
65
+
66
+ uint16 :part_type
67
+ uint16 :part_length, :value => lambda{
68
+ 4 +
69
+ case
70
+ when DroneCollectd::CollectdPacket::STRING_TYPES.include?(part_type) then self.string_value.size + 1
71
+ when DroneCollectd::CollectdPacket::INTEGER_TYPES.include?(part_type) then 8
72
+ else
73
+ (2 + self.vals.values_count * 9)
74
+ end
75
+ }
76
+
77
+ stringz :string_value, :onlyif => proc { DroneCollectd::CollectdPacket::STRING_TYPES.include?(part_type) }
78
+ int64 :integer_value, :onlyif => proc { DroneCollectd::CollectdPacket::INTEGER_TYPES.include?(part_type) }
79
+
80
+ value_part :vals, :onlyif => proc { part_type == DroneCollectd::CollectdPacket::VALUES }
81
+ end
82
+
83
+ class Packet < BinData::Record
84
+ array :parts, :type => :part, :read_until => :eof
85
+
86
+ ATTRS = %w(host plugin plugin_instance type type_instance message time interval).freeze
87
+
88
+ ATTRS.each do |attr_name|
89
+ define_method("#{attr_name}=") do |value|
90
+ type = CollectdPacket.const_get(attr_name.upcase)
91
+ property_name = CollectdPacket::STRING_TYPES.include?(type) ? 'string_value' : 'integer_value'
92
+
93
+ part = self.parts.detect{|p| p.part_type == type }
94
+ unless part
95
+ part = Part.new(:part_type => type)
96
+ part.send("#{property_name}=", value)
97
+ self.parts << part
98
+ else
99
+ part.send("#{property_name}=", value)
100
+ end
101
+ end
102
+ end
103
+
104
+
105
+ def add_value(type, value)
106
+ raise(ArgumentError, "unknown type: #{type}") unless ValuePartData::const_defined?(type.to_s.upcase)
107
+ data_type = ValuePartData::const_get(type.to_s.upcase)
108
+
109
+ v = {:data_type => data_type, :val => value}
110
+ # v.val = value
111
+
112
+ part = self.parts.detect{|p| p.part_type == CollectdPacket::VALUES }
113
+ if part
114
+ part.vals.vals_type << data_type
115
+ part.vals.vals << v
116
+ else
117
+ part = Part.new(:part_type => CollectdPacket::VALUES)
118
+ part.vals.vals_type << data_type
119
+ puts "V: #{v.inspect}"
120
+ part.vals.vals << v
121
+ self.parts << part
122
+ end
123
+ end
124
+
125
+ end
126
+
127
+
128
+
129
+ def initialize
130
+ @packet = Packet.new
131
+ end
132
+
133
+ def method_missing(m, *args)
134
+ if @packet.respond_to?(m)
135
+ @packet.send(m, *args)
136
+ else
137
+ raise NoMethodError, m.to_s
138
+ end
139
+ end
140
+
141
+ def build_packet
142
+ @packet.to_binary_s
143
+ end
144
+
145
+ end
146
+
147
+ end
148
+
149
+
150
+ if $0 == __FILE__
151
+ include DroneCollectd
152
+ v = CollectdPacket::ValuePartData.new()
153
+ end
@@ -0,0 +1,130 @@
1
+ !RBIX
2
+ 10937318184790222022
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 28
13
+ 99
14
+ 7
15
+ 0
16
+ 65
17
+ 49
18
+ 1
19
+ 2
20
+ 13
21
+ 99
22
+ 12
23
+ 7
24
+ 2
25
+ 12
26
+ 7
27
+ 3
28
+ 12
29
+ 65
30
+ 12
31
+ 49
32
+ 4
33
+ 4
34
+ 15
35
+ 49
36
+ 2
37
+ 0
38
+ 15
39
+ 2
40
+ 11
41
+ I
42
+ 6
43
+ I
44
+ 0
45
+ I
46
+ 0
47
+ I
48
+ 0
49
+ n
50
+ p
51
+ 5
52
+ x
53
+ 13
54
+ DroneCollectd
55
+ x
56
+ 11
57
+ open_module
58
+ x
59
+ 15
60
+ __module_init__
61
+ M
62
+ 1
63
+ n
64
+ n
65
+ x
66
+ 13
67
+ DroneCollectd
68
+ i
69
+ 12
70
+ 5
71
+ 66
72
+ 65
73
+ 7
74
+ 0
75
+ 7
76
+ 1
77
+ 64
78
+ 49
79
+ 2
80
+ 2
81
+ 11
82
+ I
83
+ 3
84
+ I
85
+ 0
86
+ I
87
+ 0
88
+ I
89
+ 0
90
+ n
91
+ p
92
+ 3
93
+ x
94
+ 7
95
+ VERSION
96
+ s
97
+ 5
98
+ 0.0.1
99
+ x
100
+ 9
101
+ const_set
102
+ p
103
+ 3
104
+ I
105
+ 2
106
+ I
107
+ 2
108
+ I
109
+ c
110
+ x
111
+ 73
112
+ /Users/schmurfy/Dev/personal/drone_collectd/lib/drone_collectd/version.rb
113
+ p
114
+ 0
115
+ x
116
+ 13
117
+ attach_method
118
+ p
119
+ 3
120
+ I
121
+ 0
122
+ I
123
+ 1
124
+ I
125
+ 1c
126
+ x
127
+ 73
128
+ /Users/schmurfy/Dev/personal/drone_collectd/lib/drone_collectd/version.rb
129
+ p
130
+ 0
@@ -0,0 +1,7 @@
1
+ module DroneCollectd
2
+ def self.require_lib(path)
3
+ require File.expand_path("../#{path}", __FILE__)
4
+ end
5
+
6
+ require_lib('drone_collectd/collectd')
7
+ end
@@ -0,0 +1,244 @@
1
+ !RBIX
2
+ 10937318184790222022
3
+ x
4
+ M
5
+ 1
6
+ n
7
+ n
8
+ x
9
+ 10
10
+ __script__
11
+ i
12
+ 28
13
+ 99
14
+ 7
15
+ 0
16
+ 65
17
+ 49
18
+ 1
19
+ 2
20
+ 13
21
+ 99
22
+ 12
23
+ 7
24
+ 2
25
+ 12
26
+ 7
27
+ 3
28
+ 12
29
+ 65
30
+ 12
31
+ 49
32
+ 4
33
+ 4
34
+ 15
35
+ 49
36
+ 2
37
+ 0
38
+ 15
39
+ 2
40
+ 11
41
+ I
42
+ 6
43
+ I
44
+ 0
45
+ I
46
+ 0
47
+ I
48
+ 0
49
+ n
50
+ p
51
+ 5
52
+ x
53
+ 13
54
+ DroneCollectd
55
+ x
56
+ 11
57
+ open_module
58
+ x
59
+ 15
60
+ __module_init__
61
+ M
62
+ 1
63
+ n
64
+ n
65
+ x
66
+ 13
67
+ DroneCollectd
68
+ i
69
+ 31
70
+ 5
71
+ 66
72
+ 99
73
+ 7
74
+ 0
75
+ 7
76
+ 1
77
+ 65
78
+ 5
79
+ 49
80
+ 2
81
+ 4
82
+ 15
83
+ 5
84
+ 7
85
+ 3
86
+ 64
87
+ 47
88
+ 49
89
+ 0
90
+ 1
91
+ 15
92
+ 5
93
+ 7
94
+ 4
95
+ 64
96
+ 47
97
+ 49
98
+ 0
99
+ 1
100
+ 11
101
+ I
102
+ 5
103
+ I
104
+ 0
105
+ I
106
+ 0
107
+ I
108
+ 0
109
+ n
110
+ p
111
+ 5
112
+ x
113
+ 11
114
+ require_lib
115
+ M
116
+ 1
117
+ n
118
+ n
119
+ x
120
+ 11
121
+ require_lib
122
+ i
123
+ 25
124
+ 5
125
+ 45
126
+ 0
127
+ 1
128
+ 7
129
+ 2
130
+ 20
131
+ 0
132
+ 47
133
+ 101
134
+ 3
135
+ 63
136
+ 2
137
+ 65
138
+ 49
139
+ 4
140
+ 0
141
+ 49
142
+ 5
143
+ 2
144
+ 47
145
+ 49
146
+ 6
147
+ 1
148
+ 11
149
+ I
150
+ 5
151
+ I
152
+ 1
153
+ I
154
+ 1
155
+ I
156
+ 1
157
+ n
158
+ p
159
+ 7
160
+ x
161
+ 4
162
+ File
163
+ n
164
+ s
165
+ 3
166
+ ../
167
+ x
168
+ 4
169
+ to_s
170
+ x
171
+ 11
172
+ active_path
173
+ x
174
+ 11
175
+ expand_path
176
+ x
177
+ 7
178
+ require
179
+ p
180
+ 5
181
+ I
182
+ -1
183
+ I
184
+ 2
185
+ I
186
+ 0
187
+ I
188
+ 3
189
+ I
190
+ 19
191
+ x
192
+ 65
193
+ /Users/schmurfy/Dev/personal/drone_collectd/lib/drone_collectd.rb
194
+ p
195
+ 1
196
+ x
197
+ 4
198
+ path
199
+ x
200
+ 13
201
+ attach_method
202
+ s
203
+ 22
204
+ drone_collectd/version
205
+ s
206
+ 23
207
+ drone_collectd/collectd
208
+ p
209
+ 7
210
+ I
211
+ 2
212
+ I
213
+ 2
214
+ I
215
+ d
216
+ I
217
+ 6
218
+ I
219
+ 16
220
+ I
221
+ 7
222
+ I
223
+ 1f
224
+ x
225
+ 65
226
+ /Users/schmurfy/Dev/personal/drone_collectd/lib/drone_collectd.rb
227
+ p
228
+ 0
229
+ x
230
+ 13
231
+ attach_method
232
+ p
233
+ 3
234
+ I
235
+ 0
236
+ I
237
+ 1
238
+ I
239
+ 1c
240
+ x
241
+ 65
242
+ /Users/schmurfy/Dev/personal/drone_collectd/lib/drone_collectd.rb
243
+ p
244
+ 0
data/specs/common.rb ADDED
@@ -0,0 +1,63 @@
1
+ $:.reject! { |e| e.include? 'TextMate' }
2
+
3
+ require 'rubygems'
4
+
5
+ puts "Testing with ruby #{RUBY_VERSION} and rubygems #{Gem::VERSION}"
6
+
7
+ require 'bundler/setup'
8
+
9
+ if (RUBY_VERSION >= "1.9") && ENV['COVERAGE']
10
+ require 'simplecov'
11
+ ROOT = File.expand_path('../../', __FILE__)
12
+
13
+ puts "[[ SimpleCov enabled ]]"
14
+
15
+ SimpleCov.start do
16
+ add_filter '/gems/'
17
+ add_filter '/specs/'
18
+
19
+ root(ROOT)
20
+ end
21
+ end
22
+
23
+ require 'bacon'
24
+ require 'mocha'
25
+ require 'delorean'
26
+ require 'em-spec/bacon'
27
+ EM.spec_backend = EventMachine::Spec::Bacon
28
+
29
+ $LOAD_PATH << File.expand_path('../../lib', __FILE__)
30
+
31
+ module Bacon
32
+ module MochaRequirementsCounter
33
+ def self.increment
34
+ Counter[:requirements] += 1
35
+ end
36
+ end
37
+
38
+ class Context
39
+ include Mocha::API
40
+
41
+ alias_method :it_before_mocha, :it
42
+
43
+ def it(description)
44
+ it_before_mocha(description) do
45
+ begin
46
+ mocha_setup
47
+ yield
48
+ mocha_verify(MochaRequirementsCounter)
49
+ rescue Mocha::ExpectationError => e
50
+ raise Error.new(:failed, "#{e.message}\n#{e.backtrace[0...10].join("\n")}")
51
+ ensure
52
+ mocha_teardown
53
+ end
54
+ end
55
+ end
56
+ end
57
+ end
58
+
59
+ def focus(test_label)
60
+ Bacon.const_set(:RestrictName, %r{#{test_label}})
61
+ end
62
+
63
+ Bacon.summary_on_exit()