Skip to content

Commit

Permalink
add a generic collectd parser plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
tclavier committed Feb 14, 2015
1 parent 25b4929 commit 22936a2
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 4 deletions.
7 changes: 3 additions & 4 deletions lib/backstop/collectd/parser.rb
Expand Up @@ -37,11 +37,10 @@ def parse_base
def parse_plugin
plugin = data['plugin']
method = "parse_plugin_#{plugin}".to_sym
if self.respond_to? method
send(method)
else
[]
unless self.respond_to? method
method = :parse_plugin_generic
end
send(method)
end

end
8 changes: 8 additions & 0 deletions lib/backstop/collectd/plugins/generic.rb
@@ -0,0 +1,8 @@
class CollectdData
# disk partition stats
def parse_plugin_generic
[
{ metric: "#{data['type']}.#{data['type_instance']}", value: data['values'][0] },
]
end
end
14 changes: 14 additions & 0 deletions spec/backstop/generic_collectd_data.json
@@ -0,0 +1,14 @@
[
{
"values":[42],
"dstypes":["derive"],
"dsnames":["value"],
"time":1423949215.334,
"interval":10.0,
"host":"leeloo.octo.it",
"plugin":"irq",
"plugin_instance":"",
"type":"irq",
"type_instance":"IWI"
}
]
10 changes: 10 additions & 0 deletions spec/backstop/web_spec.rb
Expand Up @@ -49,6 +49,7 @@ def app
context 'POST /collectd' do
let(:good_collectd_data) { File.open(File.dirname(__FILE__) + '/good_collectd_data.json').read }
let(:bad_collectd_data) { File.open(File.dirname(__FILE__) + '/bad_collectd_data.json').read }
let(:generic_collectd_data) { File.open(File.dirname(__FILE__) + '/generic_collectd_data.json').read }

it 'should require JSON' do
post '/collectd', 'foo'
Expand All @@ -70,6 +71,15 @@ def app
last_response.status.should eq(400)
last_response.body.should eq('missing fields')
end

it 'should handle a generic collectd metric' do
p = double('publisher')
Backstop::Publisher.should_receive(:new) { p }
p.should_receive(:publish).with('mitt.leeloo.octo.it.irq.IWI', 42, 1423949215.334)
post '/collectd', generic_collectd_data
last_response.body.should eq('ok')
last_response.status.should eq(200)
end
end

context 'POST /github' do
Expand Down

0 comments on commit 22936a2

Please sign in to comment.