Class: Riemann::Tools::Portcheck
- Inherits:
-
Object
- Object
- Riemann::Tools::Portcheck
- Includes:
- Riemann::Tools
- Defined in:
- lib/riemann/tools/portcheck.rb
Constant Summary
Constants included from Riemann::Tools
Instance Attribute Summary
Attributes included from Riemann::Tools
Instance Method Summary collapse
-
#initialize ⇒ Portcheck
constructor
A new instance of Portcheck.
- #tick ⇒ Object
Methods included from Riemann::Tools
#attributes, #endpoint_name, included, #options, #report, #riemann, #run
Constructor Details
#initialize ⇒ Portcheck
Returns a new instance of Portcheck.
16 17 18 19 20 21 |
# File 'lib/riemann/tools/portcheck.rb', line 16 def initialize super @hostname = opts.fetch(:hostname) @ports = opts.fetch(:ports) end |
Instance Method Details
#tick ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# 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 |