sensu-plugins-network-checks 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 05befbbb40128bd754c4097cd39c23cc6dcfd3e6
4
- data.tar.gz: eb80907f69c37929fa63574054cf4f75ba5428f6
3
+ metadata.gz: b91c2cab0f43f5200c2dc825c026040771355009
4
+ data.tar.gz: 48c3b6298d8d6b8771e9580e2cc120692cd236d3
5
5
  SHA512:
6
- metadata.gz: 92c7f8a40be0a0d92eff802b9ee6e678e08ee34641beea8571d05f5c4873168d3e556bd20f9431d87fa1098888ec1b2029fc12466133e7d445b671d81b65542a
7
- data.tar.gz: 9400d53919c528945403d2d99312687cecd78b3da19e07c8406b21b2f20540089ed76a15e121139267a90714567b4bdb57c9ed0ed6084829c2b4eefbf3ff8504
6
+ metadata.gz: 629b7ed21e7ee2f22f852ae5f6f0724fbf21e576238b9e53f8cb4aafbc40784eed7f9dfd6d42053af73d6e78cc40b8550ff56cb763e182ebb483dabb7db0da17
7
+ data.tar.gz: ba7c01d145a66fad0ed4aa3d9a7efc538a2a19974afd6e8d52a3009b9f460964047593050bc1aae8a5023f1462a5afb7a825627f0b04f3d7942449ec3026961e
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -5,6 +5,13 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
5
5
 
6
6
  ## [Unreleased][unreleased]
7
7
 
8
+ ## [0.0.6] - 2015-10-01
9
+ ### Added
10
+ - Added new port check
11
+
12
+ ### Changed
13
+ - Changed name of check-ports to check-ports-nmap
14
+
8
15
  ## [0.0.5] - 2015-08-05
9
16
  ### Added
10
17
  - Added new metrics-ping.rb plugin
@@ -27,6 +34,10 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
27
34
  - cleaned up Rakefile
28
35
  - updated documentation links
29
36
 
37
+ ### Refactored
38
+ - renamed check-ports.rb to check-ports-nmap.rb
39
+ - added check-ports.rb based in TCPSocket instead of nmap
40
+
30
41
  ## [0.0.2] - 2015-06-03
31
42
 
32
43
  ### Fixed
data/README.md CHANGED
@@ -13,6 +13,7 @@
13
13
  * bin/check-multicast-groups.rb
14
14
  * bin/check-netstat-tcp.rb
15
15
  * bin/check-ping.rb
16
+ * bin/check-ports-nmap.rb
16
17
  * bin/check-ports.rb
17
18
  * bin/check-rbl.rb
18
19
  * bin/check-whois-domain-expiration-multi.rb
@@ -24,6 +25,25 @@
24
25
 
25
26
  ## Usage
26
27
 
28
+ **check-ports**
29
+ This check now uses a TCPSocket, not nmap (see next below)
30
+ ```
31
+ check-ports.rb -h 0.0.0.0 -p 22,25,3030 -t 30
32
+
33
+ Usage: bin/check-ports.rb (options)
34
+ -H, --hostnames HOSTNAME Host to connect to
35
+ -p, --ports PORTS Ports to check, comma separated
36
+ -t, --timeout SECS Connection timeout
37
+ ```
38
+
39
+ **check-ports-nmap**
40
+ ```
41
+ Usage: bin/check-ports-nmap.rb (options)
42
+ -h, --host HOST Resolving name or IP address of target host
43
+ -l, --level crit|warn Alert level crit(critical) or warn(warning)
44
+ -t, --ports PORT,PORT... TCP port(s) you wish to get status for
45
+ ```
46
+
27
47
  **check-multicast-groups**
28
48
  ```
29
49
  {
@@ -83,7 +83,7 @@ class CheckNetstatTCP < Sensu::Plugin::Check::CLI
83
83
  TCP_STATES.each_pair { |_hex, name| state_counts[name] = 0 }
84
84
 
85
85
  protocols.select { |p| File.exist?('/proc/net/' + p) }.each do |protocol|
86
- File.open('/proc/net/' + protocol).each do |line| # rubocop:disable Style/Next
86
+ File.open('/proc/net/' + protocol).each do |line|
87
87
  line.strip!
88
88
  if m = line.match(/^\s*\d+:\s+(.{8}|.{32}):(.{4})\s+(.{8}|.{32}):(.{4})\s+(.{2})/) # rubocop:disable AssignmentInCondition
89
89
  connection_state = m[5]
@@ -0,0 +1,89 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-ports-nmap
4
+ #
5
+ # DESCRIPTION:
6
+ # Fetch port status using nmap. This check is good for catching bad network ACLs
7
+ # or service down events for network resources.
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux, Windows, BSD, Solaris, etc
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ # nmap package
18
+ #
19
+ # USAGE:
20
+ # $ ./check-ports-nmap.rb --host some_server --ports 5671,5672 --level crit
21
+ #
22
+ # NOTES:
23
+ # #YELLOW
24
+ # Look at rewriting this using the namp library to not depend on external tools
25
+ #
26
+ # LICENSE:
27
+ # Copyright 2013 GoDaddy.com, LLC <jjmanzer@godaddy.com>
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+ #
31
+
32
+ require 'open3'
33
+ require 'sensu-plugin/check/cli'
34
+ require 'json'
35
+
36
+ # CheckPorts
37
+ class CheckPorts < Sensu::Plugin::Check::CLI
38
+ option :host,
39
+ description: 'Resolving name or IP address of target host',
40
+ short: '-h HOST',
41
+ long: '--host HOST',
42
+ default: 'localhost'
43
+
44
+ option :ports,
45
+ description: 'TCP port(s) you wish to get status for',
46
+ short: '-t PORT,PORT...',
47
+ long: '--ports PORT,PORT...'
48
+
49
+ option :level,
50
+ description: 'Alert level crit(critical) or warn(warning)',
51
+ short: '-l crit|warn',
52
+ long: '--level crit|warn',
53
+ default: 'WARN'
54
+
55
+ def run
56
+ stdout, stderr = Open3.capture3(
57
+ ENV,
58
+ "nmap -P0 -p #{config[:ports]} #{config[:host]}"
59
+ )
60
+
61
+ case stderr
62
+ when /Failed to resolve/
63
+ critical 'cannot resolve the target hostname'
64
+ end
65
+
66
+ port_checks = {}
67
+ check_pass = true
68
+
69
+ stdout.split("\n").each do |line|
70
+ line.scan(/(\d+).tcp\s+(\w+)\s+(\w+)/).each do |status|
71
+ port_checks[status[1]] ||= []
72
+ port_checks[status[1]].push status[0]
73
+ check_pass = false unless status[1]['open']
74
+ end
75
+ end
76
+
77
+ result = port_checks.map { |state, ports| "#{state}:#{ports.join(',')}" }.join(' ')
78
+
79
+ if check_pass
80
+ ok result
81
+ elsif config[:level].upcase == 'WARN'
82
+ warning result
83
+ elsif config[:level].upcase == 'CRIT'
84
+ critical result
85
+ else
86
+ unknown "Unknown alert level #{config[:level]}"
87
+ end
88
+ end
89
+ end
@@ -1,89 +1,84 @@
1
1
  #! /usr/bin/env ruby
2
2
  #
3
- # check-ports
3
+ # encoding: UTF-8
4
+ # check-ports-socket
4
5
  #
5
6
  # DESCRIPTION:
6
- # Fetch port status using nmap. This check is good for catching bad network ACLs
7
- # or service down events for network resources.
7
+ # Connect to a TCP port on one or more ports, to see if open. Don't use nmap since it's overkill.
8
8
  #
9
9
  # OUTPUT:
10
10
  # plain text
11
11
  #
12
12
  # PLATFORMS:
13
- # Linux, Windows, BSD, Solaris, etc
13
+ # Linux
14
14
  #
15
15
  # DEPENDENCIES:
16
16
  # gem: sensu-plugin
17
- # nmap package
18
17
  #
19
18
  # USAGE:
20
- # $ ./check-ports.rb --host some_server --ports 5671,5672 --level crit
19
+ #
20
+ # To check there is only one zk leader
21
+ # ./check-ports-socket.rb -h localhost -p 22,25,80
21
22
  #
22
23
  # NOTES:
23
- # #YELLOW
24
- # Look at rewriting this using the namp library to not depend on external tools
24
+ # By default, checks for openssh on localhost port 22
25
+ #
25
26
  #
26
27
  # LICENSE:
27
- # Copyright 2013 GoDaddy.com, LLC <jjmanzer@godaddy.com>
28
28
  # Released under the same terms as Sensu (the MIT license); see LICENSE
29
29
  # for details.
30
- #
31
30
 
32
- require 'open3'
33
31
  require 'sensu-plugin/check/cli'
34
- require 'json'
32
+ require 'socket'
33
+ require 'timeout'
35
34
 
36
- # CheckPorts
37
- class CheckPorts < Sensu::Plugin::Check::CLI
35
+ #
36
+ # Check Banner
37
+ #
38
+ class CheckPort < Sensu::Plugin::Check::CLI
38
39
  option :host,
39
- description: 'Resolving name or IP address of target host',
40
- short: '-h HOST',
41
- long: '--host HOST',
42
- default: 'localhost'
40
+ short: '-H HOSTNAME',
41
+ long: '--hostname HOSTNAME',
42
+ description: 'Host to connect to',
43
+ default: '0.0.0.0'
43
44
 
44
45
  option :ports,
45
- description: 'TCP port(s) you wish to get status for',
46
- short: '-t PORT,PORT...',
47
- long: '--ports PORT,PORT...'
48
-
49
- option :level,
50
- description: 'Alert level crit(critical) or warn(warning)',
51
- short: '-l crit|warn',
52
- long: '--level crit|warn',
53
- default: 'WARN'
46
+ short: '-p PORTS',
47
+ long: '--ports PORTS',
48
+ description: 'Ports to check, comma separated (22,25,3030)',
49
+ default: '22'
54
50
 
55
- def run
56
- stdout, stderr = Open3.capture3(
57
- ENV,
58
- "nmap -P0 -p #{config[:ports]} #{config[:host]}"
59
- )
51
+ option :timeout,
52
+ short: '-t SECS',
53
+ long: '--timeout SECS',
54
+ description: 'Connection timeout',
55
+ proc: proc(&:to_i),
56
+ default: 30
60
57
 
61
- case stderr
62
- when /Failed to resolve/
63
- critical 'cannot resolve the target hostname'
58
+ def check_port(port)
59
+ timeout(config[:timeout]) do
60
+ TCPSocket.new(config[:host], port.to_i)
64
61
  end
62
+ rescue Errno::ECONNREFUSED
63
+ critical "Connection refused by #{config[:host]}:#{port}"
64
+ rescue Timeout::Error
65
+ critical "Connection or read timed out (#{config[:host]}:#{port})"
66
+ rescue Errno::EHOSTUNREACH
67
+ critical "Check failed to run: No route to host (#{config[:host]}:#{port})"
68
+ rescue EOFError
69
+ critical "Connection closed unexpectedly (#{config[:host]}:#{port})"
70
+ end
65
71
 
66
- port_checks = {}
67
- check_pass = true
68
-
69
- stdout.split("\n").each do |line|
70
- line.scan(/(\d+).tcp\s+(\w+)\s+(\w+)/).each do |status|
71
- port_checks[status[1]] ||= []
72
- port_checks[status[1]].push status[0]
73
- check_pass = false unless status[1]['open']
74
- end
72
+ def run
73
+ ports = config[:ports].split(',')
74
+ okarray = []
75
+ ports.each do |port|
76
+ okarray << 'ok' if check_port port
75
77
  end
76
-
77
- result = port_checks.map { |state, ports| "#{state}:#{ports.join(',')}" }.join(' ')
78
-
79
- if check_pass
80
- ok result
81
- elsif config[:level].upcase == 'WARN'
82
- warning result
83
- elsif config[:level].upcase == 'CRIT'
84
- critical result
78
+ if okarray.size == ports.size
79
+ ok "All ports (#{config[:ports]}) are accessible for host #{config[:host]}"
85
80
  else
86
- unknown "Unknown alert level #{config[:level]}"
81
+ critical "port count or pattern #{config[:pattern]} does not match" unless config[:crit_message]
87
82
  end
88
83
  end
89
84
  end
@@ -77,7 +77,7 @@ class RblCheck < Sensu::Plugin::Check::CLI
77
77
  criticality = 0
78
78
 
79
79
  # #YELLOW
80
- dnsbl_ret.each do |dnsbl_result| # rubocop:disable Style/Next
80
+ dnsbl_ret.each do |dnsbl_result|
81
81
  if dnsbl_result.meaning =~ /spam/i || dnsbl_result.meaning =~ /blacklist/i
82
82
  unless ignored_bls_set.member?(dnsbl_result.dnsbl)
83
83
  msg_string = "#{msg_string} #{dnsbl_result.dnsbl}"
@@ -38,7 +38,7 @@ class NetIFMetrics < Sensu::Plugin::Metric::CLI::Graphite
38
38
  default: "#{Socket.gethostname}"
39
39
 
40
40
  def run
41
- `sar -n DEV 1 1 | grep Average | grep -v IFACE`.each_line do |line| # rubocop:disable Style/Next
41
+ `sar -n DEV 1 1 | grep Average | grep -v IFACE`.each_line do |line|
42
42
  stats = line.split(/\s+/)
43
43
  unless stats.empty?
44
44
  stats.shift
@@ -80,7 +80,7 @@ class NetstatTCPMetrics < Sensu::Plugin::Metric::CLI::Graphite
80
80
  state_counts = Hash.new(0)
81
81
  TCP_STATES.each_pair { |_hex, name| state_counts[name] = 0 }
82
82
 
83
- File.open('/proc/net/' + protocol).each do |line| # rubocop:disable Style/Next
83
+ File.open('/proc/net/' + protocol).each do |line|
84
84
  line.strip!
85
85
  if m = line.match(/^\s*\d+:\s+(.{8}):(.{4})\s+(.{8}):(.{4})\s+(.{2})/) # rubocop:disable AssignmentInCondition
86
86
  connection_state = m[5]
@@ -99,7 +99,7 @@ class NetstatTCPMetrics < Sensu::Plugin::Metric::CLI::Graphite
99
99
  def run
100
100
  timestamp = Time.now.to_i
101
101
  netstat('tcp').each do |state, count|
102
- graphite_name = config[:port] ? "#{config[:scheme]}.#{config[:port]}.#{state}" : # rubocop:disable all
102
+ graphite_name = config[:port] ? "#{config[:scheme]}.#{config[:port]}.#{state}" :
103
103
  "#{config[:scheme]}.#{state}"
104
104
  output "#{graphite_name}", count, timestamp
105
105
  end
@@ -2,7 +2,7 @@ module SensuPluginsNetworkChecks
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 5
5
+ PATCH = 6
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-network-checks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
@@ -30,7 +30,7 @@ cert_chain:
30
30
  8sHuVruarogxxKPBzlL2is4EUb6oN/RdpGx2l4254+nyR+abg//Ed27Ym0PkB4lk
31
31
  HP0m8WSjZmFr109pE/sVsM5jtOCvogyujQOjNVGN4gz1wwPr
32
32
  -----END CERTIFICATE-----
33
- date: 2015-08-05 00:00:00.000000000 Z
33
+ date: 2015-10-01 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: dnsbl-client
@@ -230,6 +230,7 @@ executables:
230
230
  - check-whois-domain-expiration-multi.rb
231
231
  - check-rbl.rb
232
232
  - check-ports.rb
233
+ - check-ports-nmap.rb
233
234
  - check-ping.rb
234
235
  - check-netstat-tcp.rb
235
236
  - check-multicast-groups.rb
@@ -246,6 +247,7 @@ files:
246
247
  - bin/check-multicast-groups.rb
247
248
  - bin/check-netstat-tcp.rb
248
249
  - bin/check-ping.rb
250
+ - bin/check-ports-nmap.rb
249
251
  - bin/check-ports.rb
250
252
  - bin/check-rbl.rb
251
253
  - bin/check-whois-domain-expiration-multi.rb
metadata.gz.sig CHANGED
Binary file