Class: RRDNotifier::Server
- Inherits:
-
EM::Connection
- Object
- EM::Connection
- RRDNotifier::Server
- Defined in:
- lib/rrd-grapher/notifier.rb
Class Method Summary collapse
-
.start(opts = {}, &block) ⇒ Object
Start the notifier handler, it will open an UDP socket to which collectd should send its data using the network module.
Instance Method Summary collapse
-
#initialize(alarm_manager, on_init_block = nil, redirect_to = nil) ⇒ Server
constructor
Called by eventmachine when the connection is created.
-
#post_init ⇒ Object
Eventmachine callbacks.
-
#receive_data(data) ⇒ Object
EventMachine callback called when a packet is available.
-
#register_alarm(*args) ⇒ Object
Register a new monitoring alert.
Constructor Details
#initialize(alarm_manager, on_init_block = nil, redirect_to = nil) ⇒ Server
Called by eventmachine when the connection is created.
16 17 18 19 20 |
# File 'lib/rrd-grapher/notifier.rb', line 16 def initialize(alarm_manager, on_init_block = nil, redirect_to = nil) @alarm_manager = alarm_manager @on_init_block = on_init_block @redirect_to = redirect_to ? redirect_to.split(':') : nil end |
Class Method Details
.start(opts = {}, &block) ⇒ Object
Start the notifier handler, it will open an UDP socket to which collectd should send its data using the network module.
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/rrd-grapher/notifier.rb', line 33 def self.start(opts = {}, &block) host = opts.delete(:host) || '127.0.0.1' port = opts.delete(:port) || 10000 redirect_to = opts.delete(:redirect_to) if redirect_to # TODO: make it separate from redirect_to ? opts.merge!(:send_monitoring_to => redirect_to) end alarm_manager = AlarmManager.new(opts) unless opts.empty? raise "Unknown arguments: #{opts}" end EM::open_datagram_socket(host, port, Server, alarm_manager, block, redirect_to) end |
Instance Method Details
#post_init ⇒ Object
Eventmachine callbacks
64 65 66 |
# File 'lib/rrd-grapher/notifier.rb', line 64 def post_init @on_init_block.call(self) if @on_init_block end |
#receive_data(data) ⇒ Object
EventMachine callback called when a packet is available
73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/rrd-grapher/notifier.rb', line 73 def receive_data(data) if packets = RubyParser::parse(data) packets.each do |p| @alarm_manager.packet_received(p) end end if @redirect_to send_datagram(data, @redirect_to[0], @redirect_to[1]) end end |
#register_alarm(*args) ⇒ Object
Register a new monitoring alert.
57 58 59 |
# File 'lib/rrd-grapher/notifier.rb', line 57 def register_alarm(*args) @alarm_manager.register_alarm(*args) end |