sensu-run-check 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +2 -2
- data/lib/sensu-run-check/runner.rb +53 -5
- data/lib/sensu-run-check/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 124fa69d27a4dc7394117818fc7ae64f01a349f4
|
4
|
+
data.tar.gz: c8c8073b37ca4ccce499be14337a9dab581232f7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 46b7d5a9c7cd60eae203612e285364b47eaa0f0d06951f5ce8b8bdb4a5cf97a0d18415865a8b64749529aec958e6def984586397b3a93981dcae0cfddadd13ca
|
7
|
+
data.tar.gz: 6b679510da951ea62c99d9036ed409f6f29b36f0295385c43c51e77f6d2c1a7665d2f1b5cb69c449c1be1499ce78bcab55fc081fa6ba91a40a9cb0ba2f9a5620
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Sensu Run Check
|
2
2
|
|
3
|
-
Often after just doing a change on servers you want to just be sure that they’re all going to pass a certain or all Sensu checks. This gem exposes
|
3
|
+
Often after just doing a change on servers you want to just be sure that they’re all going to pass a certain or all (Sensu)[http://sensuapp.org] checks. This gem exposes Sensu checks to be executed local on the command line.
|
4
4
|
|
5
5
|
_WARNING_ This is very much a hack and will break with other versions* of Sensu!
|
6
6
|
|
@@ -44,4 +44,4 @@ Run all checks defined on this host.
|
|
44
44
|
|
45
45
|
(c) 2015 - Rickard von Essen
|
46
46
|
|
47
|
-
Released under the MIT license, see LICENSE.txt
|
47
|
+
Released under the MIT license, see LICENSE.txt
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require "rubygems"
|
2
2
|
|
3
|
+
require "open3"
|
3
4
|
require "sensu-run-check/version"
|
4
5
|
require "sensu/client/process"
|
5
6
|
require "sensu/settings"
|
@@ -34,6 +35,7 @@ module SensuRunCheck
|
|
34
35
|
statuses = []
|
35
36
|
s.get_all_checks.collect{ |check| check[:name] }.sort.each do |checkname|
|
36
37
|
stdout, status = s.run_check(checkname)
|
38
|
+
status ||= 3
|
37
39
|
statuses << status
|
38
40
|
puts "#{checkname} #{status} #{stdout}"
|
39
41
|
end
|
@@ -41,6 +43,7 @@ module SensuRunCheck
|
|
41
43
|
else
|
42
44
|
stdout, status = s.run_check(options[:run_check])
|
43
45
|
puts stdout
|
46
|
+
status ||= 3
|
44
47
|
exit(status)
|
45
48
|
end
|
46
49
|
end
|
@@ -57,6 +60,47 @@ module SensuRunCheck
|
|
57
60
|
@logger = SensuRunCheck::NilLog.new
|
58
61
|
end
|
59
62
|
|
63
|
+
# Execute a check command, capturing its output (STDOUT/ERR),
|
64
|
+
# exit status code, execution duration, timestamp, and publish
|
65
|
+
# the result. This method guards against multiple executions for
|
66
|
+
# the same check. Check command tokens are substituted with the
|
67
|
+
# associated client attribute values. If there are unmatched
|
68
|
+
# check command tokens, the check command will not be executed,
|
69
|
+
# instead a check result will be published reporting the
|
70
|
+
# unmatched tokens.
|
71
|
+
#
|
72
|
+
# @param check [Hash]
|
73
|
+
def execute_check_command(check)
|
74
|
+
@logger.debug("attempting to execute check command", :check => check)
|
75
|
+
unless @checks_in_progress.include?(check[:name])
|
76
|
+
@checks_in_progress << check[:name]
|
77
|
+
command, unmatched_tokens = substitute_check_command_tokens(check)
|
78
|
+
if unmatched_tokens.empty?
|
79
|
+
check[:executed] = Time.now.to_i
|
80
|
+
started = Time.now.to_f
|
81
|
+
|
82
|
+
output, status = Open3.capture2(command)
|
83
|
+
check[:duration] = ("%.3f" % (Time.now.to_f - started)).to_f
|
84
|
+
check[:output] = output
|
85
|
+
check[:status] = status.exitstatus
|
86
|
+
@checks_in_progress.delete(check[:name])
|
87
|
+
publish_check_result(check)
|
88
|
+
else
|
89
|
+
check[:output] = "Unmatched command tokens: " + unmatched_tokens.join(", ")
|
90
|
+
check[:status] = 3
|
91
|
+
check[:handle] = false
|
92
|
+
@checks_in_progress.delete(check[:name])
|
93
|
+
publish_check_result(check)
|
94
|
+
end
|
95
|
+
else
|
96
|
+
@logger.warn("previous check command execution in progress", :check => check)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
def publish_check_result(check)
|
101
|
+
return check[:output], check[:status]
|
102
|
+
end
|
103
|
+
|
60
104
|
# Find a Sensu check by name.
|
61
105
|
#
|
62
106
|
# @param [String] name of the check
|
@@ -84,16 +128,20 @@ module SensuRunCheck
|
|
84
128
|
execute_check_command(check)
|
85
129
|
end
|
86
130
|
end
|
87
|
-
|
88
131
|
end
|
89
132
|
|
90
133
|
# Swallow logs
|
91
134
|
class NilLog
|
92
|
-
def
|
93
|
-
|
135
|
+
def initialize
|
136
|
+
self.class.create_level_methods
|
94
137
|
end
|
95
|
-
|
96
|
-
|
138
|
+
|
139
|
+
def self.create_level_methods
|
140
|
+
Sensu::Logger::LEVELS.each do |level|
|
141
|
+
define_method(level) do |*args|
|
142
|
+
# Do nothing
|
143
|
+
end
|
144
|
+
end
|
97
145
|
end
|
98
146
|
end
|
99
147
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sensu-run-check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Rickard von Essen
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-04-
|
11
|
+
date: 2015-04-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: sensu
|