sensu 0.27.0.alpha → 0.27.0.alpha.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/exe/sensu-install +59 -10
- data/lib/sensu/client/http_socket.rb +183 -0
- data/lib/sensu/client/process.rb +12 -1
- data/lib/sensu/client/socket.rb +3 -59
- data/lib/sensu/client/utils.rb +65 -0
- data/lib/sensu/constants.rb +1 -1
- data/lib/sensu/daemon.rb +2 -2
- data/sensu.gemspec +2 -2
- metadata +9 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 994997d6e22b6bbb53345295b583987194967aaa
|
|
4
|
+
data.tar.gz: 58c8d9573c10beaca0f4c4ef880ff9a9c724b028
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 33bbfc2de4defdb2ac1c0a107962453159380bb8238ddbbb392445bae96bc956dde882e776b64aa0ee0a2fd20579d47cdb8c5f79cbac3d595dc25e5cec21e4d3
|
|
7
|
+
data.tar.gz: 2dfb80ad2efd1a65222c56e4b08a3db91e337f285f2285a38a4e36d4147ecfd82149c9906bd1859af9bde0e7ed7911e7db3450afce8cf109ec1258beba8c199a
|
data/exe/sensu-install
CHANGED
|
@@ -9,7 +9,8 @@ module Sensu
|
|
|
9
9
|
options = {
|
|
10
10
|
:verbose => false,
|
|
11
11
|
:plugins => [],
|
|
12
|
-
:extensions => []
|
|
12
|
+
:extensions => [],
|
|
13
|
+
:clean => false
|
|
13
14
|
}
|
|
14
15
|
optparse = OptionParser.new do |opts|
|
|
15
16
|
opts.on("-h", "--help", "Display this message") do
|
|
@@ -31,9 +32,12 @@ module Sensu
|
|
|
31
32
|
opts.on("-E", "--extensions EXTENSION[,EXT]", "EXTENSION or comma-delimited list of Sensu extensions to install") do |extensions|
|
|
32
33
|
options[:extensions].concat(extensions.split(","))
|
|
33
34
|
end
|
|
34
|
-
opts.on("-s", "--source SOURCE", "Install Sensu plugins from a custom SOURCE") do |source|
|
|
35
|
+
opts.on("-s", "--source SOURCE", "Install Sensu plugins and extensions from a custom SOURCE") do |source|
|
|
35
36
|
options[:source] = source
|
|
36
37
|
end
|
|
38
|
+
opts.on("-c", "--clean", "Clean up (remove) other installed versions of the plugin(s) and/or extension(s)") do
|
|
39
|
+
options[:clean] = true
|
|
40
|
+
end
|
|
37
41
|
end
|
|
38
42
|
optparse.parse!(arguments)
|
|
39
43
|
options
|
|
@@ -78,6 +82,39 @@ module Sensu
|
|
|
78
82
|
end
|
|
79
83
|
end
|
|
80
84
|
|
|
85
|
+
def gem_installed_versions(raw_gem, options={})
|
|
86
|
+
gem_name, gem_version = raw_gem.split(":")
|
|
87
|
+
log "determining installed versions of Sensu gem '#{gem_name}' ..."
|
|
88
|
+
gem_command = "gem list #{gem_name}"
|
|
89
|
+
log gem_command if options[:verbose]
|
|
90
|
+
gem_command_output = `#{gem_command}`
|
|
91
|
+
last_line = gem_command_output.split("\n").last
|
|
92
|
+
if last_line == "false"
|
|
93
|
+
[]
|
|
94
|
+
else
|
|
95
|
+
/\((.*)\)/.match(last_line)[1].split(", ")
|
|
96
|
+
end
|
|
97
|
+
end
|
|
98
|
+
|
|
99
|
+
def clean_gem(raw_gem, options={})
|
|
100
|
+
log "cleaning Sensu gem '#{raw_gem}'"
|
|
101
|
+
gem_name, gem_version = raw_gem.split(":")
|
|
102
|
+
gem_command = "gem clean #{gem_name}"
|
|
103
|
+
if gem_version
|
|
104
|
+
if gem_installed_versions(raw_gem, options) == [gem_version]
|
|
105
|
+
log "Sensu gem '#{gem_name}' version '#{gem_version}' is the only version installed"
|
|
106
|
+
else
|
|
107
|
+
gem_command = "gem uninstall #{gem_name} --version '!= #{gem_version}' -a"
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
log gem_command if options[:verbose]
|
|
111
|
+
if system(gem_command)
|
|
112
|
+
log "successfully cleaned Sensu gem '#{gem_name}'"
|
|
113
|
+
else
|
|
114
|
+
log "failed to clean Sensu gem '#{gem_name}'"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
81
118
|
def install_plugins(plugins, options={})
|
|
82
119
|
log "installing Sensu plugins ..."
|
|
83
120
|
log "provided Sensu plugins: #{plugins}" if options[:verbose]
|
|
@@ -89,14 +126,20 @@ module Sensu
|
|
|
89
126
|
end
|
|
90
127
|
end
|
|
91
128
|
log "compiled Sensu plugin gems: #{plugin_gems}" if options[:verbose]
|
|
92
|
-
plugin_gems.reject
|
|
129
|
+
to_be_installed = plugin_gems.reject do |raw_gem|
|
|
93
130
|
gem_installed?(raw_gem, options)
|
|
94
131
|
end
|
|
95
|
-
log "Sensu plugin gems to be installed: #{
|
|
96
|
-
|
|
132
|
+
log "Sensu plugin gems to be installed: #{to_be_installed}"
|
|
133
|
+
to_be_installed.each do |raw_gem|
|
|
97
134
|
install_gem(raw_gem, options)
|
|
98
135
|
end
|
|
99
|
-
log "successfully installed Sensu plugins: #{
|
|
136
|
+
log "successfully installed Sensu plugins: #{to_be_installed}"
|
|
137
|
+
if options[:clean]
|
|
138
|
+
log "cleaning Sensu plugin gems: #{plugin_gems}" if options[:verbose]
|
|
139
|
+
plugin_gems.each do |raw_gem|
|
|
140
|
+
clean_gem(raw_gem, options)
|
|
141
|
+
end
|
|
142
|
+
end
|
|
100
143
|
end
|
|
101
144
|
|
|
102
145
|
def install_extensions(extensions, options={})
|
|
@@ -110,14 +153,20 @@ module Sensu
|
|
|
110
153
|
end
|
|
111
154
|
end
|
|
112
155
|
log "compiled Sensu extension gems: #{extension_gems}" if options[:verbose]
|
|
113
|
-
extension_gems.reject
|
|
156
|
+
to_be_installed = extension_gems.reject do |raw_gem|
|
|
114
157
|
gem_installed?(raw_gem, options)
|
|
115
158
|
end
|
|
116
|
-
log "Sensu extension gems to be installed: #{
|
|
117
|
-
|
|
159
|
+
log "Sensu extension gems to be installed: #{to_be_installed}"
|
|
160
|
+
to_be_installed.each do |raw_gem|
|
|
118
161
|
install_gem(raw_gem, options)
|
|
119
162
|
end
|
|
120
|
-
log "successfully installed Sensu extensions: #{
|
|
163
|
+
log "successfully installed Sensu extensions: #{to_be_installed}"
|
|
164
|
+
if options[:clean]
|
|
165
|
+
log "cleaning Sensu extension gems: #{extension_gems}" if options[:verbose]
|
|
166
|
+
extension_gems.each do |raw_gem|
|
|
167
|
+
clean_gem(raw_gem, options)
|
|
168
|
+
end
|
|
169
|
+
end
|
|
121
170
|
end
|
|
122
171
|
|
|
123
172
|
def run
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
require "base64"
|
|
2
|
+
require "em-http-server"
|
|
3
|
+
require "sensu/json"
|
|
4
|
+
require "sensu/utilities"
|
|
5
|
+
require "sensu/api/utilities/transport_info"
|
|
6
|
+
require "sensu/client/utils"
|
|
7
|
+
|
|
8
|
+
module Sensu
|
|
9
|
+
module Client
|
|
10
|
+
# EventMachine connection handler for the Sensu HTTP client's socket.
|
|
11
|
+
#
|
|
12
|
+
# The Sensu client listens on localhost, port 3031 (by default), for
|
|
13
|
+
# TCP HTTP connections. This allows software running on the host to
|
|
14
|
+
# push check results (that may contain metrics) into Sensu, without
|
|
15
|
+
# needing to know anything about Sensu's internal implementation.
|
|
16
|
+
#
|
|
17
|
+
# All requests and responses expect a json-encoded body (if a body
|
|
18
|
+
# is expected at all).
|
|
19
|
+
#
|
|
20
|
+
# This socket requires receiving a proper HTTP request to any of
|
|
21
|
+
# the following endpoints:
|
|
22
|
+
#
|
|
23
|
+
# GET /info
|
|
24
|
+
# This endpoint returns 200 OK with some basic Sensu info
|
|
25
|
+
#
|
|
26
|
+
# POST /results
|
|
27
|
+
# This endpoint expects application/json body with a check result
|
|
28
|
+
#
|
|
29
|
+
# GET /settings
|
|
30
|
+
# This endpoint responds with 200 OK and the Sensu configuration
|
|
31
|
+
#
|
|
32
|
+
# GET /brew
|
|
33
|
+
# This endpoint gets you some fresh coffee
|
|
34
|
+
class HTTPSocket < EM::HttpServer::Server
|
|
35
|
+
include Sensu::API::Utilities::TransportInfo
|
|
36
|
+
include Utilities
|
|
37
|
+
include CheckUtils
|
|
38
|
+
|
|
39
|
+
attr_accessor :logger, :settings, :transport
|
|
40
|
+
|
|
41
|
+
def initialize
|
|
42
|
+
super
|
|
43
|
+
@endpoints = {
|
|
44
|
+
"/info" => {
|
|
45
|
+
"methods" => {
|
|
46
|
+
"GET" => method(:process_request_info)
|
|
47
|
+
},
|
|
48
|
+
"help" => "Sensu client information"
|
|
49
|
+
},
|
|
50
|
+
"/results" => {
|
|
51
|
+
"methods" => {
|
|
52
|
+
"POST" => method(:process_request_results)
|
|
53
|
+
},
|
|
54
|
+
"help" => "Send check JSON results here"
|
|
55
|
+
},
|
|
56
|
+
"/settings" => {
|
|
57
|
+
"methods" => {
|
|
58
|
+
"GET" => method(:process_request_settings)
|
|
59
|
+
},
|
|
60
|
+
"help" => "Get redacted Sensu settings (requires basic auth). Use ?redacted=false if you want the setting unredacted."
|
|
61
|
+
},
|
|
62
|
+
"/brew" => {
|
|
63
|
+
"methods" => {
|
|
64
|
+
"GET" => Proc.new { |response|
|
|
65
|
+
send_response(418, "I'm a teapot", {
|
|
66
|
+
:response => "I'm a teapot!"
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"help" => "Ask Sensu to brew a cup of joe (try it!)"
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
@response = nil
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
def authorized?
|
|
77
|
+
http_options = @settings[:client][:http_socket] || Hash.new
|
|
78
|
+
if http_options[:user] and http_options[:password]
|
|
79
|
+
if @http[:authorization]
|
|
80
|
+
scheme, base64 = @http[:authorization].split("\s")
|
|
81
|
+
if scheme == "Basic"
|
|
82
|
+
user, password = Base64.decode64(base64).split(":")
|
|
83
|
+
return (user == http_options[:user] && password == http_options[:password])
|
|
84
|
+
end
|
|
85
|
+
end
|
|
86
|
+
end
|
|
87
|
+
false
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
def send_response(status, status_string, content)
|
|
91
|
+
@logger.debug("sending HTTP response #{status} #{status_string}", :content => content)
|
|
92
|
+
@response.status = status
|
|
93
|
+
@response.status_string = status_string
|
|
94
|
+
@response.content = Sensu::JSON::dump(content)
|
|
95
|
+
@response.send_response
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
def process_request_info
|
|
99
|
+
transport_info do |info|
|
|
100
|
+
send_response(200, "OK", {
|
|
101
|
+
:sensu => {
|
|
102
|
+
:version => VERSION
|
|
103
|
+
},
|
|
104
|
+
:transport => info
|
|
105
|
+
})
|
|
106
|
+
end
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def process_request_results
|
|
110
|
+
if @http[:content_type] and @http[:content_type] == "application/json" and @http_content
|
|
111
|
+
begin
|
|
112
|
+
check = Sensu::JSON::load(@http_content)
|
|
113
|
+
process_check_result(check)
|
|
114
|
+
send_response(200, "OK", {:response => "ok"})
|
|
115
|
+
rescue Sensu::JSON::ParseError, ArgumentError
|
|
116
|
+
send_response(400, "Failed to parse JSON body", {:response => "Failed to parse JSON body"})
|
|
117
|
+
end
|
|
118
|
+
else
|
|
119
|
+
send_response(415, "Only application/json content type accepted", {:response => "Invalid content type"})
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
|
|
123
|
+
def process_request_settings
|
|
124
|
+
if authorized?
|
|
125
|
+
@logger.info("responding to HTTP request for configuration settings")
|
|
126
|
+
if @http_query_string and @http_query_string.downcase.include?("redacted=false")
|
|
127
|
+
send_response(200, "OK", @settings.to_hash)
|
|
128
|
+
else
|
|
129
|
+
send_response(200, "OK", redact_sensitive(@settings.to_hash))
|
|
130
|
+
end
|
|
131
|
+
else
|
|
132
|
+
@logger.warn("refusing to serve unauthorized settings request")
|
|
133
|
+
@response.headers["WWW-Authenticate"] = 'Basic realm="Sensu Client Restricted Area"'
|
|
134
|
+
send_response(401, "Unauthorized", {
|
|
135
|
+
:response => "You must be authenticated using your http_options user and password settings"
|
|
136
|
+
})
|
|
137
|
+
end
|
|
138
|
+
end
|
|
139
|
+
|
|
140
|
+
def http_request_errback(ex)
|
|
141
|
+
@logger.error("exception while processing HTTP request: #{ex.class}: #{ex.message}", backtrace: ex.backtrace)
|
|
142
|
+
@response = EM::DelegatedHttpResponse.new(self)
|
|
143
|
+
@response.content_type "application/json"
|
|
144
|
+
send_response(500, "Internal Server Error", {
|
|
145
|
+
"response" => "Internal Server Error: Check your Sensu logs for error details"
|
|
146
|
+
})
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
# This method is called to process HTTP requests
|
|
150
|
+
def process_http_request
|
|
151
|
+
@logger.debug("processing #{@http_request_method} #{@http_request_uri}")
|
|
152
|
+
@response = EM::DelegatedHttpResponse.new(self)
|
|
153
|
+
@response.content_type "application/json"
|
|
154
|
+
endpoint = @endpoints[@http_request_uri]
|
|
155
|
+
if endpoint
|
|
156
|
+
@logger.debug("endpoint #{@http_request_uri} found", :accepted_methods => endpoint["methods"].keys)
|
|
157
|
+
method_name = @http_request_method.upcase
|
|
158
|
+
method_handler = endpoint["methods"][method_name]
|
|
159
|
+
if method_handler
|
|
160
|
+
@logger.debug("executing #{method_name} #{@http_request_uri} handler")
|
|
161
|
+
method_handler.call
|
|
162
|
+
else
|
|
163
|
+
@logger.debug("method #{method_name} is not allowed for endpoint #{@http_request_uri}")
|
|
164
|
+
send_response(405, "Method Not Allowed", {
|
|
165
|
+
:response => "Valid methods for this endpoint: #{reqdef['methods'].keys}"
|
|
166
|
+
})
|
|
167
|
+
end
|
|
168
|
+
else
|
|
169
|
+
@logger.warn("unknown endpoint requested: #{@http_request_uri}")
|
|
170
|
+
help_response = {
|
|
171
|
+
:endpoints => {}
|
|
172
|
+
}
|
|
173
|
+
@endpoints.each do |key, value|
|
|
174
|
+
help_response[:endpoints][key] ||= Hash.new
|
|
175
|
+
help_response[:endpoints][key]["help"] = value["help"]
|
|
176
|
+
help_response[:endpoints][key]["methods"] = value["methods"].keys
|
|
177
|
+
end
|
|
178
|
+
send_response(404, "Not Found", help_response)
|
|
179
|
+
end
|
|
180
|
+
end
|
|
181
|
+
end
|
|
182
|
+
end
|
|
183
|
+
end
|
data/lib/sensu/client/process.rb
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
require "sensu/daemon"
|
|
2
2
|
require "sensu/client/socket"
|
|
3
|
+
require "sensu/client/http_socket"
|
|
3
4
|
|
|
4
5
|
module Sensu
|
|
5
6
|
module Client
|
|
@@ -372,6 +373,16 @@ module Sensu
|
|
|
372
373
|
socket.transport = @transport
|
|
373
374
|
socket.protocol = :udp
|
|
374
375
|
end
|
|
376
|
+
# Setup the HTTP socket
|
|
377
|
+
http_options = @settings[:client][:http_socket] || Hash.new
|
|
378
|
+
http_options[:bind] ||= "127.0.0.1"
|
|
379
|
+
http_options[:port] ||= 3031
|
|
380
|
+
@logger.debug("binding client http socket", :http_options => http_options)
|
|
381
|
+
@sockets << EM::start_server(http_options[:bind], http_options[:port], HTTPSocket) do |socket|
|
|
382
|
+
socket.logger = @logger
|
|
383
|
+
socket.settings = @settings
|
|
384
|
+
socket.transport = @transport
|
|
385
|
+
end
|
|
375
386
|
end
|
|
376
387
|
|
|
377
388
|
# Call a callback (Ruby block) when there are no longer check
|
|
@@ -424,7 +435,7 @@ module Sensu
|
|
|
424
435
|
# connection object indicates a socket connection that needs to
|
|
425
436
|
# be closed, eg. a UDP datagram socket.
|
|
426
437
|
def close_sockets
|
|
427
|
-
@logger.info("closing client
|
|
438
|
+
@logger.info("closing client sockets")
|
|
428
439
|
@sockets.each do |socket|
|
|
429
440
|
if socket.is_a?(Numeric)
|
|
430
441
|
EM.stop_server(socket)
|
data/lib/sensu/client/socket.rb
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
require "sensu/json"
|
|
2
|
+
require "sensu/client/utils"
|
|
2
3
|
|
|
3
4
|
module Sensu
|
|
4
5
|
module Client
|
|
@@ -47,7 +48,7 @@ module Sensu
|
|
|
47
48
|
# of data was received, the agent will give up on the sender, and
|
|
48
49
|
# instead respond +"invalid"+ and close the connection.
|
|
49
50
|
class Socket < EM::Connection
|
|
50
|
-
|
|
51
|
+
include CheckUtils
|
|
51
52
|
|
|
52
53
|
attr_accessor :logger, :settings, :transport, :protocol
|
|
53
54
|
|
|
@@ -115,64 +116,6 @@ module Sensu
|
|
|
115
116
|
end
|
|
116
117
|
end
|
|
117
118
|
|
|
118
|
-
# Validate check result attributes.
|
|
119
|
-
#
|
|
120
|
-
# @param [Hash] check result to validate.
|
|
121
|
-
def validate_check_result(check)
|
|
122
|
-
unless check[:name] =~ /\A[\w\.-]+\z/
|
|
123
|
-
raise DataError, "check name must be a string and cannot contain spaces or special characters"
|
|
124
|
-
end
|
|
125
|
-
unless check[:source].nil? || check[:source] =~ /\A[\w\.-]+\z/
|
|
126
|
-
raise DataError, "check source must be a string and cannot contain spaces or special characters"
|
|
127
|
-
end
|
|
128
|
-
unless check[:output].is_a?(String)
|
|
129
|
-
raise DataError, "check output must be a string"
|
|
130
|
-
end
|
|
131
|
-
unless check[:status].is_a?(Integer)
|
|
132
|
-
raise DataError, "check status must be an integer"
|
|
133
|
-
end
|
|
134
|
-
unless check[:executed].is_a?(Integer)
|
|
135
|
-
raise DataError, "check executed timestamp must be an integer"
|
|
136
|
-
end
|
|
137
|
-
unless check[:ttl].nil? || (check[:ttl].is_a?(Integer) && check[:ttl] > 0)
|
|
138
|
-
raise DataError, "check ttl must be an integer greater than 0"
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
# Publish a check result to the Sensu transport.
|
|
143
|
-
#
|
|
144
|
-
# @param [Hash] check result.
|
|
145
|
-
def publish_check_result(check)
|
|
146
|
-
payload = {
|
|
147
|
-
:client => @settings[:client][:name],
|
|
148
|
-
:check => check.merge(:issued => Time.now.to_i)
|
|
149
|
-
}
|
|
150
|
-
payload[:signature] = @settings[:client][:signature] if @settings[:client][:signature]
|
|
151
|
-
@logger.info("publishing check result", :payload => payload)
|
|
152
|
-
@transport.publish(:direct, "results", Sensu::JSON.dump(payload)) do |info|
|
|
153
|
-
if info[:error]
|
|
154
|
-
@logger.error("failed to publish check result", {
|
|
155
|
-
:payload => payload,
|
|
156
|
-
:error => info[:error].to_s
|
|
157
|
-
})
|
|
158
|
-
end
|
|
159
|
-
end
|
|
160
|
-
end
|
|
161
|
-
|
|
162
|
-
# Process a check result. Set check result attribute defaults,
|
|
163
|
-
# validate the attributes, publish the check result to the Sensu
|
|
164
|
-
# transport, and respond to the sender with the message +"ok"+.
|
|
165
|
-
#
|
|
166
|
-
# @param [Hash] check result to be validated and published.
|
|
167
|
-
# @raise [DataError] if +check+ is invalid.
|
|
168
|
-
def process_check_result(check)
|
|
169
|
-
check[:status] ||= 0
|
|
170
|
-
check[:executed] ||= Time.now.to_i
|
|
171
|
-
validate_check_result(check)
|
|
172
|
-
publish_check_result(check)
|
|
173
|
-
respond("ok")
|
|
174
|
-
end
|
|
175
|
-
|
|
176
119
|
# Parse a JSON check result. For UDP, immediately raise a parser
|
|
177
120
|
# error. For TCP, record parser errors, so the connection
|
|
178
121
|
# +watchdog+ can report them.
|
|
@@ -183,6 +126,7 @@ module Sensu
|
|
|
183
126
|
check = Sensu::JSON.load(data)
|
|
184
127
|
cancel_watchdog
|
|
185
128
|
process_check_result(check)
|
|
129
|
+
respond("ok")
|
|
186
130
|
rescue Sensu::JSON::ParseError, ArgumentError => error
|
|
187
131
|
if @protocol == :tcp
|
|
188
132
|
@parse_error = error.to_s
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
require "sensu/json"
|
|
2
|
+
|
|
3
|
+
module Sensu
|
|
4
|
+
module Client
|
|
5
|
+
module CheckUtils
|
|
6
|
+
class DataError < StandardError; end
|
|
7
|
+
# Validate check result attributes.
|
|
8
|
+
#
|
|
9
|
+
# @param [Hash] check result to validate.
|
|
10
|
+
def validate_check_result(check)
|
|
11
|
+
unless check[:name] =~ /\A[\w\.-]+\z/
|
|
12
|
+
raise DataError, "check name must be a string and cannot contain spaces or special characters"
|
|
13
|
+
end
|
|
14
|
+
unless check[:source].nil? || check[:source] =~ /\A[\w\.-]+\z/
|
|
15
|
+
raise DataError, "check source must be a string and cannot contain spaces or special characters"
|
|
16
|
+
end
|
|
17
|
+
unless check[:output].is_a?(String)
|
|
18
|
+
raise DataError, "check output must be a string"
|
|
19
|
+
end
|
|
20
|
+
unless check[:status].is_a?(Integer)
|
|
21
|
+
raise DataError, "check status must be an integer"
|
|
22
|
+
end
|
|
23
|
+
unless check[:executed].is_a?(Integer)
|
|
24
|
+
raise DataError, "check executed timestamp must be an integer"
|
|
25
|
+
end
|
|
26
|
+
unless check[:ttl].nil? || (check[:ttl].is_a?(Integer) && check[:ttl] > 0)
|
|
27
|
+
raise DataError, "check ttl must be an integer greater than 0"
|
|
28
|
+
end
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Process a check result. Set check result attribute defaults,
|
|
32
|
+
# validate the attributes, publish the check result to the Sensu
|
|
33
|
+
# transport, and respond to the sender with the message +"ok"+.
|
|
34
|
+
#
|
|
35
|
+
# @param [Hash] check result to be validated and published.
|
|
36
|
+
# @raise [DataError] if +check+ is invalid.
|
|
37
|
+
def process_check_result(check)
|
|
38
|
+
check[:status] ||= 0
|
|
39
|
+
check[:executed] ||= Time.now.to_i
|
|
40
|
+
validate_check_result(check)
|
|
41
|
+
publish_check_result(check)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Publish a check result to the Sensu transport.
|
|
45
|
+
#
|
|
46
|
+
# @param [Hash] check result.
|
|
47
|
+
def publish_check_result(check)
|
|
48
|
+
payload = {
|
|
49
|
+
:client => @settings[:client][:name],
|
|
50
|
+
:check => check.merge(:issued => Time.now.to_i)
|
|
51
|
+
}
|
|
52
|
+
payload[:signature] = @settings[:client][:signature] if @settings[:client][:signature]
|
|
53
|
+
@logger.info("publishing check result", :payload => payload)
|
|
54
|
+
@transport.publish(:direct, "results", Sensu::JSON.dump(payload)) do |info|
|
|
55
|
+
if info[:error]
|
|
56
|
+
@logger.error("failed to publish check result", {
|
|
57
|
+
:payload => payload,
|
|
58
|
+
:error => info[:error].to_s
|
|
59
|
+
})
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
end
|
|
63
|
+
end
|
|
64
|
+
end
|
|
65
|
+
end
|
data/lib/sensu/constants.rb
CHANGED
data/lib/sensu/daemon.rb
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
require "rubygems"
|
|
2
2
|
|
|
3
|
-
gem "eventmachine", "1.2.
|
|
3
|
+
gem "eventmachine", "1.2.1"
|
|
4
4
|
|
|
5
5
|
gem "sensu-json", "2.0.1"
|
|
6
6
|
gem "sensu-logger", "1.2.1"
|
|
@@ -9,7 +9,7 @@ gem "sensu-extension", "1.5.1"
|
|
|
9
9
|
gem "sensu-extensions", "1.7.1"
|
|
10
10
|
gem "sensu-transport", "7.0.2"
|
|
11
11
|
gem "sensu-spawn", "2.2.1"
|
|
12
|
-
gem "sensu-redis", "2.
|
|
12
|
+
gem "sensu-redis", "2.1.0"
|
|
13
13
|
|
|
14
14
|
require "time"
|
|
15
15
|
require "uri"
|
data/sensu.gemspec
CHANGED
|
@@ -12,7 +12,7 @@ Gem::Specification.new do |s|
|
|
|
12
12
|
s.license = "MIT"
|
|
13
13
|
s.has_rdoc = false
|
|
14
14
|
|
|
15
|
-
s.add_dependency "eventmachine", "1.2.
|
|
15
|
+
s.add_dependency "eventmachine", "1.2.1"
|
|
16
16
|
s.add_dependency "sensu-json", "2.0.1"
|
|
17
17
|
s.add_dependency "sensu-logger", "1.2.1"
|
|
18
18
|
s.add_dependency "sensu-settings", "9.2.2"
|
|
@@ -20,7 +20,7 @@ Gem::Specification.new do |s|
|
|
|
20
20
|
s.add_dependency "sensu-extensions", "1.7.1"
|
|
21
21
|
s.add_dependency "sensu-transport", "7.0.2"
|
|
22
22
|
s.add_dependency "sensu-spawn", "2.2.1"
|
|
23
|
-
s.add_dependency "sensu-redis", "2.
|
|
23
|
+
s.add_dependency "sensu-redis", "2.1.0"
|
|
24
24
|
s.add_dependency "em-http-server", "0.1.8"
|
|
25
25
|
|
|
26
26
|
s.add_development_dependency "rake", "10.5.0"
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: sensu
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.27.0.alpha
|
|
4
|
+
version: 0.27.0.alpha.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Sean Porter
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: exe
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date: 2016-11-
|
|
12
|
+
date: 2016-11-18 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: eventmachine
|
|
@@ -17,14 +17,14 @@ dependencies:
|
|
|
17
17
|
requirements:
|
|
18
18
|
- - '='
|
|
19
19
|
- !ruby/object:Gem::Version
|
|
20
|
-
version: 1.2.
|
|
20
|
+
version: 1.2.1
|
|
21
21
|
type: :runtime
|
|
22
22
|
prerelease: false
|
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
|
24
24
|
requirements:
|
|
25
25
|
- - '='
|
|
26
26
|
- !ruby/object:Gem::Version
|
|
27
|
-
version: 1.2.
|
|
27
|
+
version: 1.2.1
|
|
28
28
|
- !ruby/object:Gem::Dependency
|
|
29
29
|
name: sensu-json
|
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -129,14 +129,14 @@ dependencies:
|
|
|
129
129
|
requirements:
|
|
130
130
|
- - '='
|
|
131
131
|
- !ruby/object:Gem::Version
|
|
132
|
-
version: 2.
|
|
132
|
+
version: 2.1.0
|
|
133
133
|
type: :runtime
|
|
134
134
|
prerelease: false
|
|
135
135
|
version_requirements: !ruby/object:Gem::Requirement
|
|
136
136
|
requirements:
|
|
137
137
|
- - '='
|
|
138
138
|
- !ruby/object:Gem::Version
|
|
139
|
-
version: 2.
|
|
139
|
+
version: 2.1.0
|
|
140
140
|
- !ruby/object:Gem::Dependency
|
|
141
141
|
name: em-http-server
|
|
142
142
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -248,8 +248,10 @@ files:
|
|
|
248
248
|
- lib/sensu/api/validators/client.rb
|
|
249
249
|
- lib/sensu/api/validators/invalid.rb
|
|
250
250
|
- lib/sensu/cli.rb
|
|
251
|
+
- lib/sensu/client/http_socket.rb
|
|
251
252
|
- lib/sensu/client/process.rb
|
|
252
253
|
- lib/sensu/client/socket.rb
|
|
254
|
+
- lib/sensu/client/utils.rb
|
|
253
255
|
- lib/sensu/constants.rb
|
|
254
256
|
- lib/sensu/daemon.rb
|
|
255
257
|
- lib/sensu/server/filter.rb
|
|
@@ -280,7 +282,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
280
282
|
version: 1.3.1
|
|
281
283
|
requirements: []
|
|
282
284
|
rubyforge_project:
|
|
283
|
-
rubygems_version: 2.6.
|
|
285
|
+
rubygems_version: 2.6.6
|
|
284
286
|
signing_key:
|
|
285
287
|
specification_version: 4
|
|
286
288
|
summary: A monitoring framework
|