Class: IcingaDashing::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/icinga-dashing/socket.rb

Instance Method Summary collapse

Instance Method Details

#getdevices(type, columns, filters) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/icinga-dashing/socket.rb', line 18

def getdevices(type,columns,filters)
  s = socket_initialize
  s.send "GET #{type}\n", 0
  s.send "Columns: #{columns}\n", 0
  s.send "Filter: #{filters}\n", 0
  s.send "OutputFormat: csv\n", 0
  answer = socket_close(s)
end

#getstate(hostname) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/icinga-dashing/socket.rb', line 27

def getstate(hostname)
  s = socket_initialize
  s.send "GET hosts\n", 0
  s.send "Columns: state acknowledged\n", 0
  s.send "Filter: name = #{hostname}\n", 0
  s.send "OutputFormat: csv\n", 0
  answer = socket_close(s)
end

#socket_close(s) ⇒ Object



11
12
13
14
15
16
# File 'lib/icinga-dashing/socket.rb', line 11

def socket_close(s)
  s.shutdown(:WR)
  answer = s.read
  s.close
  return answer
end

#socket_initialize(hostname, port) ⇒ Object



7
8
9
# File 'lib/icinga-dashing/socket.rb', line 7

def socket_initialize(hostname,port)
  return TCPSocket.open(hostname,port)
end