Sha256: 85e4a553abc919be31d9f35ffcdfc840d9b879087bbc688778449535029ed2a1

Contents?: true

Size: 1.27 KB

Versions: 9

Compression:

Stored size: 1.27 KB

Contents

module Sc4ry
  module Helpers

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

    # TCP/IP service checker
    # @return [Bool] status
    # @param [Hash] options
    # @option options [String] :host hostname
    # @option options [String] :port TCP port
    # @option options [String] :url full URL, priority on :host and :port
    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


    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

  end 
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sc4ry-0.1.8 lib/sc4ry/helpers.rb
sc4ry-0.1.7 lib/sc4ry/helpers.rb
sc4ry-0.1.6 lib/sc4ry/helpers.rb
sc4ry-0.1.5 lib/sc4ry/helpers.rb
sc4ry-0.1.4 lib/sc4ry/helpers.rb
sc4ry-0.1.3 lib/sc4ry/helpers.rb
sc4ry-0.1.2 lib/sc4ry/helpers.rb
sc4ry-0.1.1 lib/sc4ry/helpers.rb
sc4ry-0.1.0 lib/sc4ry/helpers.rb