check_graphite 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3f32d43d3f59664a0564f37e8df80b67d55a5226
4
+ data.tar.gz: 372374a809d7a7a116195433d33d960e704dd374
5
+ SHA512:
6
+ metadata.gz: a8bf5155f627b0047aa35879786415b6f762fe813a33559f4540a335483a8d4ebdef47eaa9798b909d6f03b0b7fbb0231a30715e1a0948fda6e3d459efa75201
7
+ data.tar.gz: 21b34042f300ad2ba40fcf38be2b14b0688dd6761d54500e73e2eb4cc524a1f2e34474e596342246a29a46a4ec5bcf1770c09e3db83a4b53bcf5de0ef829fe8b
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.2
4
+ - 1.9.3
data/README.md CHANGED
@@ -1,5 +1,9 @@
1
1
  check_graphite is a nagios module to query graphite
2
2
 
3
+ [![Build
4
+ Status](https://secure.travis-ci.org/pyr/check-graphite.png)](http://travis-ci.org/pyr/check-graphite)
5
+
6
+
3
7
  ## Example
4
8
 
5
9
  check_graphite -H 'http://my.graphite.host
data/Rakefile CHANGED
@@ -1 +1,10 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ desc "Default: run specs."
5
+ task :default => :spec
6
+
7
+ desc "Run specs"
8
+ RSpec::Core::RakeTask.new do |t|
9
+ t.rspec_opts = "--color"
10
+ end
@@ -22,6 +22,7 @@ Gem::Specification.new do |s|
22
22
  # s.add_development_dependency "rspec"
23
23
  s.add_runtime_dependency "nagios_check"
24
24
 
25
+ s.add_development_dependency "rake"
25
26
  s.add_development_dependency "rspec"
26
27
  s.add_development_dependency "fakeweb"
27
28
  end
@@ -34,20 +34,20 @@ module CheckGraphite
34
34
  http.request(req)
35
35
  }
36
36
 
37
- res.code == "200" || raise("HTTP error code #{res.code}")
37
+ raise "HTTP error code #{res.code}" unless res.code == "200"
38
+ raise "no data returned for target" if res.body == "[]"
38
39
 
39
40
  datapoints = JSON(res.body).first["datapoints"]
40
- res = datapoints.drop(options.dropfirst).
41
- take(datapoints.length - options.dropfirst - options.droplast).
42
- reduce({:sum => 0.0, :count => 0}) {|acc, e|
43
- if e[0]
44
- {:sum => acc[:sum] + e[0], :count => acc[:count] + 1}
45
- else
46
- acc
47
- end
48
- }
41
+ datapoints = datapoints.slice(
42
+ options.dropfirst,
43
+ (datapoints.size - options.dropfirst - options.droplast)
44
+ )
45
+ datapoints.reject! { |v| v.first.nil? }
46
+ sum = datapoints.reduce(0.0) {|acc, v| acc + v.first }
47
+
49
48
  raise "no valid datapoints" if res[:count] == 0
50
- value = res[:sum] / res[:count]
49
+
50
+ value = sum / datapoints.size
51
51
  store_value options.name, value
52
52
  store_message "#{options.name}=#{value}"
53
53
  end
@@ -1,3 +1,3 @@
1
1
  module CheckGraphite
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -11,21 +11,79 @@ describe CheckGraphite::Command do
11
11
  describe "it should make http requests and return data" do
12
12
  before do
13
13
  FakeWeb.register_uri(:get, "http://your.graphite.host/render?target=collectd.somebox.load.load.midterm&from=-30seconds&format=json",
14
- :body => '[{"target": "default.test.boottime", "datapoints": [[1.0, 1339512060], [3.0, 1339512120]]}]',
14
+ :body => '[{"target": "default.test.boottime", "datapoints": [[1.0, 1339512060], [2.0, 1339512120], [6.0, 1339512180], [7.0, 1339512240]]}]',
15
15
  :content_type => "application/json")
16
16
  end
17
17
 
18
- it "should just work" do
18
+ it "should return OK" do
19
19
  ARGV = %w{ -H http://your.graphite.host/render -M collectd.somebox.load.load.midterm }
20
20
  c = CheckGraphite::Command.new
21
- STDOUT.should_receive(:puts).with("OK|value=2.0;;;;")
21
+ STDOUT.should_receive(:puts).with("OK: value=4.0|value=4.0;;;;")
22
+ lambda { c.run }.should raise_error SystemExit
23
+ end
24
+
25
+ it "should return WARNING" do
26
+ ARGV = %w{ -H http://your.graphite.host/render -M collectd.somebox.load.load.midterm -w 0 }
27
+ c = CheckGraphite::Command.new
28
+ STDOUT.should_receive(:puts).with("WARNING: value=4.0|value=4.0;;;;")
22
29
  lambda { c.run }.should raise_error SystemExit
23
30
  end
24
31
 
25
- it "should be critical" do
32
+ it "should return CRITICAL" do
26
33
  ARGV = %w{ -H http://your.graphite.host/render -M collectd.somebox.load.load.midterm -c 0 }
27
34
  c = CheckGraphite::Command.new
28
- STDOUT.should_receive(:puts).with("CRITICAL|value=2.0;;;;")
35
+ STDOUT.should_receive(:puts).with("CRITICAL: value=4.0|value=4.0;;;;")
36
+ lambda { c.run }.should raise_error SystemExit
37
+ end
38
+
39
+ it "should honour dropfirst" do
40
+ ARGV = %w{ -H http://your.graphite.host/render -M collectd.somebox.load.load.midterm --dropfirst 1 }
41
+ c = CheckGraphite::Command.new
42
+ STDOUT.should_receive(:puts).with("OK: value=5.0|value=5.0;;;;")
43
+ lambda { c.run }.should raise_error SystemExit
44
+ end
45
+
46
+ it "should honour droplast" do
47
+ ARGV = %w{ -H http://your.graphite.host/render -M collectd.somebox.load.load.midterm --droplast 1 }
48
+ c = CheckGraphite::Command.new
49
+ STDOUT.should_receive(:puts).with("OK: value=3.0|value=3.0;;;;")
50
+ lambda { c.run }.should raise_error SystemExit
51
+ end
52
+
53
+ it "should honour dropfirst and droplast together" do
54
+ ARGV = %w{ -H http://your.graphite.host/render -M collectd.somebox.load.load.midterm --dropfirst 1 --droplast 1 }
55
+ c = CheckGraphite::Command.new
56
+ STDOUT.should_receive(:puts).with("OK: value=4.0|value=4.0;;;;")
57
+ lambda { c.run }.should raise_error SystemExit
58
+ end
59
+ end
60
+
61
+ describe "when data contains null values" do
62
+ before do
63
+ FakeWeb.register_uri(:get, "http://your.graphite.host/render?target=collectd.somebox.load.load.midterm&from=-30seconds&format=json",
64
+ :body => '[{"target": "default.test.boottime", "datapoints": [[1.0, 1339512060], [null, 1339512120], [null, 1339512180], [3.0, 1339512240]]}]',
65
+ :content_type => "application/json")
66
+ end
67
+
68
+ it "should discard them" do
69
+ ARGV = %w{ -H http://your.graphite.host/render -M collectd.somebox.load.load.midterm }
70
+ c = CheckGraphite::Command.new
71
+ STDOUT.should_receive(:puts).with("OK: value=2.0|value=2.0;;;;")
72
+ lambda { c.run }.should raise_error SystemExit
73
+ end
74
+ end
75
+
76
+ describe "when Graphite returns no datapoints" do
77
+ before do
78
+ FakeWeb.register_uri(:get, "http://your.graphite.host/render?target=value.does.not.exist&from=-30seconds&format=json",
79
+ :body => '[]',
80
+ :content_type => "application/json")
81
+ end
82
+
83
+ it "should be unknown" do
84
+ ARGV = %w{ -H http://your.graphite.host/render -M value.does.not.exist }
85
+ c = CheckGraphite::Command.new
86
+ STDOUT.should_receive(:puts).with(/UNKNOWN: INTERNAL ERROR: (RuntimeError: )?no data returned for target/)
29
87
  lambda { c.run }.should raise_error SystemExit
30
88
  end
31
89
  end
@@ -43,15 +101,15 @@ describe CheckGraphite::Command do
43
101
  it "should work with valid username and password" do
44
102
  ARGV = %w{ -H http://your.graphite.host/render -M collectd.somebox.load.load.midterm -U testuser -P testpass}
45
103
  c = CheckGraphite::Command.new
46
- STDOUT.should_receive(:puts).with("OK|value=2.0;;;;")
104
+ STDOUT.should_receive(:puts).with("OK: value=2.0|value=2.0;;;;")
47
105
  lambda { c.run }.should raise_error SystemExit
48
106
  end
49
107
 
50
108
  it "should fail with bad username and password" do
51
109
  ARGV = %w{ -H http://your.graphite.host/render -M collectd.somebox.load.load.midterm -U baduser -P badpass }
52
110
  c = CheckGraphite::Command.new
53
- STDOUT.should_receive(:puts).with(/UNKNOWN: INTERNAL ERROR: HTTP error code 401/)
111
+ STDOUT.should_receive(:puts).with(/UNKNOWN: INTERNAL ERROR: (RuntimeError: )?HTTP error code 401/)
54
112
  lambda { c.run }.should raise_error SystemExit
55
113
  end
56
114
  end
57
- end
115
+ end
metadata CHANGED
@@ -1,49 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: check_graphite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Pierre-Yves Ritschard
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2012-07-17 00:00:00.000000000Z
11
+ date: 2013-03-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: nagios_check
16
- requirement: &14292080 !ruby/object:Gem::Requirement
17
- none: false
15
+ requirement: !ruby/object:Gem::Requirement
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
- version_requirements: *14292080
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
25
41
  - !ruby/object:Gem::Dependency
26
42
  name: rspec
27
- requirement: &14266700 !ruby/object:Gem::Requirement
28
- none: false
43
+ requirement: !ruby/object:Gem::Requirement
29
44
  requirements:
30
- - - ! '>='
45
+ - - '>='
31
46
  - !ruby/object:Gem::Version
32
47
  version: '0'
33
48
  type: :development
34
49
  prerelease: false
35
- version_requirements: *14266700
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
36
55
  - !ruby/object:Gem::Dependency
37
56
  name: fakeweb
38
- requirement: &14264460 !ruby/object:Gem::Requirement
39
- none: false
57
+ requirement: !ruby/object:Gem::Requirement
40
58
  requirements:
41
- - - ! '>='
59
+ - - '>='
42
60
  - !ruby/object:Gem::Version
43
61
  version: '0'
44
62
  type: :development
45
63
  prerelease: false
46
- version_requirements: *14264460
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
47
69
  description: check values from a graphite server
48
70
  email:
49
71
  - pyr@spootnik.org
@@ -53,6 +75,7 @@ extensions: []
53
75
  extra_rdoc_files: []
54
76
  files:
55
77
  - .gitignore
78
+ - .travis.yml
56
79
  - Gemfile
57
80
  - README.md
58
81
  - Rakefile
@@ -63,27 +86,26 @@ files:
63
86
  - spec/check_graphite_spec.rb
64
87
  homepage: https://github.com/pyr/check-graphite
65
88
  licenses: []
89
+ metadata: {}
66
90
  post_install_message:
67
91
  rdoc_options: []
68
92
  require_paths:
69
93
  - lib
70
94
  required_ruby_version: !ruby/object:Gem::Requirement
71
- none: false
72
95
  requirements:
73
- - - ! '>='
96
+ - - '>='
74
97
  - !ruby/object:Gem::Version
75
98
  version: '0'
76
99
  required_rubygems_version: !ruby/object:Gem::Requirement
77
- none: false
78
100
  requirements:
79
- - - ! '>='
101
+ - - '>='
80
102
  - !ruby/object:Gem::Version
81
103
  version: '0'
82
104
  requirements: []
83
105
  rubyforge_project: check_graphite
84
- rubygems_version: 1.8.10
106
+ rubygems_version: 2.0.0
85
107
  signing_key:
86
- specification_version: 3
108
+ specification_version: 4
87
109
  summary: check_graphite
88
110
  test_files:
89
111
  - spec/check_graphite_spec.rb