Class: PingMon::Pinger
- Inherits:
-
Object
- Object
- PingMon::Pinger
- Defined in:
- lib/pingmon/pinger.rb
Class Method Summary collapse
Instance Method Summary collapse
- #host ⇒ Object
-
#initialize(configuration = Config.new) ⇒ Pinger
constructor
A new instance of Pinger.
- #ping ⇒ Object
Constructor Details
#initialize(configuration = Config.new) ⇒ Pinger
Returns a new instance of Pinger.
7 8 9 |
# File 'lib/pingmon/pinger.rb', line 7 def initialize(configuration=Config.new) @config = configuration end |
Class Method Details
.ping(host) ⇒ Object
3 4 5 |
# File 'lib/pingmon/pinger.rb', line 3 def self.ping(host) ::Ping.pingecho(host) end |
Instance Method Details
#host ⇒ Object
26 27 28 |
# File 'lib/pingmon/pinger.rb', line 26 def host @config.host if @config.loaded? end |
#ping ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/pingmon/pinger.rb', line 11 def ping @config.load unless @config.loaded? PingMon.log << "[#{Time.now}] - Pinging host '#{@config.host}'." if PingMon.log result = PingMon::Pinger.ping(@config.host) unless result PingMon.log << "[#{Time.now}] - '#{@config.host}' appears to be: DOWN. Sending notification." if PingMon.log notify_down_status if @config.notify_when_down else PingMon.log << "[#{Time.now}] - '#{@config.host}' appears to be: UP." if PingMon.log end result end |