Class: Riemann::Client
- Inherits:
-
Object
- Object
- Riemann::Client
- Defined in:
- lib/riemann/client.rb,
lib/riemann/client/tcp.rb,
lib/riemann/client/udp.rb,
lib/riemann/client/tcp_socket.rb
Defined Under Namespace
Classes: Error, InvalidResponse, ServerError, TCP, TcpSocket, TooBig, UDP, Unsupported
Constant Summary collapse
- HOST =
'127.0.0.1'- PORT =
5555- TIMEOUT =
5
Instance Attribute Summary collapse
-
#tcp ⇒ Object
readonly
Returns the value of attribute tcp.
-
#udp ⇒ Object
readonly
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
- #connected? ⇒ Boolean
- #host ⇒ Object
-
#initialize(opts = {}) ⇒ Client
constructor
A new instance of Client.
- #port ⇒ Object
-
#query(string = "true") ⇒ Object
Ask for states.
- #send_maybe_recv(*a) ⇒ Object
- #send_recv(*a) ⇒ Object
- #timeout ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Client
Returns a new instance of Client.
23 24 25 26 27 28 29 30 31 |
# File 'lib/riemann/client.rb', line 23 def initialize(opts = {}) @options = opts.dup @options[:host] ||= HOST @options[:port] ||= PORT @options[:timeout] ||= TIMEOUT @udp = UDP.new(@options) @tcp = TCP.new(@options) end |
Instance Attribute Details
#tcp ⇒ Object (readonly)
Returns the value of attribute tcp.
21 22 23 |
# File 'lib/riemann/client.rb', line 21 def tcp @tcp end |
#udp ⇒ Object (readonly)
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
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/riemann/client.rb', line 46 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.
67 68 69 70 71 |
# File 'lib/riemann/client.rb', line 67 def [](query) response = query(query) (response.events || []) | (response.states || []) end |
#close ⇒ Object
Close both UDP and TCP sockets.
79 80 81 82 |
# File 'lib/riemann/client.rb', line 79 def close @udp.close @tcp.close end |
#connect ⇒ Object
73 74 75 76 |
# File 'lib/riemann/client.rb', line 73 def connect # NOTE: connections are made automatically on send warn "Riemann client#connect is deprecated" end |
#connected? ⇒ Boolean
84 85 86 |
# File 'lib/riemann/client.rb', line 84 def connected? tcp.connected? and udp.connected? end |
#host ⇒ Object
33 34 35 |
# File 'lib/riemann/client.rb', line 33 def host @options[:host] end |
#port ⇒ Object
37 38 39 |
# File 'lib/riemann/client.rb', line 37 def port @options[:port] end |
#query(string = "true") ⇒ Object
Ask for states
89 90 91 |
# File 'lib/riemann/client.rb', line 89 def query(string = "true") send_recv Riemann::Message.new(:query => Riemann::Query.new(:string => string)) end |
#send_maybe_recv(*a) ⇒ Object
97 98 99 100 101 102 103 |
# File 'lib/riemann/client.rb', line 97 def send_maybe_recv(*a) begin @udp.send_maybe_recv *a rescue TooBig @tcp.send_maybe_recv *a end end |
#send_recv(*a) ⇒ Object
93 94 95 |
# File 'lib/riemann/client.rb', line 93 def send_recv(*a) @tcp.send_recv *a end |
#timeout ⇒ Object
41 42 43 |
# File 'lib/riemann/client.rb', line 41 def timeout @options[:timeout] end |