class Riemann::Tools::Portcheck
Public Class Methods
new()
click to toggle source
Calls superclass method
Riemann::Tools::new
# File lib/riemann/tools/portcheck.rb, line 16 def initialize super @hostname = opts.fetch(:hostname) @ports = opts.fetch(:ports) end
Public Instance Methods
tick()
click to toggle source
# File lib/riemann/tools/portcheck.rb, line 23 def tick @ports.each do |thisport| # try opening tcp connection with 5s timeout; # if this fails, the port is considered closed portopen = begin Socket.tcp(@hostname, thisport, connect_timeout: 5) { true } rescue StandardError false end state = if portopen 'ok' else 'critical' end report( host: @hostname.to_s, service: "port #{thisport}", state: state.to_s, tags: ['portcheck'], ) end end