Class: GaddyGaddyCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/gg_check/gaddy_gaddy_check.rb

Instance Method Summary collapse

Constructor Details

#initialize(extra) ⇒ GaddyGaddyCheck

Returns a new instance of GaddyGaddyCheck.



17
18
19
# File 'lib/gg_check/gaddy_gaddy_check.rb', line 17

def initialize(extra)
  @extra = extra.split(',')
end

Instance Method Details

#extraObject

Will return extra info given as parameter



24
25
26
# File 'lib/gg_check/gaddy_gaddy_check.rb', line 24

def extra
 @extra
end

#process_alive?(regexp) ⇒ Boolean

Will check if a process is live

Returns:

  • (Boolean)


51
52
53
54
# File 'lib/gg_check/gaddy_gaddy_check.rb', line 51

def process_alive? (regexp)
  status, process_lines, stderr = run_cmd "ps -ef|grep -e '#{regexp}'|grep -v grep".strip
  process_lines.size > 0
end

#run_cmd(cmd) ⇒ Object

Will run a command and return: status, stdout, stderr



32
33
34
# File 'lib/gg_check/gaddy_gaddy_check.rb', line 32

def run_cmd cmd
  systemu cmd
end

#socket(host, port, message, sleep_sec = 1) ⇒ Object

Will open a socket connection and send a message and wait for a result



39
40
41
42
43
44
45
46
# File 'lib/gg_check/gaddy_gaddy_check.rb', line 39

def socket(host,port,message,sleep_sec=1)
  Socket.tcp(host, port) {|sock|
    sock.print message
    sleep sleep_sec
    sock.close_write
    sock.read
  }
end