Class: Bosh::Monitor::Plugins::Nats
- Inherits:
-
Base
- Object
- Base
- Bosh::Monitor::Plugins::Nats
show all
- Defined in:
- lib/bosh/monitor/plugins/nats.rb
Constant Summary
collapse
- SUBJECT =
"bosh.hm.events"
Instance Attribute Summary
Attributes inherited from Base
#event_kinds, #logger, #options
Instance Method Summary
collapse
Methods inherited from Base
#initialize
Instance Method Details
#process(event) ⇒ Object
31
32
33
34
35
36
37
38
39
40
41
42
|
# File 'lib/bosh/monitor/plugins/nats.rb', line 31
def process(event)
if @nats.nil?
@logger.error("Cannot deliver event, NATS not initialized")
return false
end
nats_subject = options["subject"] || SUBJECT
EM.schedule do
@nats.publish(nats_subject, event.to_json)
end
true
end
|
#run ⇒ Object
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/bosh/monitor/plugins/nats.rb', line 13
def run
unless EM.reactor_running?
logger.error("NATS delivery agent can only be started when event loop is running")
return false
end
nats_client_options = {
:uri => options["endpoint"],
:user => options["user"],
:pass => options["password"],
:autostart => false
}
@nats = NATS.connect(nats_client_options) do
logger.info("Ready to publish alerts to NATS at '#{options["endpoint"]}'")
end
end
|
#validate_options ⇒ Object
6
7
8
9
10
11
|
# File 'lib/bosh/monitor/plugins/nats.rb', line 6
def validate_options
options.kind_of?(Hash) &&
options["endpoint"] &&
options.has_key?("user") &&
options.has_key?("password")
end
|