sensu-extensions-check-dependencies 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6b1e09684897fdf40f7c969aa0d59720c0a0ca2d
4
+ data.tar.gz: 8088c80f569f0e823ae392514f40ba033bc0215b
5
+ SHA512:
6
+ metadata.gz: 1a5371f6b55f6efd9330e911bd19f4a7d1833432fd89d00ef67b316ed0717dda6cce55e8d46b1693de6e809ba6a7800c9c73a29b33c70605e287dce145a65995
7
+ data.tar.gz: 2b9827fd4d830d196c9887a790ba80f97f0971e60b120966aa91c10301b06532c04e601f7541f2c0648dfef3044a0cdfc32d060203175e9c6df66fc79cd28392
data/CHANGELOG.md ADDED
@@ -0,0 +1,22 @@
1
+ # Change Log for Sensu::Extension::CheckDependencies
2
+
3
+ This project adheres to [Semantic Versioning](http://semver.org/).
4
+
5
+ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/).
6
+
7
+ ## [Unreleased]
8
+
9
+ ### Fixed
10
+
11
+ ### Added
12
+
13
+ ### Changed
14
+
15
+ ## [1.0.0] - 2017-02-13
16
+
17
+ ### Added
18
+
19
+ - Initial release.
20
+
21
+ [Unreleased]: https://github.com/sensu-extensions/sensu-extensions-check-dependencies/compare/v1.0.0...HEAD
22
+ [1.0.0]: https://github.com/sensu-extensions/sensu-extensions-check-dependencies/compare/v0.0.1...v1.0.0
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Sensu-Extensions
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,82 @@
1
+ ## Sensu::Extensions::CheckDependencies
2
+
3
+ This filter matches events when an event already exists, enabling the user to
4
+ reduce notification noise and only be notified for the “root cause” of a given
5
+ 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
+
9
+ ### Installation
10
+
11
+ This extension requires Sensu version >= 0.26.
12
+
13
+ On a Sensu server machine:
14
+
15
+ ```
16
+ $ sudo sensu-install -e check_dependencies:1.0.0
17
+ ```
18
+
19
+ Edit `/etc/sensu/conf.d/extensions.json` to load it:
20
+
21
+ ```
22
+ {
23
+ "extensions": {
24
+ "check_dependencies": {
25
+ "version": "1.0.0"
26
+ }
27
+ }
28
+ ```
29
+
30
+ ### Example Check/Handler Configuration
31
+
32
+ Specify a dependency on the `mysql` check:
33
+
34
+ ``` javascript
35
+ {
36
+ "checks": {
37
+ "web_application_api": {
38
+ "command": "check-http.rb -u https://localhost:8080/api/v1/health",
39
+ "subscribers": [
40
+ "web_application"
41
+ ],
42
+ "interval": 20,
43
+ "dependencies": [
44
+ "mysql"
45
+ ]
46
+ }
47
+ }
48
+ }
49
+ ```
50
+
51
+ ... or specify a dependency on another client's `mysql` check:
52
+
53
+ ``` javascript
54
+ {
55
+ "checks": {
56
+ "web_application_api": {
57
+ "command": "check-http.rb -u https://localhost:8080/api/v1/health",
58
+ "subscribers": [
59
+ "web_application"
60
+ ],
61
+ "interval": 20,
62
+ "dependencies": [
63
+ "db-01/mysql"
64
+ ]
65
+ }
66
+ }
67
+ }
68
+ ```
69
+
70
+ Apply the `check_dependencies` filter to one or more handlers:
71
+
72
+ ``` javascript
73
+ {
74
+ "handlers": {
75
+ "custom_mailer": {
76
+ "type": "pipe",
77
+ "command": "custom_mailer.rb",
78
+ "filters": ["check_dependencies"]
79
+ }
80
+ }
81
+ }
82
+ ```
@@ -0,0 +1,89 @@
1
+ require "sensu/extension"
2
+ require "timeout"
3
+ require "net/http"
4
+
5
+ module Sensu
6
+ module Extension
7
+ class CheckDependencies < Filter
8
+ def name
9
+ "check_dependencies"
10
+ end
11
+
12
+ def description
13
+ "filter events when an event exists for a check dependency"
14
+ end
15
+
16
+ # Make an HTTP GET request to the Sensu API, using the URI
17
+ # path provided. Uses Sensu settings to determine how to
18
+ # connect to the API.
19
+ #
20
+ # @param path [String]
21
+ # @return [Object] http response object.
22
+ def sensu_api_get_request(path)
23
+ api = @settings[:api] || {}
24
+ request = Net::HTTP::Get.new(path)
25
+ if api[:user]
26
+ request.basic_auth(api[:user], api[:password])
27
+ end
28
+ Net::HTTP.new(api[:host] || '127.0.0.1', api[:port] || 4567).start do |http|
29
+ http.request(request)
30
+ end
31
+ end
32
+
33
+ # Check to see if an event exists for a client/check pair. This
34
+ # method is looking for a HTTP response code of `200`.
35
+ #
36
+ # @param client_name [String]
37
+ # @param check_name [String]
38
+ # @return [Boolean]
39
+ def event_exists?(client_name, check_name)
40
+ path = "/events/#{client_name}/#{check_name}"
41
+ response = sensu_api_get_request(path)
42
+ response.code.to_i == 200
43
+ end
44
+
45
+ # Determine if an event exists for any of the check
46
+ # dependencies declared in the event data, specified in array,
47
+ # 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`).
50
+ #
51
+ # @param event [Hash]
52
+ # @return [Boolean]
53
+ def dependency_events_exist?(event)
54
+ if event[:check][:dependencies].is_a?(Array)
55
+ event[:check][:dependencies].any? do |dependency|
56
+ begin
57
+ check_name, client_name = dependency.split("/").reverse
58
+ client_name ||= event[:client][:name]
59
+ event_exists?(client_name, check_name)
60
+ rescue => error
61
+ @logger.error("failed to query api for a check dependency event", :error => error)
62
+ false
63
+ end
64
+ end
65
+ else
66
+ false
67
+ end
68
+ end
69
+
70
+ def run(event, &callback)
71
+ filter = Proc.new do
72
+ begin
73
+ Timeout::timeout(10) do
74
+ if dependency_events_exist?(event)
75
+ ["event exists for check dependency", 0]
76
+ else
77
+ ["no current events for check dependencies", 1]
78
+ end
79
+ end
80
+ rescue => error
81
+ @logger.error("check dependencies filter error", :error => error.to_s)
82
+ ["check dependencies filter error: #{error}", 1]
83
+ end
84
+ end
85
+ EM.defer(filter, callback)
86
+ end
87
+ end
88
+ end
89
+ end
metadata ADDED
@@ -0,0 +1,145 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: sensu-extensions-check-dependencies
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Sensu Inc
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-02-14 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sensu-extension
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
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: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '1.6'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '1.6'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: webmock
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sensu-logger
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: sensu-settings
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ description: Filter events when an event already exists for a defined check dependency
112
+ email:
113
+ - "<support@sensu.io>"
114
+ executables: []
115
+ extensions: []
116
+ extra_rdoc_files: []
117
+ files:
118
+ - CHANGELOG.md
119
+ - LICENSE
120
+ - README.md
121
+ - lib/sensu/extensions/check_dependencies.rb
122
+ homepage: https://github.com/sensu-extensions/sensu-extensions-check-dependencies
123
+ licenses: []
124
+ metadata: {}
125
+ post_install_message:
126
+ rdoc_options: []
127
+ require_paths:
128
+ - lib
129
+ required_ruby_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ required_rubygems_version: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ requirements: []
140
+ rubyforge_project:
141
+ rubygems_version: 2.6.6
142
+ signing_key:
143
+ specification_version: 4
144
+ summary: Filter events when an event already exists for a defined check dependency
145
+ test_files: []