Module: Sc4ry::Helpers
- Defined in:
- lib/sc4ry/helpers.rb
Class Method Summary collapse
- .log(options) ⇒ Object
- .notify(options = {}) ⇒ Object
-
.verify_service(options = {}) ⇒ Bool
TCP/IP service checker.
Class Method Details
.log(options) ⇒ Object
5 6 7 8 |
# File 'lib/sc4ry/helpers.rb', line 5 def Helpers.log() Sc4ry::Logger.current = [:target] if [:target] Sc4ry::Logger.get.send [:level], "Sc4ry : #{[:message]}" end |
.notify(options = {}) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/sc4ry/helpers.rb', line 41 def Helpers.notify( = {}) Sc4ry::Notifiers.list.each do |record| notifier = Sc4ry::Notifiers.get name: record notifier[:class].notify() if [:config][:notifiers].include? record end end |
.verify_service(options = {}) ⇒ Bool
TCP/IP service checker
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( ={}) begin if [:url] then uri = URI.parse([:url]) host = uri.host port = uri.port else host = [:host] port = [: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 |