sensu-plugin 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -69,9 +69,20 @@ module Sensu
69
69
  exit 0
70
70
  end
71
71
 
72
- def api_request(*path)
72
+ def api_request(method, path, &blk)
73
73
  http = Net::HTTP.new(settings['api']['host'], settings['api']['port'])
74
- http.request(Net::HTTP::Get.new(path.join('/')))
74
+ req = case method.to_s.upcase
75
+ when 'GET'
76
+ Net::HTTP::Get.new(path)
77
+ when 'POST'
78
+ Net::HTTP::Post.new(path)
79
+ when 'DELETE'
80
+ Net::HTTP::Delete.new(path)
81
+ when 'PUT'
82
+ Net::HTTP::Put.new(path)
83
+ end
84
+ yield(req) if block_given?
85
+ http.request(req)
75
86
  end
76
87
 
77
88
  def filter_disabled
@@ -96,10 +107,10 @@ module Sensu
96
107
  def filter_silenced
97
108
  begin
98
109
  timeout(3) do
99
- if api_request('/stash/silence', @event['client']['name']).code == '200'
110
+ if stash_exists?('/silence/' + @event['client']['name'])
100
111
  bail 'client alerts silenced'
101
112
  end
102
- if api_request('/stash/silence', @event['client']['name'], @event['check']['name']).code == '200'
113
+ if stash_exists?('/silence/' + @event['client']['name'] + '/' + @event['check']['name'])
103
114
  bail 'check alerts silenced'
104
115
  end
105
116
  end
@@ -108,6 +119,10 @@ module Sensu
108
119
  end
109
120
  end
110
121
 
122
+ def stash_exists?(path)
123
+ api_request(:GET, '/stash' + path).code == '200'
124
+ end
125
+
111
126
  end
112
127
  end
113
128
 
@@ -1,6 +1,6 @@
1
1
  module Sensu
2
2
  module Plugin
3
- VERSION = "0.1.2"
3
+ VERSION = "0.1.3"
4
4
  EXIT_CODES = {
5
5
  'OK' => 0,
6
6
  'WARNING' => 1,
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugin
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-01-13 00:00:00.000000000 Z
12
+ date: 2012-02-10 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: json
16
- requirement: &70202734882620 !ruby/object:Gem::Requirement
16
+ requirement: &70113831789080 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70202734882620
24
+ version_requirements: *70113831789080
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: mixlib-cli
27
- requirement: &70202734881980 !ruby/object:Gem::Requirement
27
+ requirement: &70113831788560 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 1.1.0
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *70202734881980
35
+ version_requirements: *70113831788560
36
36
  description: Plugins and helper libraries for Sensu, a monitoring framework
37
37
  email:
38
38
  - decklin@red-bean.com