sensu-extensions-check-dependencies 1.0.1 → 1.1.0

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: d977bb2e39d5c5632903ee1b398471bc26444ec1
4
- data.tar.gz: 81bc9b8e744b6dbf1164c3f6e9db1fc4a2c04aaa
3
+ metadata.gz: 39743c7fcd8b25f612cc82a2f5a0ff489d3af94f
4
+ data.tar.gz: 91a0e1327220c042b83a6dd886e8ddccc3df2304
5
5
  SHA512:
6
- metadata.gz: 9980c6005bf198117ccd05b3e415e4dab7afbe4e880dcc0156fdc6d23a92bbac7a0e6a2b0985ce4b419bba456c2a3d760256e6292571903ec2b44325511460a7
7
- data.tar.gz: 2a10c067c7e988ab5fbded2eb77e5af44ece60e7e0dcbe8c8edc9a2e3bbcf9f716d0594e3eb3a819a0e7bc14c6655c64902bf24ff9ea5f817889a2f1619bf28e
6
+ metadata.gz: 4b673e3f89b99151a5e7697176088d52dcef84668251de281f512c0ff33e10f95d8c54d98689ef06521950f5d868fab73a94327bcf386838caca49e045c754ae
7
+ data.tar.gz: e71797d1c07b3814e6a9b8ba60aacea120af2610f6ee855b935e04cc1865021768a633586addaff807501ea4a026552ffd2c4c9ec2560021c7cc38e24936a0f5
@@ -12,6 +12,12 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
12
12
 
13
13
  ### Changed
14
14
 
15
+ ## [1.1.0] - 2018-06-21
16
+
17
+ ### Added
18
+
19
+ - Add support for setting a subscription/check pair as a check dependency. #12 (@testeddoughnut)
20
+
15
21
  ## [1.0.1] - 2017-03-15
16
22
 
17
23
  ### Fixed
@@ -24,6 +30,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
24
30
 
25
31
  - Initial release.
26
32
 
27
- [Unreleased]: https://github.com/sensu-extensions/sensu-extensions-check-dependencies/compare/v1.0.0...HEAD
33
+ [Unreleased]: https://github.com/sensu-extensions/sensu-extensions-check-dependencies/compare/v1.1.0...HEAD
34
+ [1.1.0]: https://github.com/sensu-extensions/sensu-extensions-check-dependencies/compare/v1.0.1...v1.1.0
28
35
  [1.0.1]: https://github.com/sensu-extensions/sensu-extensions-check-dependencies/compare/v1.0.0...v1.0.1
29
36
  [1.0.0]: https://github.com/sensu-extensions/sensu-extensions-check-dependencies/compare/v1.0.0...v1.0.0
data/README.md CHANGED
@@ -1,19 +1,25 @@
1
1
  ## Sensu::Extensions::CheckDependencies
2
2
 
3
+ This filter extension provides the Sensu Core built-in filter `check_dependencies`.
4
+
3
5
  This filter matches events when an event already exists, enabling the user to
4
6
  reduce notification noise and only be notified for the “root cause” of a given
5
7
  failure. Check dependencies can be defined in the check definition, using
6
- dependencies, an array of checks (e.g. `check_app`) or Sensu client/check pairs
7
- (e.g. `db-01/check_mysql`).
8
+ dependencies, an array of checks (e.g. `check_app`), Sensu client/check pairs
9
+ (e.g. `db-01/check_mysql`), or a subscription/check pair
10
+ (e.g. `subscription:mysql/check_mysql`).
11
+
12
+ [![Build Status](https://travis-ci.org/sensu-extensions/sensu-extensions-check-dependencies.svg?branch=master)](https://travis-ci.org/sensu-extensions/sensu-extensions-check-dependencies)
8
13
 
9
14
  ### Installation
10
15
 
11
- This extension requires Sensu version >= 0.26.
16
+ This extension requires Sensu version >= 0.26 and is provided as a built-in
17
+ filter in Sensu >= 0.29.
12
18
 
13
- On a Sensu server machine:
19
+ To manually install this extension on a Sensu server machine:
14
20
 
15
21
  ```
16
- $ sudo sensu-install -e check-dependencies:1.0.1
22
+ $ sudo sensu-install -e check-dependencies:1.1.0
17
23
  ```
18
24
 
19
25
  Edit `/etc/sensu/conf.d/extensions.json` to load it:
@@ -22,7 +28,7 @@ Edit `/etc/sensu/conf.d/extensions.json` to load it:
22
28
  {
23
29
  "extensions": {
24
30
  "check-dependencies": {
25
- "version": "1.0.1"
31
+ "version": "1.1.0"
26
32
  }
27
33
  }
28
34
  }
@@ -68,6 +74,26 @@ Specify a dependency on the `mysql` check:
68
74
  }
69
75
  ```
70
76
 
77
+ ... or specify a dependency on any `mysql` check in the `mysql_nodes`
78
+ subscription:
79
+
80
+ ``` javascript
81
+ {
82
+ "checks": {
83
+ "web_application_api": {
84
+ "command": "check-http.rb -u https://localhost:8080/api/v1/health",
85
+ "subscribers": [
86
+ "web_application"
87
+ ],
88
+ "interval": 20,
89
+ "dependencies": [
90
+ "subscription:mysql_nodes/mysql"
91
+ ]
92
+ }
93
+ }
94
+ }
95
+ ```
96
+
71
97
  Apply the `check_dependencies` filter to one or more handlers:
72
98
 
73
99
  ``` javascript
@@ -36,17 +36,31 @@ module Sensu
36
36
  # @param client_name [String]
37
37
  # @param check_name [String]
38
38
  # @return [Boolean]
39
- def event_exists?(client_name, check_name)
39
+ def client_event_exists?(client_name, check_name)
40
40
  path = "/events/#{client_name}/#{check_name}"
41
41
  response = sensu_api_get_request(path)
42
42
  response.code.to_i == 200
43
43
  end
44
44
 
45
+ # Check to see if an event exists for a subscription/check pair. This
46
+ # method is looking for a HTTP response code of `200`.
47
+ #
48
+ # @param subscription_name [String]
49
+ # @param check_name [String]
50
+ # @return [Boolean]
51
+ def subscription_event_exists?(subscription_name, check_name)
52
+ path = "/events"
53
+ response = sensu_api_get_request(path)
54
+ events = JSON.load(response.body)
55
+ !events.select { |event| event[:client][:subscriptions].include?(subscription_name) && event[:check][:name] == check_name}.empty?
56
+ end
57
+
45
58
  # Determine if an event exists for any of the check
46
59
  # dependencies declared in the event data, specified in array,
47
60
  # check `dependencies`. A check dependency can be a check
48
- # executed by the same Sensu client (eg. `check_app`), or a
49
- # client/check pair (eg.`i-424242/check_mysql`).
61
+ # executed by the same Sensu client (eg. `check_app`), a
62
+ # client/check pair (eg.`i-424242/check_mysql`), or a
63
+ # subscription/check pair (eg. `subscription:mysql/check_mysql`).
50
64
  #
51
65
  # @param event [Hash]
52
66
  # @return [Boolean]
@@ -54,9 +68,15 @@ module Sensu
54
68
  if event[:check][:dependencies].is_a?(Array)
55
69
  event[:check][:dependencies].any? do |dependency|
56
70
  begin
57
- check_name, client_name = dependency.split("/").reverse
58
- client_name ||= event[:client][:name]
59
- event_exists?(client_name, check_name)
71
+ check_name, entity = dependency.split("/").reverse
72
+ if entity =~ /^subscription:.*$/
73
+ subscription_name = entity.split(":")[1]
74
+ subscription_event_exists?(subscription_name, check_name)
75
+ else
76
+ client_name = entity
77
+ client_name ||= event[:client][:name]
78
+ client_event_exists?(client_name, check_name)
79
+ end
60
80
  rescue => error
61
81
  @logger.error("failed to query api for a check dependency event", :error => error)
62
82
  false
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-extensions-check-dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu Inc
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-15 00:00:00.000000000 Z
11
+ date: 2018-06-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: sensu-extension
@@ -138,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
138
138
  version: '0'
139
139
  requirements: []
140
140
  rubyforge_project:
141
- rubygems_version: 2.6.6
141
+ rubygems_version: 2.6.11
142
142
  signing_key:
143
143
  specification_version: 4
144
144
  summary: Filter events when an event already exists for a defined check dependency