Module: Sc4ry::Helpers
- Defined in:
- lib/sc4ry/helpers.rb
Overview
Note:
namespace
Sc4ry::Helpers module
Class Method Summary collapse
-
.log(message:, target: nil, level: :info) ⇒ Boolean
class method (module) to help logging messages.
-
.notify(options = {}) ⇒ Boolean
class method (module) to help send notifiesby Sc4ry::Notifiers.
-
.verify_service(options = {}) ⇒ Bool
TCP/IP service checker.
Class Method Details
.log(message:, target: nil, level: :info) ⇒ Boolean
class method (module) to help logging messages
14 15 16 17 18 19 20 |
# File 'lib/sc4ry/helpers.rb', line 14 def self.log(message:, target: nil, level: :info) save = Sc4ry::Loggers.current Sc4ry::Loggers.current = target if target Sc4ry::Loggers.get.send level, "Sc4ry : #{}" Sc4ry::Loggers.current = save true end |
.notify(options = {}) ⇒ Boolean
class method (module) to help send notifiesby Sc4ry::Notifiers
51 52 53 54 55 56 |
# File 'lib/sc4ry/helpers.rb', line 51 def self.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
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/sc4ry/helpers.rb', line 28 def self.verify_service( = {}) if [:url] uri = URI.parse([:url]) host = uri.host port = uri.port else host = [:host] port = [:port] end Timeout.timeout(1) do s = TCPSocket.new(host, port) s.close return true rescue Errno::ECONNREFUSED, Errno::EHOSTUNREACH return false end rescue Timeout::Error false end |