check_graphite 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3f32d43d3f59664a0564f37e8df80b67d55a5226
4
- data.tar.gz: 372374a809d7a7a116195433d33d960e704dd374
3
+ metadata.gz: 603d1010785574e54ebb2353fd075ab503c17a96
4
+ data.tar.gz: fd8419b57ca05f96d2606b6b585a1e733a910dd9
5
5
  SHA512:
6
- metadata.gz: a8bf5155f627b0047aa35879786415b6f762fe813a33559f4540a335483a8d4ebdef47eaa9798b909d6f03b0b7fbb0231a30715e1a0948fda6e3d459efa75201
7
- data.tar.gz: 21b34042f300ad2ba40fcf38be2b14b0688dd6761d54500e73e2eb4cc524a1f2e34474e596342246a29a46a4ec5bcf1770c09e3db83a4b53bcf5de0ef829fe8b
6
+ metadata.gz: 0c8b40d62478a0be9fcea816746b1943b5b5b178ad39f73e96412354f7afd30c71ef832f6fef26f0c4e447ef4d11e61a9f1351bc13bbb6b8b5360f1bfb33a6ff
7
+ data.tar.gz: 58e4a59d104d66124ef651ad802642beaaf7d30c44c9e83a6b96962d190c2c9e2f61d53d26ad44a3b0f6d8f213a0a059ab179f4b6c36f2283ec941ff156774dc
data/README.md CHANGED
@@ -26,6 +26,7 @@ check_graphite accepts the following options:
26
26
  ## How it works
27
27
 
28
28
  check_graphite, asks for a small window of metrics, and computes an average over the last valid
29
- points collected, it then checks the value against supplied thresholds.
29
+ points collected, it then checks the value against supplied thresholds. Thresholds are expressed
30
+ in the format given in [The Nagios Developer Guidelines](http://nagiosplug.sourceforge.net/developer-guidelines.html#THRESHOLDFORMAT).
30
31
 
31
32
  NaN values are not taken into account in the average
@@ -1,3 +1,3 @@
1
1
  module CheckGraphite
2
- VERSION = "0.2.0"
2
+ VERSION = "0.2.2"
3
3
  end
@@ -1,6 +1,6 @@
1
1
  require "nagios_check"
2
2
  require "json"
3
- require "net/http"
3
+ require "net/https"
4
4
  require "check_graphite/version"
5
5
 
6
6
  module CheckGraphite
@@ -30,7 +30,7 @@ module CheckGraphite
30
30
  req.basic_auth options.username, options.password
31
31
  end
32
32
 
33
- res = Net::HTTP.start(uri.host, uri.port) { |http|
33
+ res = Net::HTTP.start(uri.host, uri.port, :use_ssl => 'https' == uri.scheme) { |http|
34
34
  http.request(req)
35
35
  }
36
36
 
@@ -42,11 +42,12 @@ module CheckGraphite
42
42
  options.dropfirst,
43
43
  (datapoints.size - options.dropfirst - options.droplast)
44
44
  )
45
- datapoints.reject! { |v| v.first.nil? }
46
- sum = datapoints.reduce(0.0) {|acc, v| acc + v.first }
47
45
 
48
- raise "no valid datapoints" if res[:count] == 0
46
+ # Remove NULL values. Return UNKNOWN if there's nothing left.
47
+ datapoints.reject! { |v| v.first.nil? }
48
+ raise "no valid datapoints" if datapoints.size == 0
49
49
 
50
+ sum = datapoints.reduce(0.0) {|acc, v| acc + v.first }
50
51
  value = sum / datapoints.size
51
52
  store_value options.name, value
52
53
  store_message "#{options.name}=#{value}"
@@ -73,7 +73,7 @@ describe CheckGraphite::Command do
73
73
  end
74
74
  end
75
75
 
76
- describe "when Graphite returns no datapoints" do
76
+ describe "when Graphite returns no data at all" do
77
77
  before do
78
78
  FakeWeb.register_uri(:get, "http://your.graphite.host/render?target=value.does.not.exist&from=-30seconds&format=json",
79
79
  :body => '[]',
@@ -88,6 +88,21 @@ describe CheckGraphite::Command do
88
88
  end
89
89
  end
90
90
 
91
+ describe "when Graphite returns only NULL values" do
92
+ before do
93
+ FakeWeb.register_uri(:get, "http://your.graphite.host/render?target=all.values.null&from=-30seconds&format=json",
94
+ :body => '[{"target": "all.values.null", "datapoints": [[null, 1339512060], [null, 1339512120], [null, 1339512180], [null, 1339512240]]}]',
95
+ :content_type => "application/json")
96
+ end
97
+
98
+ it "should be unknown" do
99
+ ARGV = %w{ -H http://your.graphite.host/render -M all.values.null }
100
+ c = CheckGraphite::Command.new
101
+ STDOUT.should_receive(:puts).with(/UNKNOWN: INTERNAL ERROR: (RuntimeError: )?no valid datapoints/)
102
+ lambda { c.run }.should raise_error SystemExit
103
+ end
104
+ end
105
+
91
106
  describe "it should make http requests with basic auth and return data" do
92
107
  before do
93
108
  FakeWeb.register_uri(:get, "http://baduser:badpass@your.graphite.host/render?target=collectd.somebox.load.load.midterm&from=-30seconds&format=json",
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: check_graphite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pierre-Yves Ritschard
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-03-28 00:00:00.000000000 Z
11
+ date: 2013-11-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nagios_check