sensu-plugins-sensu 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -1
- data/README.md +34 -0
- data/bin/check-stale-results.rb +109 -0
- data/bin/handler-purge-stale-results.rb +90 -0
- data/lib/sensu-plugins-sensu/version.rb +1 -1
- metadata +20 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db61d659c304cbb69bab103dc96810acc18b303e
|
4
|
+
data.tar.gz: 65d88dbf81a056122cf421e2eef2a354e0cb7971
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87ba1a72154774b05550e1969d7e3f6a7129921371cff565bb29067f74b3502d499628886929efb20450b0633dda14d2a37083dd391ce9121c1ff6a573863308
|
7
|
+
data.tar.gz: 06d0d10142e70be953d73eef0b233eda4e4b4ef25d2b1632d4c7a2fee9b11dedd26a6e5bcadcf1e89008e15033abd7db4c930768ddd88e5b0ed00e92cb452c12
|
data/CHANGELOG.md
CHANGED
@@ -5,6 +5,11 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
5
5
|
|
6
6
|
## [Unreleased]
|
7
7
|
|
8
|
+
## [2.1.0] - 2017-08-29
|
9
|
+
### Added
|
10
|
+
- check-stale-results.rb: new script to check for stale results in sensu (@m4ce)
|
11
|
+
- handler-purge-stale-results.rb: new handler to purge stale results from sensu (@m4ce)
|
12
|
+
|
8
13
|
## [2.0.0] - 2017-08-20
|
9
14
|
### Breaking Changes
|
10
15
|
- check-aggregates.rb: Changed the default behaviour to alert with the severity of the aggregated checks.
|
@@ -64,7 +69,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
|
|
64
69
|
### Added
|
65
70
|
- initial release
|
66
71
|
|
67
|
-
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-sensu/compare/
|
72
|
+
[Unreleased]: https://github.com/sensu-plugins/sensu-plugins-sensu/compare/2.1.0...HEAD
|
73
|
+
[2.1.0]: https://github.com/sensu-plugins/sensu-plugins-sensu/compare/2.0.0...2.1.0
|
68
74
|
[2.0.0]: https://github.com/sensu-plugins/sensu-plugins-sensu/compare/1.1.1...2.0.0
|
69
75
|
[1.1.1]: https://github.com/sensu-plugins/sensu-plugins-sensu/compare/1.1.0...1.1.1
|
70
76
|
[1.1.0]: https://github.com/sensu-plugins/sensu-plugins-sensu/compare/1.0.0...1.1.0
|
data/README.md
CHANGED
@@ -10,14 +10,48 @@
|
|
10
10
|
|
11
11
|
## Files
|
12
12
|
* bin/check-aggregate.rb
|
13
|
+
* bin/check-stale-results.rb
|
13
14
|
* bin/metrics-aggregate.rb
|
14
15
|
* bin/metrics-delete-expired-stashes.rb
|
15
16
|
* bin/metrics-events.rb
|
16
17
|
* bin/handler-sensu.rb
|
17
18
|
* bin/handler-sensu-deregister.rb
|
19
|
+
* bin/handler-purge-stale-results.rb
|
18
20
|
|
19
21
|
## Usage
|
20
22
|
|
23
|
+
### check-stale-results.rb
|
24
|
+
|
25
|
+
A sensu plugin to monitor sensu stale check results. You can then implement an handler that purges the results after X days using the `handlers-purge-stale-results` handler.
|
26
|
+
|
27
|
+
The plugin accepts the following command line options:
|
28
|
+
|
29
|
+
```
|
30
|
+
Usage: check-stale-results.rb (options)
|
31
|
+
-c, --crit <COUNT> Critical if number of stale check results exceeds COUNT
|
32
|
+
-s, --stale <TIME> Elapsed time to consider a check result result (default: 1d)
|
33
|
+
-v, --verbose Be verbose
|
34
|
+
-w, --warn <COUNT> Warn if number of stale check results exceeds COUNT (default: 1)
|
35
|
+
```
|
36
|
+
|
37
|
+
the --stale command line option accepts elapsed times formatted as documented in https://github.com/hpoydar/chronic_duration.
|
38
|
+
|
39
|
+
The handler accepts the following command line options:
|
40
|
+
|
41
|
+
### handler-purge-stale-results.rb
|
42
|
+
|
43
|
+
A sensu handler to purge stale check results. This handler can be invoked from a check that uses the the `check-stale-results` plugin.
|
44
|
+
|
45
|
+
```
|
46
|
+
Usage: handler-purge-stale-results.rb (options)
|
47
|
+
--mail-recipient <ADDRESS> Mail recipient (required)
|
48
|
+
--mail-sender <ADDRESS> Mail sender (default: sensu@localhost)
|
49
|
+
--mail-server <HOST> Mail server (default: localhost)
|
50
|
+
-s, --stale <TIME> Elapsed time after which a stale check result will be deleted (default: 7d)
|
51
|
+
```
|
52
|
+
|
53
|
+
the --stale command line option accepts elapsed times formatted as documented in https://github.com/hpoydar/chronic_duration.
|
54
|
+
|
21
55
|
## Installation
|
22
56
|
|
23
57
|
[Installation and Setup](http://sensu-plugins.io/docs/installation_instructions.html)
|
@@ -0,0 +1,109 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# check-stale-results.rb
|
4
|
+
#
|
5
|
+
# Author: Matteo Cerutti <matteo.cerutti@hotmail.co.uk>
|
6
|
+
#
|
7
|
+
|
8
|
+
require 'net/http'
|
9
|
+
require 'json'
|
10
|
+
require 'sensu-plugin/utils'
|
11
|
+
require 'sensu-plugin/check/cli'
|
12
|
+
require 'chronic_duration'
|
13
|
+
|
14
|
+
class CheckStaleResults < Sensu::Plugin::Check::CLI
|
15
|
+
include Sensu::Plugin::Utils
|
16
|
+
|
17
|
+
option :stale,
|
18
|
+
description: 'Elapsed time to consider a check result result (default: 1d)',
|
19
|
+
short: '-s <TIME>',
|
20
|
+
long: '--stale <TIME>',
|
21
|
+
proc: proc { |s| ChronicDuration.parse(s) },
|
22
|
+
default: ChronicDuration.parse('1d')
|
23
|
+
|
24
|
+
option :verbose,
|
25
|
+
description: 'Be verbose',
|
26
|
+
short: '-v',
|
27
|
+
long: '--verbose',
|
28
|
+
boolean: true,
|
29
|
+
default: false
|
30
|
+
|
31
|
+
option :warn,
|
32
|
+
description: 'Warn if number of stale check results exceeds COUNT (default: 1)',
|
33
|
+
short: '-w <COUNT>',
|
34
|
+
long: '--warn <COUNT>',
|
35
|
+
proc: proc(&:to_i),
|
36
|
+
default: 1
|
37
|
+
|
38
|
+
option :crit,
|
39
|
+
description: 'Critical if number of stale check results exceeds COUNT',
|
40
|
+
short: '-c <COUNT>',
|
41
|
+
long: '--crit <COUNT>',
|
42
|
+
proc: proc(&:to_i),
|
43
|
+
default: nil
|
44
|
+
|
45
|
+
def initialize
|
46
|
+
super
|
47
|
+
|
48
|
+
raise 'Critical threshold must be higher than the warning threshold' if config[:crit] && config[:warn] >= config[:crit]
|
49
|
+
|
50
|
+
# get list of sensu results
|
51
|
+
@results = results
|
52
|
+
end
|
53
|
+
|
54
|
+
def humanize(secs)
|
55
|
+
[[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map do |count, name|
|
56
|
+
if secs > 0
|
57
|
+
secs, n = secs.divmod(count)
|
58
|
+
"#{n.to_i} #{name}"
|
59
|
+
end
|
60
|
+
end.compact.reverse.join(' ')
|
61
|
+
end
|
62
|
+
|
63
|
+
def api_request(method, path, _blk)
|
64
|
+
unless settings.key?('api')
|
65
|
+
raise 'api.json settings not found.'
|
66
|
+
end
|
67
|
+
http = Net::HTTP.new(settings['api']['host'], settings['api']['port'])
|
68
|
+
req = net_http_req_class(method).new(path)
|
69
|
+
if settings['api']['user'] && settings['api']['password']
|
70
|
+
req.basic_auth(settings['api']['user'], settings['api']['password'])
|
71
|
+
end
|
72
|
+
yield(req) if block_given?
|
73
|
+
http.request(req)
|
74
|
+
end
|
75
|
+
|
76
|
+
def results
|
77
|
+
res = []
|
78
|
+
req = api_request(:GET, '/results')
|
79
|
+
res = JSON.parse(req.body) if req && req.code == '200'
|
80
|
+
res
|
81
|
+
end
|
82
|
+
|
83
|
+
def run
|
84
|
+
stale = 0
|
85
|
+
footer = "\n\n"
|
86
|
+
@results.each do |result|
|
87
|
+
diff = Time.now.to_i - result['check']['issued']
|
88
|
+
if diff > config[:stale]
|
89
|
+
stale += 1
|
90
|
+
footer += " - check result #{result['client']}/#{result['check']['name']} is stale (#{humanize(diff)})\n"
|
91
|
+
end
|
92
|
+
end
|
93
|
+
footer += "\n"
|
94
|
+
|
95
|
+
if config[:crit] && stale >= config[:crit]
|
96
|
+
msg = "Found #{stale} stale check results (>= #{config[:crit]})"
|
97
|
+
msg += footer if config[:verbose]
|
98
|
+
critical(msg)
|
99
|
+
end
|
100
|
+
|
101
|
+
if stale >= config[:warn]
|
102
|
+
msg = "Found #{stale} stale check results (>= #{config[:warn]})"
|
103
|
+
msg += footer if config[:verbose]
|
104
|
+
warning(msg)
|
105
|
+
end
|
106
|
+
|
107
|
+
ok("No stale check results found (>= #{config[:warn]})")
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
#
|
2
|
+
# handler-purge-stale-results.rb
|
3
|
+
#
|
4
|
+
# Author: Matteo Cerutti <matteo.cerutti@hotmail.co.uk>
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'sensu-handler'
|
8
|
+
require 'time'
|
9
|
+
require 'net/smtp'
|
10
|
+
require 'socket'
|
11
|
+
require 'chronic_duration'
|
12
|
+
|
13
|
+
class HandlerPurgeStaleResults < Sensu::Handler
|
14
|
+
option :stale,
|
15
|
+
description: 'Elapsed time after which a stale check result will be deleted (default: 7d)',
|
16
|
+
short: '-s <TIME>',
|
17
|
+
long: '--stale <TIME>',
|
18
|
+
proc: proc { |s| ChronicDuration.parse(s) },
|
19
|
+
default: ChronicDuration.parse('7d')
|
20
|
+
|
21
|
+
option :mail_server,
|
22
|
+
description: 'Mail server (default: localhost)',
|
23
|
+
long: '--mail-server <HOST>',
|
24
|
+
default: 'localhost'
|
25
|
+
|
26
|
+
option :mail_sender,
|
27
|
+
description: 'Mail sender (default: sensu@localhost)',
|
28
|
+
long: '--mail-sender <ADDRESS>',
|
29
|
+
default: 'sensu@localhost'
|
30
|
+
|
31
|
+
option :mail_recipient,
|
32
|
+
description: 'Mail recipient',
|
33
|
+
long: '--mail-recipient <ADDRESS>',
|
34
|
+
required => true
|
35
|
+
|
36
|
+
def results
|
37
|
+
res = []
|
38
|
+
req = api_request(:GET, '/results')
|
39
|
+
res = JSON.parse(req.body) if req && req.code == '200'
|
40
|
+
res
|
41
|
+
end
|
42
|
+
|
43
|
+
def handle
|
44
|
+
deleted = []
|
45
|
+
failed = []
|
46
|
+
|
47
|
+
results.each do |result|
|
48
|
+
diff = Time.now.to_i - result['check']['issued']
|
49
|
+
if diff > config[:stale]
|
50
|
+
begin
|
51
|
+
req = api_request(:DELETE, "/results/#{result['client']}/#{result['check']['name']}")
|
52
|
+
if req.code != '204'
|
53
|
+
failed << "#{result['client']} - #{result['check']['name']} (Code: #{req.code}, Message: #{req.body})"
|
54
|
+
else
|
55
|
+
deleted << "#{result['client']} - #{result['check']['name']}"
|
56
|
+
end
|
57
|
+
rescue
|
58
|
+
failed << "#{result['client']} - #{result['check']['name']} (Caught exception: #{$ERROR_INFO})"
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
if !deleted.empty? || !failed.empty?
|
64
|
+
msg = <<EOF
|
65
|
+
From: Sensu <#{config[:mail_sender]}>
|
66
|
+
To: <#{config[:mail_recipient]}>
|
67
|
+
Subject: Purge stale check results
|
68
|
+
|
69
|
+
This is a notification concerning the #{self.class.name} sensu handler running at #{Socket.gethostname}
|
70
|
+
|
71
|
+
* Summary
|
72
|
+
|
73
|
+
Deleted: #{deleted.size}
|
74
|
+
Failed to delete: #{failed.size}
|
75
|
+
|
76
|
+
* Failed to delete check results:
|
77
|
+
|
78
|
+
#{failed.map { |m| " #{m}" }.join("\n")}
|
79
|
+
|
80
|
+
* Deleted check results:
|
81
|
+
|
82
|
+
#{deleted.map { |m| " #{m}" }.join("\n")}
|
83
|
+
EOF
|
84
|
+
|
85
|
+
Net::SMTP.start(config[:mail_server]) do |smtp|
|
86
|
+
smtp.send_message(msg, config[:mail_sender], config[:mail_recipient])
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-plugins-sensu
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sensu-Plugins and contributors
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-08-
|
11
|
+
date: 2017-08-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu-plugin
|
@@ -52,6 +52,20 @@ dependencies:
|
|
52
52
|
- - '='
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: 0.6.3
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: chronic_duration
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.10.6
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: 0.10.6
|
55
69
|
- !ruby/object:Gem::Dependency
|
56
70
|
name: bundler
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -182,6 +196,8 @@ description: This plugin provides monitoring and metrics for Sensu.
|
|
182
196
|
email: "<sensu-users@googlegroups.com>"
|
183
197
|
executables:
|
184
198
|
- check-aggregate.rb
|
199
|
+
- check-stale-results.rb
|
200
|
+
- handler-purge-stale-results.rb
|
185
201
|
- handler-sensu-deregister.rb
|
186
202
|
- handler-sensu.rb
|
187
203
|
- metrics-aggregate.rb
|
@@ -194,6 +210,8 @@ files:
|
|
194
210
|
- LICENSE
|
195
211
|
- README.md
|
196
212
|
- bin/check-aggregate.rb
|
213
|
+
- bin/check-stale-results.rb
|
214
|
+
- bin/handler-purge-stale-results.rb
|
197
215
|
- bin/handler-sensu-deregister.rb
|
198
216
|
- bin/handler-sensu.rb
|
199
217
|
- bin/metrics-aggregate.rb
|