Class: EzNemo::Ping
- Inherits:
-
Object
- Object
- EzNemo::Ping
- Defined in:
- lib/eznemo/monitor/ping.rb
Overview
ICMP ping plugin
Constant Summary collapse
- DEFAULT_MIN_INTERVAL =
10
- DEFAULT_TIMEOUT =
5
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
Returns the value of attribute config.
-
#monitor ⇒ Object
readonly
Returns the value of attribute monitor.
Instance Method Summary collapse
-
#add_check(check) ⇒ Object
Add a check using this plugin.
- #bsd_ping(check) ⇒ Object
-
#initialize ⇒ Ping
constructor
A new instance of Ping.
- #linux_ping(check) ⇒ Object
-
#name ⇒ Symbol
Gets called by Monitor at regisration.
-
#registered(mon) ⇒ Object
Gets called by Monitor after regisration.
Constructor Details
#initialize ⇒ Ping
Returns a new instance of Ping.
12 13 14 15 16 17 18 19 20 |
# File 'lib/eznemo/monitor/ping.rb', line 12 def initialize os = RbConfig::CONFIG['host_os'] case when os.include?('darwin') @os = 'bsd' when os.include?('linux') @os = 'linux' end end |
Instance Attribute Details
#config ⇒ Object (readonly)
Returns the value of attribute config.
10 11 12 |
# File 'lib/eznemo/monitor/ping.rb', line 10 def config @config end |
#monitor ⇒ Object (readonly)
Returns the value of attribute monitor.
9 10 11 |
# File 'lib/eznemo/monitor/ping.rb', line 9 def monitor @monitor end |
Instance Method Details
#add_check(check) ⇒ Object
Add a check using this plugin
42 43 44 45 46 47 48 |
# File 'lib/eznemo/monitor/ping.rb', line 42 def add_check(check) min = config[:min_interval] check[:interval] = min if check[:interval] < min EM.add_periodic_timer(check[:interval]) do self.send("#{@os}_ping", check) end end |
#bsd_ping(check) ⇒ Object
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/eznemo/monitor/ping.rb', line 67 def bsd_ping(check) result = create_result_for_check(check) args = {timeout: config[:timeout] * 1000} EM.system(build_cmd(check, args)) do |output, status| case status.exitstatus when 0 expr = /=\s*([0-9\.]+)/ expr =~ output set_ok_result(result, $1.to_f) when 2 set_ng_result(result) else set_error_result(result, output) end monitor.report(result) end end |
#linux_ping(check) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/eznemo/monitor/ping.rb', line 50 def linux_ping(check) result = create_result_for_check(check) EM.system(build_cmd(check)) do |output, status| case status.exitstatus when 0 expr = /=\s*([0-9\.]+)/ expr =~ output set_ok_result(result, $1.to_f) when 1 set_ng_result(result) else set_error_result(result, output) end monitor.report(result) end end |
#name ⇒ Symbol
Gets called by Monitor at regisration
24 25 26 |
# File 'lib/eznemo/monitor/ping.rb', line 24 def name return :ping end |
#registered(mon) ⇒ Object
Gets called by Monitor after regisration
30 31 32 33 34 35 36 37 38 |
# File 'lib/eznemo/monitor/ping.rb', line 30 def registered(mon) @monitor = mon @config = EzNemo.config[:monitor][:ping] if EzNemo.config[:monitor] @config ||= {} @config[:path] ||= 'ping' @config[:min_interval] ||= DEFAULT_MIN_INTERVAL @config[:timeout] ||= DEFAULT_TIMEOUT EzNemo.logger.info 'Ping plugin registered.' end |