Class: Livestatus::UnixHandler
- Inherits:
-
BaseHandler
- Object
- BaseHandler
- Livestatus::UnixHandler
- Defined in:
- lib/livestatus/handler/unix.rb
Instance Method Summary collapse
- #get(table_name, options = {}) ⇒ Object
-
#initialize(config) ⇒ UnixHandler
constructor
A new instance of UnixHandler.
- #query(method, query, headers = {}) ⇒ Object
Methods inherited from BaseHandler
Constructor Details
#initialize(config) ⇒ UnixHandler
Returns a new instance of UnixHandler.
8 9 10 |
# File 'lib/livestatus/handler/unix.rb', line 8 def initialize(config) @socket = UNIXSocket.open(config[:uri].sub(/^unix:\/\//, '')) end |
Instance Method Details
#get(table_name, options = {}) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/livestatus/handler/unix.rb', line 12 def get(table_name, = {}) data = super if .include?(:columns) columns = [:columns].split(" ") else columns = data.delete_at(0) end column_zip(columns, data) end |
#query(method, query, headers = {}) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/livestatus/handler/unix.rb', line 24 def query(method, query, headers = {}) headers.merge!({ :response_header => "fixed16", :output_format => "json", :keep_alive => "on", }) headers = headers.map { |k,v| "#{k.to_s.camelize}: #{v}" }.join("\n") headers += "\n" unless headers.empty? @socket.write("#{method.to_s.upcase} #{query}\n#{headers}\n") res = @socket.read(16) status, length = res[0..2].to_i, res[4..14].chomp.to_i unless status == 200 raise HandlerException, "livestatus query failed with status #{status}" end Yajl::Parser.new.parse(@socket.read(length)) end |