sensu-plugins-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 +19 -0
- data/bin/check-stale-results.rb +110 -0
- data/lib/sensu-plugins-stale-results/version.rb +9 -0
- data/lib/sensu-plugins-stale-results.rb +1 -0
- metadata +70 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a8a39c2cb442994fb202eabfb166b091bddb2647
|
4
|
+
data.tar.gz: e166f302c89193ef6aba9b6a681d04afb9ecbcb5
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: d34335670082a4b28182deaccfb04d2d95125d4914bce2401a8f1fadd46731e138deb7a0a650f5a96c9ee846d376cb9bb80a2f1a2f1e3de09f56619bdd028bc5
|
7
|
+
data.tar.gz: 2fe77c146b125530c5af4dd081b8739af65963731105aa2d29a096ca93c840b52bc62015425b85de2b9f400fa8da7972d70d0972bc25e8ea0ebcab8237287659
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
Copyright (c) 2015 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,19 @@
|
|
1
|
+
# Sensu plugin for monitoring Sensu stale check results
|
2
|
+
|
3
|
+
A sensu plugin to monitor sensu stale check results. You can then implement an handler that purges
|
4
|
+
the results after X occurences.
|
5
|
+
|
6
|
+
## Usage
|
7
|
+
|
8
|
+
The plugin accepts the following command line options:
|
9
|
+
|
10
|
+
```
|
11
|
+
Usage: check-stale-results.rb (options)
|
12
|
+
-c, --crit <COUNT> Critical if number of stale check results exceeds COUNT
|
13
|
+
-s, --stale <SECONDS> Number of seconds to consider a check result stale (default: 86400)
|
14
|
+
-v, --verbose Be verbose
|
15
|
+
-w, --warn <COUNT> Warn if number of stale check results exceeds COUNT (default: 1)
|
16
|
+
```
|
17
|
+
|
18
|
+
## Author
|
19
|
+
Matteo Cerutti - <matteo.cerutti@hotmail.co.uk>
|
@@ -0,0 +1,110 @@
|
|
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
|
+
|
13
|
+
class CheckStaleResults < Sensu::Plugin::Check::CLI
|
14
|
+
include Sensu::Plugin::Utils
|
15
|
+
|
16
|
+
option :stale,
|
17
|
+
:description => "Number of seconds to consider a check result stale (default: 86400)",
|
18
|
+
:short => "-s <SECONDS>",
|
19
|
+
:long => "--stale <SECONDS>",
|
20
|
+
:proc => proc(&:to_i),
|
21
|
+
:default => 86400
|
22
|
+
|
23
|
+
option :verbose,
|
24
|
+
:description => "Be verbose",
|
25
|
+
:short => "-v",
|
26
|
+
:long => "--verbose",
|
27
|
+
:boolean => true,
|
28
|
+
:default => false
|
29
|
+
|
30
|
+
option :warn,
|
31
|
+
:description => "Warn if number of stale check results exceeds COUNT (default: 1)",
|
32
|
+
:short => "-w <COUNT>",
|
33
|
+
:long => "--warn <COUNT>",
|
34
|
+
:proc => proc(&:to_i),
|
35
|
+
:default => 1
|
36
|
+
|
37
|
+
option :crit,
|
38
|
+
:description => "Critical if number of stale check results exceeds COUNT",
|
39
|
+
:short => "-c <COUNT>",
|
40
|
+
:long => "--crit <COUNT>",
|
41
|
+
:proc => proc(&:to_i),
|
42
|
+
:default => nil
|
43
|
+
|
44
|
+
def initialize()
|
45
|
+
super
|
46
|
+
|
47
|
+
raise "Critical threshold must be higher than the warning threshold" if (config[:crit] and config[:warn] >= config[:crit])
|
48
|
+
|
49
|
+
# get list of sensu results
|
50
|
+
@results = get_results()
|
51
|
+
end
|
52
|
+
|
53
|
+
def humanize(secs)
|
54
|
+
[[60, :seconds], [60, :minutes], [24, :hours], [1000, :days]].map { |count, name|
|
55
|
+
if secs > 0
|
56
|
+
secs, n = secs.divmod(count)
|
57
|
+
"#{n.to_i} #{name}"
|
58
|
+
end
|
59
|
+
}.compact.reverse.join(' ')
|
60
|
+
end
|
61
|
+
|
62
|
+
def api_request(method, path, &blk)
|
63
|
+
if not settings.has_key?('api')
|
64
|
+
raise "api.json settings not found."
|
65
|
+
end
|
66
|
+
http = Net::HTTP.new(settings['api']['host'], settings['api']['port'])
|
67
|
+
req = net_http_req_class(method).new(path)
|
68
|
+
if settings['api']['user'] && settings['api']['password']
|
69
|
+
req.basic_auth(settings['api']['user'], settings['api']['password'])
|
70
|
+
end
|
71
|
+
yield(req) if block_given?
|
72
|
+
http.request(req)
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_results()
|
76
|
+
results = []
|
77
|
+
|
78
|
+
if req = api_request(:GET, "/results")
|
79
|
+
results = JSON.parse(req.body) if req.code == '200'
|
80
|
+
end
|
81
|
+
|
82
|
+
results
|
83
|
+
end
|
84
|
+
|
85
|
+
def run()
|
86
|
+
stale = 0
|
87
|
+
footer = "\n\n"
|
88
|
+
@results.each do |result|
|
89
|
+
if (diff = Time.now.to_i - result['check']['issued']) > config[:stale]
|
90
|
+
stale += 1
|
91
|
+
footer += " - check result #{result['client']}/#{result['check']['name']} is stale (#{humanize(diff)})\n"
|
92
|
+
end
|
93
|
+
end
|
94
|
+
footer += "\n"
|
95
|
+
|
96
|
+
if (config[:crit] and stale >= config[:crit])
|
97
|
+
msg = "Found #{stale} stale check results (>= #{config[:crit]})"
|
98
|
+
msg += footer if config[:verbose]
|
99
|
+
critical(msg)
|
100
|
+
end
|
101
|
+
|
102
|
+
if stale >= config[:warn]
|
103
|
+
msg = "Found #{stale} stale check results (>= #{config[:warn]})"
|
104
|
+
msg += footer if config[:verbose]
|
105
|
+
warning(msg)
|
106
|
+
end
|
107
|
+
|
108
|
+
ok("No stale check results found (>= #{config[:warn]})")
|
109
|
+
end
|
110
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'sensu-plugins-stale-results/version'
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sensu-plugins-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-13 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
|
+
description: This plugin provides facilities for monitoring stale sensu check results
|
28
|
+
email: "<matteo.cerutti@hotmail.co.uk>"
|
29
|
+
executables:
|
30
|
+
- check-stale-results.rb
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- CHANGELOG.md
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- bin/check-stale-results.rb
|
38
|
+
- lib/sensu-plugins-stale-results.rb
|
39
|
+
- lib/sensu-plugins-stale-results/version.rb
|
40
|
+
homepage: https://github.com/m4ce/sensu-plugins-stale-results
|
41
|
+
licenses:
|
42
|
+
- MIT
|
43
|
+
metadata:
|
44
|
+
maintainer: "@m4ce"
|
45
|
+
development_status: active
|
46
|
+
production_status: stable
|
47
|
+
release_draft: 'false'
|
48
|
+
release_prerelease: 'false'
|
49
|
+
post_install_message: You can use the embedded Ruby by setting EMBEDDED_RUBY=true
|
50
|
+
in /etc/default/sensu
|
51
|
+
rdoc_options: []
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
55
|
+
requirements:
|
56
|
+
- - ">="
|
57
|
+
- !ruby/object:Gem::Version
|
58
|
+
version: 1.9.3
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '0'
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 2.4.5.1
|
67
|
+
signing_key:
|
68
|
+
specification_version: 4
|
69
|
+
summary: Sensu plugins for monitoring stale check results
|
70
|
+
test_files: []
|