13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
|
# File 'lib/livestatus/handler/unix.rb', line 13
def get(model, options = {})
options.merge!({
:response_header => "fixed16",
:output_format => "json",
:keep_alive => "on",
})
= options.map do |k,v|
if v.is_a?(Array)
v.map do |e|
"#{k.to_s.camelize}: #{e}"
end
else
"#{k.to_s.camelize}: #{v}"
end
end.flatten.join("\n")
+= "\n" unless .empty?
@socket.write("GET #{model.table_name}\n#{}\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
data = Yajl::Parser.new.parse(@socket.read(length))
if options.include?(:columns)
columns = options[:columns].split(" ")
else
columns = data.delete_at(0)
end
column_zip(columns, data).map do |d|
model.new(d, @connection)
end
end
|