Last active
August 29, 2015 14:20
-
-
Save stibi/f3f8c5ca4c40a939a14b to your computer and use it in GitHub Desktop.
Getting data from Icinga2 with ruby and livestatus
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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