sensu 0.23.3 → 0.24.0.beta
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/CHANGELOG.md +58 -0
- data/lib/sensu/api/process.rb +184 -90
- data/lib/sensu/api/validators.rb +37 -0
- data/lib/sensu/cli.rb +3 -0
- data/lib/sensu/client/process.rb +34 -6
- data/lib/sensu/constants.rb +1 -1
- data/lib/sensu/daemon.rb +67 -30
- data/lib/sensu/server/filter.rb +2 -2
- data/lib/sensu/server/handle.rb +12 -12
- data/lib/sensu/server/mutate.rb +4 -4
- data/lib/sensu/server/process.rb +218 -213
- data/sensu.gemspec +5 -5
- metadata +15 -14
data/lib/sensu/daemon.rb
CHANGED
@@ -2,14 +2,14 @@ require "rubygems"
|
|
2
2
|
|
3
3
|
gem "eventmachine", "1.2.0.1"
|
4
4
|
|
5
|
-
gem "sensu-json", "
|
5
|
+
gem "sensu-json", "2.0.0"
|
6
6
|
gem "sensu-logger", "1.2.0"
|
7
|
-
gem "sensu-settings", "
|
7
|
+
gem "sensu-settings", "5.1.0"
|
8
8
|
gem "sensu-extension", "1.5.0"
|
9
9
|
gem "sensu-extensions", "1.5.0"
|
10
|
-
gem "sensu-transport", "
|
10
|
+
gem "sensu-transport", "6.0.0"
|
11
11
|
gem "sensu-spawn", "2.2.0"
|
12
|
-
gem "sensu-redis", "1.
|
12
|
+
gem "sensu-redis", "1.4.0"
|
13
13
|
|
14
14
|
require "time"
|
15
15
|
require "uri"
|
@@ -49,6 +49,7 @@ module Sensu
|
|
49
49
|
setup_logger(options)
|
50
50
|
load_settings(options)
|
51
51
|
load_extensions(options)
|
52
|
+
setup_spawn
|
52
53
|
setup_process(options)
|
53
54
|
end
|
54
55
|
|
@@ -64,56 +65,78 @@ module Sensu
|
|
64
65
|
@logger.setup_signal_traps
|
65
66
|
end
|
66
67
|
|
67
|
-
# Log setting or extension loading
|
68
|
+
# Log setting or extension loading notices, sensitive information
|
68
69
|
# is redacted.
|
69
70
|
#
|
70
|
-
# @param
|
71
|
-
# @param level [Symbol] to log the
|
72
|
-
def
|
73
|
-
|
71
|
+
# @param notices [Array] to be logged.
|
72
|
+
# @param level [Symbol] to log the notices at.
|
73
|
+
def log_notices(notices=[], level=:warn)
|
74
|
+
notices.each do |concern|
|
74
75
|
message = concern.delete(:message)
|
75
76
|
@logger.send(level, message, redact_sensitive(concern))
|
76
77
|
end
|
77
78
|
end
|
78
79
|
|
79
|
-
#
|
80
|
-
#
|
81
|
-
#
|
82
|
-
#
|
83
|
-
#
|
80
|
+
# Determine if the Sensu settings are valid, if there are load or
|
81
|
+
# validation errors, and immediately exit the process with the
|
82
|
+
# appropriate exit status code. This method is used to determine
|
83
|
+
# if the latest configuration changes are valid prior to
|
84
|
+
# restarting the Sensu service, triggered by a CLI argument, e.g.
|
85
|
+
# `--validate_config`.
|
84
86
|
#
|
85
87
|
# @param settings [Object]
|
86
|
-
def
|
88
|
+
def validate_settings!(settings)
|
89
|
+
if settings.errors.empty?
|
90
|
+
puts "configuration is valid"
|
91
|
+
exit
|
92
|
+
else
|
93
|
+
puts "configuration is invalid"
|
94
|
+
puts Sensu::JSON.dump({:errors => @settings.errors}, :pretty => true)
|
95
|
+
exit 2
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Print the Sensu settings (JSON) to STDOUT and immediately exit
|
100
|
+
# the process with the appropriate exit status code. This method
|
101
|
+
# is used while troubleshooting configuration issues, triggered by
|
102
|
+
# a CLI argument, e.g. `--print_config`. Sensu settings with
|
103
|
+
# sensitive values (e.g. passwords) are first redacted.
|
104
|
+
#
|
105
|
+
# @param settings [Object]
|
106
|
+
def print_settings!(settings)
|
87
107
|
redacted_settings = redact_sensitive(settings.to_hash)
|
88
108
|
@logger.warn("outputting compiled configuration and exiting")
|
89
109
|
puts Sensu::JSON.dump(redacted_settings, :pretty => true)
|
90
|
-
exit
|
110
|
+
exit(settings.errors.empty? ? 0 : 2)
|
91
111
|
end
|
92
112
|
|
93
|
-
# Load Sensu settings
|
94
|
-
#
|
95
|
-
#
|
96
|
-
#
|
97
|
-
#
|
98
|
-
#
|
113
|
+
# Load Sensu settings. This method creates the settings instance
|
114
|
+
# variable: `@settings`. If the `validate_config` option is true,
|
115
|
+
# this method calls `validate_settings!()` to validate the latest
|
116
|
+
# compiled configuration settings and will then exit the process.
|
117
|
+
# If the `print_config` option is true, this method calls
|
118
|
+
# `print_settings!()` to output the compiled configuration
|
119
|
+
# settings and will then exit the process. If there are loading or
|
120
|
+
# validation errors, they will be logged (notices), and this
|
121
|
+
# method will exit(2) the process.
|
122
|
+
#
|
99
123
|
#
|
100
124
|
# https://github.com/sensu/sensu-settings
|
101
125
|
#
|
102
126
|
# @param options [Hash]
|
103
127
|
def load_settings(options={})
|
104
128
|
@settings = Settings.get(options)
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
129
|
+
validate_settings!(@settings) if options[:validate_config]
|
130
|
+
log_notices(@settings.warnings)
|
131
|
+
log_notices(@settings.errors, :fatal)
|
132
|
+
print_settings!(@settings) if options[:print_config]
|
133
|
+
unless @settings.errors.empty?
|
110
134
|
@logger.fatal("SENSU NOT RUNNING!")
|
111
135
|
exit 2
|
112
136
|
end
|
113
|
-
print_settings(@settings) if options[:print_config]
|
114
137
|
end
|
115
138
|
|
116
|
-
# Load Sensu extensions and log any
|
139
|
+
# Load Sensu extensions and log any notices. Set the logger and
|
117
140
|
# settings for each extension instance. This method creates the
|
118
141
|
# extensions instance variable: `@extensions`.
|
119
142
|
#
|
@@ -123,7 +146,7 @@ module Sensu
|
|
123
146
|
# @param options [Hash]
|
124
147
|
def load_extensions(options={})
|
125
148
|
@extensions = Extensions.get(options)
|
126
|
-
|
149
|
+
log_notices(@extensions.warnings)
|
127
150
|
extension_settings = @settings.to_hash.dup
|
128
151
|
@extensions.all.each do |extension|
|
129
152
|
extension.logger = @logger
|
@@ -131,6 +154,20 @@ module Sensu
|
|
131
154
|
end
|
132
155
|
end
|
133
156
|
|
157
|
+
# Set up Sensu spawn, creating a worker to create, control, and
|
158
|
+
# limit spawned child processes. This method adjusts the
|
159
|
+
# EventMachine thread pool size to accommodate the concurrent
|
160
|
+
# process spawn limit and other Sensu process operations.
|
161
|
+
#
|
162
|
+
# https://github.com/sensu/sensu-spawn
|
163
|
+
def setup_spawn
|
164
|
+
@logger.info("configuring sensu spawn", :settings => @settings[:sensu][:spawn])
|
165
|
+
threadpool_size = @settings[:sensu][:spawn][:limit] + 10
|
166
|
+
@logger.debug("setting eventmachine threadpool size", :size => threadpool_size)
|
167
|
+
EM.threadpool_size = threadpool_size
|
168
|
+
Spawn.setup(@settings[:sensu][:spawn])
|
169
|
+
end
|
170
|
+
|
134
171
|
# Manage the current process, optionally daemonize and/or write
|
135
172
|
# the current process ID to a PID file.
|
136
173
|
#
|
data/lib/sensu/server/filter.rb
CHANGED
@@ -345,14 +345,14 @@ module Sensu
|
|
345
345
|
end
|
346
346
|
if filter_message
|
347
347
|
@logger.info(filter_message, details)
|
348
|
-
@
|
348
|
+
@in_progress[:events] -= 1 if @in_progress
|
349
349
|
else
|
350
350
|
event_filtered?(handler, event) do |filtered|
|
351
351
|
unless filtered
|
352
352
|
yield(event)
|
353
353
|
else
|
354
354
|
@logger.info("event was filtered", details)
|
355
|
-
@
|
355
|
+
@in_progress[:events] -= 1 if @in_progress
|
356
356
|
end
|
357
357
|
end
|
358
358
|
end
|
data/lib/sensu/server/handle.rb
CHANGED
@@ -4,7 +4,7 @@ module Sensu
|
|
4
4
|
module Server
|
5
5
|
module Handle
|
6
6
|
# Create a handler error callback, for logging the error and
|
7
|
-
# decrementing the `@
|
7
|
+
# decrementing the `@in_progress[:events]` by `1`.
|
8
8
|
#
|
9
9
|
# @param handler [Object]
|
10
10
|
# @param event_data [Object]
|
@@ -16,14 +16,14 @@ module Sensu
|
|
16
16
|
:event_data => event_data,
|
17
17
|
:error => error.to_s
|
18
18
|
})
|
19
|
-
@
|
19
|
+
@in_progress[:events] -= 1 if @in_progress
|
20
20
|
end
|
21
21
|
end
|
22
22
|
|
23
23
|
# Execute a pipe event handler, using the defined handler
|
24
24
|
# command to spawn a process, passing it event data via STDIN.
|
25
25
|
# Log the handler output lines and decrement the
|
26
|
-
# `@
|
26
|
+
# `@in_progress[:events]` by `1` when the handler executes
|
27
27
|
# successfully.
|
28
28
|
#
|
29
29
|
# @param handler [Hash] definition.
|
@@ -36,7 +36,7 @@ module Sensu
|
|
36
36
|
:handler => handler,
|
37
37
|
:output => output.split("\n+")
|
38
38
|
})
|
39
|
-
@
|
39
|
+
@in_progress[:events] -= 1 if @in_progress
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
@@ -47,7 +47,7 @@ module Sensu
|
|
47
47
|
# `handler_error()` method is used to create the `on_error`
|
48
48
|
# callback for the connection handler. The `on_error` callback
|
49
49
|
# is call in the event of any error(s). The
|
50
|
-
# `@
|
50
|
+
# `@in_progress[:events]` is decremented by `1` when the data is
|
51
51
|
# transmitted successfully, `on_success`.
|
52
52
|
#
|
53
53
|
# @param handler [Hash] definition.
|
@@ -57,7 +57,7 @@ module Sensu
|
|
57
57
|
begin
|
58
58
|
EM::connect(handler[:socket][:host], handler[:socket][:port], Socket) do |socket|
|
59
59
|
socket.on_success = Proc.new do
|
60
|
-
@
|
60
|
+
@in_progress[:events] -= 1 if @in_progress
|
61
61
|
end
|
62
62
|
socket.on_error = on_error
|
63
63
|
timeout = handler[:timeout] || 10
|
@@ -71,7 +71,7 @@ module Sensu
|
|
71
71
|
end
|
72
72
|
|
73
73
|
# Transmit event data to a UDP socket, then close the
|
74
|
-
# connection. The `@
|
74
|
+
# connection. The `@in_progress[:events]` is decremented by `1`
|
75
75
|
# when the data is assumed to have been transmitted.
|
76
76
|
#
|
77
77
|
# @param handler [Hash] definition.
|
@@ -81,7 +81,7 @@ module Sensu
|
|
81
81
|
EM::open_datagram_socket("0.0.0.0", 0, nil) do |socket|
|
82
82
|
socket.send_datagram(event_data.to_s, handler[:socket][:host], handler[:socket][:port])
|
83
83
|
socket.close_connection_after_writing
|
84
|
-
@
|
84
|
+
@in_progress[:events] -= 1 if @in_progress
|
85
85
|
end
|
86
86
|
rescue => error
|
87
87
|
handler_error(handler, event_data).call(error)
|
@@ -90,7 +90,7 @@ module Sensu
|
|
90
90
|
|
91
91
|
# Publish event data to a Sensu transport pipe. Event data that
|
92
92
|
# is `nil` or empty will not be published, to prevent transport
|
93
|
-
# errors. The `@
|
93
|
+
# errors. The `@in_progress[:events]` is decremented by `1`,
|
94
94
|
# even if the event data is not published.
|
95
95
|
#
|
96
96
|
# @param handler [Hash] definition.
|
@@ -105,14 +105,14 @@ module Sensu
|
|
105
105
|
end
|
106
106
|
end
|
107
107
|
end
|
108
|
-
@
|
108
|
+
@in_progress[:events] -= 1 if @in_progress
|
109
109
|
end
|
110
110
|
|
111
111
|
# Run a handler extension, within the Sensu EventMachine reactor
|
112
112
|
# (event loop). The extension API `safe_run()` method is used to
|
113
113
|
# guard against most errors. The `safe_run()` callback is always
|
114
114
|
# called, logging the extension run output and status, and
|
115
|
-
# decrementing the `@
|
115
|
+
# decrementing the `@in_progress[:events]` by `1`.
|
116
116
|
#
|
117
117
|
# @param handler [Hash] definition.
|
118
118
|
# @param event_data [Object] to pass to the handler extension.
|
@@ -123,7 +123,7 @@ module Sensu
|
|
123
123
|
:output => output,
|
124
124
|
:status => status
|
125
125
|
})
|
126
|
-
@
|
126
|
+
@in_progress[:events] -= 1 if @in_progress
|
127
127
|
end
|
128
128
|
end
|
129
129
|
|
data/lib/sensu/server/mutate.rb
CHANGED
@@ -6,7 +6,7 @@ module Sensu
|
|
6
6
|
# created callback can be used for standard mutators and mutator
|
7
7
|
# extensions. The provided callback will only be called when the
|
8
8
|
# mutator status is `0` (OK). If the status is not `0`, an error
|
9
|
-
# is logged, and the `@
|
9
|
+
# is logged, and the `@in_progress[:events]` is decremented by
|
10
10
|
# `1`.
|
11
11
|
#
|
12
12
|
# @param mutator [Object] definition or extension.
|
@@ -25,7 +25,7 @@ module Sensu
|
|
25
25
|
:output => output,
|
26
26
|
:status => status
|
27
27
|
})
|
28
|
-
@
|
28
|
+
@in_progress[:events] -= 1 if @in_progress
|
29
29
|
end
|
30
30
|
end
|
31
31
|
end
|
@@ -63,7 +63,7 @@ module Sensu
|
|
63
63
|
# mutator is used, unless the handler specifies another mutator.
|
64
64
|
# If a mutator does not exist, not defined or a missing
|
65
65
|
# extension, an error will be logged and the
|
66
|
-
# `@
|
66
|
+
# `@in_progress[:events]` is decremented by `1`. This method
|
67
67
|
# first checks for the existence of a standard mutator, then
|
68
68
|
# checks for an extension if a standard mutator is not defined.
|
69
69
|
#
|
@@ -84,7 +84,7 @@ module Sensu
|
|
84
84
|
@logger.error("unknown mutator", {
|
85
85
|
:mutator_name => mutator_name
|
86
86
|
})
|
87
|
-
@
|
87
|
+
@in_progress[:events] -= 1 if @in_progress
|
88
88
|
end
|
89
89
|
end
|
90
90
|
end
|