sensu-handlers-purge-stale-results 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/CHANGELOG.md +10 -0
- data/LICENSE +23 -0
- data/README.md +26 -0
- data/bin/handler-purge-stale-results.rb +92 -0
- data/lib/sensu-handlers-purge-stale-results.rb +1 -0
- data/lib/sensu-handlers-purge-stale-results/version.rb +9 -0
- metadata +84 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: bebea96733d92f1f6081887b924384cbacad1686
|
4
|
+
data.tar.gz: e6712baa669754deb91039418c03554c6cbaf248
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a027e987e1bee13a6240dab13b75c94d2ade71a17ab4f11081d79b060c4020df1a147f40fa21b5d14df95d9eb28e756c15dced3cc4649c7115712dd3a6eb1236
|
7
|
+
data.tar.gz: 677d9e8334add570841004aed41aa7e0268756e999bdd6d6d15b69f0700ed4ecb712d7406d60bdd0a993e221ceeff6e6b9fb4591ccc2a437e9832af5e38b203e
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2016 Matteo Cerutti
|
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.
|
23
|
+
|
data/README.md
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# Sensu handler for purging stale check results
|
2
|
+
|
3
|
+
A sensu handler to purge stale check results. This handler can be invoked from a check that uses the the [sensu-plugins-stale-results](http://github.com/m4ce/sensu-plugins-stale-results) plugin.
|
4
|
+
|
5
|
+
## Usage
|
6
|
+
|
7
|
+
The handler accepts the following command line options:
|
8
|
+
|
9
|
+
```
|
10
|
+
Usage: handler-purge-stale-results.rb (options)
|
11
|
+
--mail-recipient <ADDRESS> Mail recipient (required)
|
12
|
+
--mail-sender <ADDRESS> Mail sender (default: sensu@localhost)
|
13
|
+
--mail-server <HOST> Mail server (default: localhost)
|
14
|
+
-s, --stale <TIME> Elapsed time after which a stale check result will be deleted (default: 7d)
|
15
|
+
```
|
16
|
+
|
17
|
+
the --stale command line option accepts elapsed times formatted as documented in https://github.com/hpoydar/chronic_duration.
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
```
|
22
|
+
/opt/sensu/embedded/bin/gem install sensu-handlers-purge-stale-results
|
23
|
+
```
|
24
|
+
|
25
|
+
## Author
|
26
|
+
Matteo Cerutti - <matteo.cerutti@hotmail.co.uk>
|
@@ -0,0 +1,92 @@
|
|
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 get_results()
|
37
|
+
results = []
|
38
|
+
|
39
|
+
if req = api_request(:GET, "/results")
|
40
|
+
results = JSON.parse(req.body) if req.code == '200'
|
41
|
+
end
|
42
|
+
|
43
|
+
results
|
44
|
+
end
|
45
|
+
|
46
|
+
def handle
|
47
|
+
deleted = []
|
48
|
+
failed = []
|
49
|
+
|
50
|
+
get_results().each do |result|
|
51
|
+
if (diff = Time.now.to_i - result['check']['issued']) > config[:stale]
|
52
|
+
begin
|
53
|
+
req = api_request(:DELETE, "/results/#{result['client']}/#{result['check']['name']}")
|
54
|
+
if req.code != '204'
|
55
|
+
failed << "#{result['client']} - #{result['check']['name']} (Code: #{req.code}, Message: #{req.body})"
|
56
|
+
else
|
57
|
+
deleted << "#{result['client']} - #{result['check']['name']}"
|
58
|
+
end
|
59
|
+
rescue
|
60
|
+
failed << "#{result['client']} - #{result['check']['name']} (Caught exception: #{$!})"
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
if deleted.size > 0 or failed.size > 0
|
66
|
+
msg = <<EOF
|
67
|
+
From: Sensu <#{config[:mail_sender]}>
|
68
|
+
To: <#{config[:mail_recipient]}>
|
69
|
+
Subject: Purge stale check results
|
70
|
+
|
71
|
+
This is a notification concerning the #{self.class.name} sensu handler running at #{Socket.gethostname()}
|
72
|
+
|
73
|
+
* Summary
|
74
|
+
|
75
|
+
Deleted: #{deleted.size}
|
76
|
+
Failed to delete: #{failed.size}
|
77
|
+
|
78
|
+
* Failed to delete check results:
|
79
|
+
|
80
|
+
#{failed.map { |m| " #{m}" }.join("\n")}
|
81
|
+
|
82
|
+
* Deleted check results:
|
83
|
+
|
84
|
+
#{deleted.map { |m| " #{m}" }.join("\n")}
|
85
|
+
EOF
|
86
|
+
|
87
|
+
Net::SMTP.start(config[:mail_server]) do |smtp|
|
88
|
+
smtp.send_message(msg, config[:mail_sender], config[:mail_recipient])
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sensu-handlers-purge-stale-results/version'
|
metadata
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-handlers-purge-stale-results
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Matteo Cerutti
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-01-14 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: sensu-plugin
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.2.0
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.2.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: chronic_duration
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.10.6
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.10.6
|
41
|
+
description: This handler provides facilities for purging stale check events
|
42
|
+
email: "<matteo.cerutti@hotmail.co.uk>"
|
43
|
+
executables:
|
44
|
+
- handler-purge-stale-results.rb
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- CHANGELOG.md
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- bin/handler-purge-stale-results.rb
|
52
|
+
- lib/sensu-handlers-purge-stale-results.rb
|
53
|
+
- lib/sensu-handlers-purge-stale-results/version.rb
|
54
|
+
homepage: https://github.com/m4ce/sensu-handlers-purge-stale-results
|
55
|
+
licenses:
|
56
|
+
- MIT
|
57
|
+
metadata:
|
58
|
+
maintainer: "@m4ce"
|
59
|
+
development_status: active
|
60
|
+
production_status: stable
|
61
|
+
release_draft: 'false'
|
62
|
+
release_prerelease: 'false'
|
63
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
64
|
+
in /etc/default/sensu
|
65
|
+
rdoc_options: []
|
66
|
+
require_paths:
|
67
|
+
- lib
|
68
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
version: 1.9.3
|
73
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
|
+
requirements:
|
75
|
+
- - ">="
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: '0'
|
78
|
+
requirements: []
|
79
|
+
rubyforge_project:
|
80
|
+
rubygems_version: 2.4.5.1
|
81
|
+
signing_key:
|
82
|
+
specification_version: 4
|
83
|
+
summary: Sensu handler for purging stale check results
|
84
|
+
test_files: []
|