sensu-plugins-network-checks 1.1.0 → 1.2.0

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: 46421c6d0dc7862d251f2700a9a4487b9f144f7a
4
- data.tar.gz: 7131967b4d010104830c77fb483b3cbfa295ac4a
3
+ metadata.gz: 651fd18722857deccf8b625724d9af60f6fa6f11
4
+ data.tar.gz: fac9caaa1715e6dce254c730f7292c1b229a5efc
5
5
  SHA512:
6
- metadata.gz: f84d7725673e378612e026fac3a2f027a2d73d2b04457947be44170fd632035b1535f08e29dc1daf9f858e9d81bb5e4b54f32ebb34b8b5a2ed54e8f7edd15a77
7
- data.tar.gz: 92b82831b5022e73ff521be0fdb22048822ed13d643f6b80c3759994909626aed8d65b266db5d815e2859c1202c2d16b1d731f15d0cfe7a094bdbb68fddbd5be
6
+ metadata.gz: 786041c0783aed55f063262ed705438e40af3b662406527a3d9d308190f1597c6c8e539eb08fa82519bb38797208a7e0c6174205b4cc38db4dbfbfe94531ce67
7
+ data.tar.gz: fd47db814330cc687da22208cc4b642cbd3cdb0c9b1d271529b5a7994f1d58c7d75978dcbf217d062542edc4aee1faa7d49adb1e659b8c613759d72f649deb6d
data/CHANGELOG.md CHANGED
@@ -4,6 +4,21 @@ This project adheres to [Semantic Versioning](http://semver.org/).
4
4
  This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachangelog.com/)
5
5
 
6
6
  ## [Unreleased]
7
+ ## [1.2.0] - 2017-06-07
8
+ ### Added
9
+ - Added check-ports-bind.rb (@hanynowsky)
10
+ - Added interval option to metrics-netif.rb (@Evesy)
11
+ - metrics-netif.rb: expose average-key option that is used to `grep` to more easily handle locale issues (@majormoses)
12
+ - metrics-netif.rb: unknown if it can not find `sar` in its `$PATH` (@majormoses)
13
+ - check-ping.rb: unknown if using `--reports` and do not have `mtr` installed and in "$PATH" (@majormoses)
14
+
15
+ ### Fixed
16
+ - metrics-netstat-tcp.rb: Option to disable IPv6 check (#44 via @MattMencel)
17
+ - check-multicast-groups.rb: Fix undefined method deep_merge for []:Array (@maoe)
18
+ - check-whois-domain-expiration-multi.rb does not fail as timeout is cast to integer (@majormoses)
19
+
20
+ ### Changed
21
+ - check-banner.rb: Option to enable SSL socket for secure connection
7
22
 
8
23
  ## [1.1.0] - 2016-08-07
9
24
  ### Added
@@ -29,7 +44,7 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
29
44
 
30
45
  ## [0.2.4] - 2016-04-02
31
46
  ### Fixed
32
- - metrics-ping.rb: Fix error when a host can't be pinged. Convert to a proper metrics check.
47
+ - metrics-ping.rb: Fix error when a host cannot be pinged. Convert to a proper metrics check.
33
48
 
34
49
  ### Added
35
50
  - basic check for netfilter conntrack
@@ -151,7 +166,8 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
151
166
 
152
167
  * initial release, same as community repo
153
168
 
154
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/1.1.0...HEAD
169
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/1.2.0...HEAD
170
+ [1.2.0]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/1.1.0...1.2.0
155
171
  [1.1.0]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/1.0.0...1.1.0
156
172
  [1.0.0]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/0.2.4...1.0.0
157
173
  [0.2.4]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/0.1.4...0.2.4
data/README.md CHANGED
@@ -16,6 +16,7 @@
16
16
  * bin/check-ping.rb
17
17
  * bin/check-ports-nmap.rb
18
18
  * bin/check-ports.rb
19
+ * bin/check-ports-bind.rb
19
20
  * bin/check-rbl.rb
20
21
  * bin/check-socat.rb
21
22
  * bin/check-whois-domain-expiration-multi.rb
data/bin/check-banner.rb CHANGED
@@ -34,6 +34,7 @@
34
34
  # Released under the same terms as Sensu (the MIT license); see LICENSE
35
35
  # for details.
36
36
 
37
+ require 'openssl'
37
38
  require 'sensu-plugin/check/cli'
38
39
  require 'socket'
39
40
  require 'timeout'
@@ -101,9 +102,21 @@ class CheckBanner < Sensu::Plugin::Check::CLI
101
102
  long: '--critmessage MESSAGE',
102
103
  description: 'Custom critical message to send'
103
104
 
105
+ option :ssl,
106
+ short: '-S',
107
+ long: '--ssl',
108
+ description: 'Enable SSL socket for secure connection'
109
+
104
110
  def acquire_banner(host)
105
111
  Timeout.timeout(config[:timeout]) do
106
112
  sock = TCPSocket.new(host, config[:port])
113
+
114
+ if config[:ssl]
115
+ ssl_context = OpenSSL::SSL::SSLContext.new
116
+ sock = OpenSSL::SSL::SSLSocket.new(sock, ssl_context)
117
+ sock.connect
118
+ end
119
+
107
120
  if config[:write]
108
121
  sock.write config[:write]
109
122
  sock.write "\n" unless config[:exclude_newline]
@@ -1,6 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
  #
3
- # check-multicasr-groups
3
+ # check-multicast-groups
4
4
  #
5
5
  # DESCRIPTION:
6
6
  # This plugin checks if specific multicast groups are configured
@@ -51,7 +51,7 @@ class CheckMulticastGroups < Sensu::Plugin::Check::CLI
51
51
  def run
52
52
  targets = settings['check-multicast-groups'] ||= []
53
53
  extras = load_config(config[:config])['check-multicast-groups'] || []
54
- targets.deep_merge(extras)
54
+ targets = targets.concat(extras).uniq
55
55
 
56
56
  critical 'No target muticast groups are specified.' if targets.empty?
57
57
 
@@ -64,7 +64,7 @@ class CheckMulticastGroups < Sensu::Plugin::Check::CLI
64
64
  expected = Set.new(targets)
65
65
 
66
66
  diff = expected.difference(actual)
67
- if diff.size > 0 # rubocop:disable Style/ZeroLengthPredicate
67
+ unless diff.empty?
68
68
  diff_output = diff.map { |iface, addr| "#{iface}\t#{addr}" }.join("\n")
69
69
  critical "#{diff.size} missing multicast group(s):\n#{diff_output}"
70
70
  end
data/bin/check-ping.rb CHANGED
@@ -98,6 +98,10 @@ class CheckPING < Sensu::Plugin::Check::CLI
98
98
  failure_message = "ICMP ping unsuccessful for host: #{config[:host]} (successful: #{successful_count}/#{total_count})"
99
99
 
100
100
  if config[:report]
101
+ mtr = `mtr --help`
102
+ if mtr == 1
103
+ unknown 'mtr is not available in $PATH'
104
+ end
101
105
  report = `mtr --curses --report-cycles=1 --report --no-dns #{config[:host]}`
102
106
  failure_message = failure_message + "\n" + report
103
107
  end
@@ -0,0 +1,158 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # encoding: UTF-8
4
+ # check-ports-bind
5
+ #
6
+ # DESCRIPTION:
7
+ # Connect to a TCP/UDP address:port, to check whether open or closed.
8
+ # Don't use nmap since it's overkill.
9
+ # Test UDP ports as well: Experimental
10
+ #
11
+ # OUTPUT:
12
+ # plain text
13
+ #
14
+ # PLATFORMS:
15
+ # Linux
16
+ #
17
+ # DEPENDENCIES:
18
+ # gem: sensu-plugin
19
+ #
20
+ # USAGE:
21
+ #
22
+ # Ports are comma separated and support ranges
23
+ # ./check-ports.rb -p 127.0.0.1:22,46.20.205.10 --hard --warn
24
+ # ./check-ports.rb -p 127.0.0.1:22,46.20.205.10:80
25
+ # If you mention a port without the bind address then the default address is : 0.0.0.0
26
+ #
27
+ # NOTES:
28
+ # By default, checks for openssh on localhost port 22
29
+ #
30
+ #
31
+ # LICENSE:
32
+ # Adpated from check-ports.rb
33
+ # Magic Online - www.magic.fr - hanynowsky@gmail.com
34
+ # September 2016
35
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
36
+ # for details.
37
+
38
+ require 'sensu-plugin/check/cli'
39
+ require 'socket'
40
+ require 'timeout'
41
+
42
+ #
43
+ # Check Ports by bound address
44
+ #
45
+ class CheckPort < Sensu::Plugin::Check::CLI
46
+ option(
47
+ :hard,
48
+ short: '-d',
49
+ long: '--hard',
50
+ description: 'Check given ports on both, TCP & UDP',
51
+ boolean: true,
52
+ default: false
53
+
54
+ )
55
+ option(
56
+ :host,
57
+ short: '-H HOSTNAME',
58
+ long: '--hostname HOSTNAME',
59
+ description: 'default Host address bound to port',
60
+ default: '0.0.0.0'
61
+ )
62
+
63
+ option(
64
+ :portbinds,
65
+ short: '-p PORTS',
66
+ long: '--portbinds PORTS',
67
+ description: 'different address:port to check, comma separated (0.0.0.0:22,localhost:25,127.0.0.0.1:8100-8131,192.168.0.12:3030)',
68
+ default: '0.0.0.0:22'
69
+ )
70
+
71
+ option(
72
+ :timeout,
73
+ short: '-t SECS',
74
+ long: '--timeout SECS',
75
+ description: 'Connection timeout',
76
+ proc: proc(&:to_i),
77
+ default: 10
78
+ )
79
+
80
+ option(
81
+ :warn,
82
+ description: 'Alert level. warn(warning) instead of critical',
83
+ short: '-w',
84
+ long: '--warn',
85
+ default: false,
86
+ boolean: true
87
+ )
88
+
89
+ option(
90
+ :debug,
91
+ description: 'Print debug info',
92
+ short: '-D',
93
+ long: '--debug',
94
+ default: false,
95
+ boolean: true
96
+ )
97
+
98
+ # Severity switcher
99
+ def severity(warn, text)
100
+ if warn
101
+ warning text.to_s
102
+ else
103
+ critical text.to_s
104
+ end
105
+ end
106
+
107
+ # Check address:port
108
+ def check_port(portbind, okays)
109
+ address = portbind.split(':')[0]
110
+ port = portbind.split(':')[1]
111
+ Timeout.timeout(config[:timeout]) do
112
+ connection = TCPSocket.new(address, port.to_i)
113
+ p connection if config[:debug]
114
+ okays.push("TCP-#{portbind}")
115
+ end
116
+ if config[:hard]
117
+ Timeout.timeout(config[:timeout]) do
118
+ s = UDPSocket.new
119
+ s.connect(address, port.to_i)
120
+ s.close
121
+ okays.push("UDP-#{portbind}")
122
+ end
123
+ end
124
+ rescue Errno::ECONNREFUSED
125
+ severity(config[:warn], "Connection refused by #{portbind}")
126
+ rescue Timeout::Error
127
+ severity(config[:warn], "Connection or read timed out (#{portbind})")
128
+ rescue Errno::EHOSTUNREACH
129
+ severity(config[:warn], "Check failed to run: No route to host (#{portbind})")
130
+ rescue EOFError
131
+ severity(config[:warn], "Connection closed unexpectedly (#{portbind})")
132
+ end
133
+
134
+ def run
135
+ portbinds = config[:portbinds].split(',').flat_map do |port_bind|
136
+ port_bind = "#{config[:host]}:#{port_bind}" unless port_bind.include? ':'
137
+ # Port range
138
+ if port_bind.split(',')[1] =~ /^[0-9]+(-[0-9]+)$/
139
+ first_port, last_port = port_bind.split('-')
140
+ (first_port.to_i..last_port.to_i).to_a
141
+ # Single port
142
+ else
143
+ port_bind
144
+ end
145
+ end
146
+ array = []
147
+ portbinds.each do |port|
148
+ check_port(port, array)
149
+ end
150
+ multiplier = 1
151
+ multiplier = 2 if config[:hard] == true
152
+ if array.size == portbinds.size * multiplier
153
+ ok "All ports (#{config[:portbinds]}) are reachable - HARD: #{config[:hard]} => SUCCESS: #{array}"
154
+ else
155
+ severity(config[:warn], 'port count or pattern does not match')
156
+ end
157
+ end
158
+ end
@@ -44,17 +44,20 @@ class WhoisDomainExpirationCheck < Sensu::Plugin::Check::CLI
44
44
  short: '-w DAYS',
45
45
  long: '--warn DAYS',
46
46
  default: 30,
47
+ proc: proc(&:to_i),
47
48
  description: 'Warn if fewer than DAYS away'
48
49
 
49
50
  option :critical,
50
51
  short: '-c DAYS',
51
52
  long: '--critical DAYS',
53
+ proc: proc(&:to_i),
52
54
  default: 7,
53
55
  description: 'Critical if fewer than DAYS away'
54
56
 
55
57
  option :timeout,
56
58
  short: '-t SECONDS',
57
59
  long: '--timeout SECONDS',
60
+ proc: proc(&:to_i),
58
61
  default: 10,
59
62
  description: 'Timeout for whois lookup'
60
63
 
data/bin/metrics-netif.rb CHANGED
@@ -37,8 +37,22 @@ class NetIFMetrics < Sensu::Plugin::Metric::CLI::Graphite
37
37
  long: '--scheme SCHEME',
38
38
  default: Socket.gethostname.to_s
39
39
 
40
+ option :interval,
41
+ description: 'Interval to collect metrics over',
42
+ long: '--interval INTERVAL',
43
+ default: 1
44
+
45
+ option :average_key,
46
+ description: 'This key is used to `grep` for a key that corresponds to average. useful for different locales',
47
+ long: '--average-key',
48
+ default: 'Average'
49
+
40
50
  def run
41
- `sar -n DEV 1 1 | grep Average | grep -v IFACE`.each_line do |line|
51
+ sar = `sar -n DEV #{config[:interval]} 1 | grep #{config[:average_key]} | grep -v IFACE`
52
+ if sar.nil? || sar.empty?
53
+ unknown 'sar is not installed or in $PATH'
54
+ end
55
+ sar.each_line do |line|
42
56
  stats = line.split(/\s+/)
43
57
  unless stats.empty?
44
58
  stats.shift
@@ -76,6 +76,12 @@ class NetstatTCPMetrics < Sensu::Plugin::Metric::CLI::Graphite
76
76
  long: '--port PORT',
77
77
  proc: proc(&:to_i)
78
78
 
79
+ option :disabletcp6,
80
+ description: 'Disable tcp6 check',
81
+ short: '-d',
82
+ long: '--disabletcp6',
83
+ boolean: true
84
+
79
85
  def netstat(protocol, pattern, state_counts)
80
86
  File.open('/proc/net/' + protocol).each do |line|
81
87
  line.strip!
@@ -101,8 +107,10 @@ class NetstatTCPMetrics < Sensu::Plugin::Metric::CLI::Graphite
101
107
  tcp4_pattern = /^\s*\d+:\s+(.{8}):(.{4})\s+(.{8}):(.{4})\s+(.{2})/
102
108
  state_counts = netstat('tcp', tcp4_pattern, state_counts)
103
109
 
104
- tcp6_pattern = /^\s*\d+:\s+(.{32}):(.{4})\s+(.{32}):(.{4})\s+(.{2})/
105
- state_counts = netstat('tcp6', tcp6_pattern, state_counts)
110
+ unless config[:disabletcp6]
111
+ tcp6_pattern = /^\s*\d+:\s+(.{32}):(.{4})\s+(.{32}):(.{4})\s+(.{2})/
112
+ state_counts = netstat('tcp6', tcp6_pattern, state_counts)
113
+ end
106
114
 
107
115
  state_counts.each do |state, count|
108
116
  graphite_name = config[:port] ? "#{config[:scheme]}.#{config[:port]}.#{state}" :
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsNetworkChecks
2
2
  module Version
3
3
  MAJOR = 1
4
- MINOR = 1
4
+ MINOR = 2
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sensu-plugins-network-checks
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-07 00:00:00.000000000 Z
11
+ date: 2017-06-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dnsbl-client
@@ -70,16 +70,16 @@ dependencies:
70
70
  name: activesupport
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - '='
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: 4.2.5
75
+ version: '4.2'
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - '='
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: 4.2.5
82
+ version: '4.2'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: bundler
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -233,6 +233,7 @@ executables:
233
233
  - check-netfilter-conntrack.rb
234
234
  - check-netstat-tcp.rb
235
235
  - check-ping.rb
236
+ - check-ports-bind.rb
236
237
  - check-ports-nmap.rb
237
238
  - check-ports.rb
238
239
  - check-rbl.rb
@@ -259,6 +260,7 @@ files:
259
260
  - bin/check-netfilter-conntrack.sh
260
261
  - bin/check-netstat-tcp.rb
261
262
  - bin/check-ping.rb
263
+ - bin/check-ports-bind.rb
262
264
  - bin/check-ports-nmap.rb
263
265
  - bin/check-ports.rb
264
266
  - bin/check-rbl.rb
@@ -299,7 +301,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
299
301
  version: '0'
300
302
  requirements: []
301
303
  rubyforge_project:
302
- rubygems_version: 2.5.1
304
+ rubygems_version: 2.4.5
303
305
  signing_key:
304
306
  specification_version: 4
305
307
  summary: Sensu plugins for checking network hardware, connections, and data