Skip to content

Instantly share code, notes, and snippets.

@stibi
Last active August 29, 2015 14:20
Show Gist options
  • Save stibi/f3f8c5ca4c40a939a14b to your computer and use it in GitHub Desktop.
Save stibi/f3f8c5ca4c40a939a14b to your computer and use it in GitHub Desktop.
Getting data from Icinga2 with ruby and livestatus
require 'socket'
host = 'icinga_ip_address'
port = 6558
query = "GET hosts\n"
query << "Columns: name alias state services_with_state\n"
query << "OutputFormat: json\n"
query << "ResponseHeader: fixed16"
socket = TCPSocket.new(host, port)
socket.send(query, 0)
socket.send("\n", 0)
socket.send("\n", 0)
socket.shutdown(Socket::SHUT_WR)
response_header = socket.recv(16)
puts "header:"
puts response_header
puts "data:"
data = ""
while(line = socket.gets) do
data << line
end
puts data
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment