Class: Riemann::Client
- Inherits:
-
Object
- Object
- Riemann::Client
- Defined in:
- lib/riemann/client.rb,
lib/riemann/client/tcp.rb,
lib/riemann/client/udp.rb
Defined Under Namespace
Classes: Error, InvalidResponse, ServerError, TCP, TooBig, UDP, Unsupported
Constant Summary collapse
- HOST =
'127.0.0.1'- PORT =
5555- TIMEOUT =
5
Instance Attribute Summary collapse
-
#host ⇒ Object
Returns the value of attribute host.
-
#port ⇒ Object
Returns the value of attribute port.
-
#tcp ⇒ Object
Returns the value of attribute tcp.
-
#timeout ⇒ Object
Returns the value of attribute timeout.
-
#udp ⇒ Object
Returns the value of attribute udp.
Instance Method Summary collapse
-
#<<(event_opts) ⇒ Object
Send a state.
-
#[](query) ⇒ Object
Returns an array of states matching query.
-
#close ⇒ Object
Close both UDP and TCP sockets.
-
#connect ⇒ Object
Connect both UDP and TCP sockets.
- #connected? ⇒ Boolean
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
-
#query(string = "true") ⇒ Object
Ask for states.
- #send_maybe_recv(*a) ⇒ Object
- #send_recv(*a) ⇒ Object
Constructor Details
Instance Attribute Details
#host ⇒ Object
Returns the value of attribute host.
21 22 23 |
# File 'lib/riemann/client.rb', line 21 def host @host end |
#port ⇒ Object
Returns the value of attribute port.
21 22 23 |
# File 'lib/riemann/client.rb', line 21 def port @port end |
#tcp ⇒ Object
Returns the value of attribute tcp.
21 22 23 |
# File 'lib/riemann/client.rb', line 21 def tcp @tcp end |
#timeout ⇒ Object
Returns the value of attribute timeout.
21 22 23 |
# File 'lib/riemann/client.rb', line 21 def timeout @timeout end |
#udp ⇒ Object
Returns the value of attribute udp.
21 22 23 |
# File 'lib/riemann/client.rb', line 21 def udp @udp end |
Instance Method Details
#<<(event_opts) ⇒ Object
Send a state
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/riemann/client.rb', line 32 def <<(event_opts) # Create state case event_opts when Riemann::State event = event_opts when Riemann::Event event = event_opts else unless event_opts.include? :host event_opts[:host] = Socket.gethostname end event = Riemann::Event.new(event_opts) end = Riemann::Message.new :events => [event] # Transmit send_maybe_recv end |
#[](query) ⇒ Object
Returns an array of states matching query.
53 54 55 56 57 |
# File 'lib/riemann/client.rb', line 53 def [](query) response = query(query) (response.events || []) | (response.states || []) end |
#close ⇒ Object
Close both UDP and TCP sockets.
60 61 62 63 |
# File 'lib/riemann/client.rb', line 60 def close @udp.close @tcp.close end |
#connect ⇒ Object
Connect both UDP and TCP sockets.
66 67 68 69 |
# File 'lib/riemann/client.rb', line 66 def connect udp.connect tcp.connect end |
#connected? ⇒ Boolean
71 72 73 |
# File 'lib/riemann/client.rb', line 71 def connected? tcp.connected? and udp.connected? end |
#query(string = "true") ⇒ Object
Ask for states
76 77 78 |
# File 'lib/riemann/client.rb', line 76 def query(string = "true") send_recv Riemann::Message.new(:query => Riemann::Query.new(:string => string)) end |
#send_maybe_recv(*a) ⇒ Object
84 85 86 87 88 89 90 |
# File 'lib/riemann/client.rb', line 84 def send_maybe_recv(*a) begin @udp.send_maybe_recv *a rescue TooBig @tcp.send_maybe_recv *a end end |
#send_recv(*a) ⇒ Object
80 81 82 |
# File 'lib/riemann/client.rb', line 80 def send_recv(*a) @tcp.send_recv *a end |