Class: Hookit::Resource::Socket

Inherits:
Base
  • Object
show all
Defined in:
lib/hookit/resource/socket.rb

Instance Attribute Summary

Attributes inherited from Base

#dict

Instance Method Summary collapse

Methods inherited from Base

#action, actions, #can_run?, default_action, #default_action, field, #not_if, #only_if

Constructor Details

#initialize(name) ⇒ Socket

Returns a new instance of Socket.



13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/hookit/resource/socket.rb', line 13

def initialize(name)
  service name unless service
  max_checks 3 unless max_checks
  super

  case platform.os
  when 'sun'
    @active_com   = "netstat -an | egrep '\*\.#{port}' | grep LISTEN"
    @inactive_com = "netstat -an | grep 'ESTABLISHED' | awk '{ print $1 }' | grep \"$(ifconfig #{interface} | grep inet | awk '{ print $2 }')\.#{port}\""
  else
    @active_com   = "netstat -an | egrep ':#{port}' | grep LISTEN"
    @inactive_com = "netstat -an | grep 'ESTABLISHED' | awk '{ print $4 }' | grep \"$(ifconfig #{interface} | awk '/inet addr/ { print $2}' | cut -f2 -d':' | tr -d '\n'):#{port}\""
  end
end

Instance Method Details

#run(action) ⇒ Object



28
29
30
31
32
33
34
35
36
37
# File 'lib/hookit/resource/socket.rb', line 28

def run(action)
  case action
  when :listening
    check_listening!
  when :no_connections
    check_no_connections!
  when :reset
    reset!
  end
end