Module: Sc4ry::Helpers

Defined in:
lib/sc4ry/helpers.rb

Class Method Summary collapse

Class Method Details

.log(options) ⇒ Object



5
6
7
8
# File 'lib/sc4ry/helpers.rb', line 5

def Helpers.log(options)
  Sc4ry::Logger.current = options[:target] if options[:target]
  Sc4ry::Logger.get.send options[:level], "Sc4ry : #{options[:message]}"  
end

.notify(options = {}) ⇒ Object



41
42
43
44
45
46
# File 'lib/sc4ry/helpers.rb', line 41

def Helpers.notify(options = {})
  Sc4ry::Notifiers.list.each do |record|
    notifier = Sc4ry::Notifiers.get name: record
    notifier[:class].notify(options) if options[:config][:notifiers].include? record 
  end
end

.verify_service(options = {}) ⇒ Bool

TCP/IP service checker

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • :host (String)

    hostname

  • :port (String)

    TCP port

  • :url (String)

    full URL, priority on :host and :port

Returns:

  • (Bool)

    status



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sc4ry/helpers.rb', line 16

def Helpers.verify_service(options ={})
  begin
    if options[:url] then
      uri = URI.parse(options[:url])
      host = uri.host
      port = uri.port
    else
      host = options[:host]
      port = options[:port]
    end
    Timeout::timeout(1) do
      begin
        s = TCPSocket.new(host, port)
        s.close
        return true
      rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH
        return false
      end
    end
  rescue Timeout::Error
    return false
  end
end