sensu-plugins-network-checks 0.0.1.alpha.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 313887c517630cb3ea1af2696f2177fd1d1dacc8
4
+ data.tar.gz: 711ccebf4a7a2487d5387a7f1d3e1e11728f678e
5
+ SHA512:
6
+ metadata.gz: a1320cfabd4bc8ffb4ce71bcffe7bd709a017dda7e56809577024c8e02a4dbf3350874c38015b9ed8a4bef84c2effaca6ee14c7b5188bc793a0ef21cd95a0bf3
7
+ data.tar.gz: d05ed8213e49614af6e433a70436b4b895aedaff86cc6e8a873c60a024bc6658d0440444881575874133298cb924a128d6a3e81a56feb755f224969d27b123c5
@@ -0,0 +1 @@
1
+ Q���ч8Q�7��<�іR?����e�P�~qz mv��Ī�<W�7Y!sz
@@ -0,0 +1,2 @@
1
+ MF)���M�t|],�9f��� �`����@;�Mϋ"�ؘ}��x�4�ʵ)�2ެ#���3M6W����H��P��7���ͨ?Te:čC�լA�0d�#�e3��:>����nu�����R�1o�H��� P�ڙS
2
+ ]Lo��*�����~�)^ت� 1Gy�
@@ -0,0 +1,8 @@
1
+ #### 0.1.0-alpha.1
2
+
3
+ * initial release, same as community repo
4
+
5
+ #### 0.1.0-alpha.2
6
+
7
+ * all tests pass
8
+ * initial gem release
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 devops@yieldbot.com
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,71 @@
1
+
2
+ [![Build Status](https://travis-ci.org/sensu-plugins/sensu-plugins-network-checks.svg?branch=master)](https://travis-ci.org/sensu-plugins/sensu-plugins-network-checks)
3
+ [![Gem Version](https://badge.fury.io/rb/sensu-plugins-network-checks.svg)](http://badge.fury.io/rb/sensu-plugins-network-checks)
4
+ [![Code Climate](https://codeclimate.com/github/sensu-plugins/sensu-plugins-network-checks/badges/gpa.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-network-checks)
5
+ [![Test Coverage](https://codeclimate.com/github/sensu-plugins/sensu-plugins-network-checks/badges/coverage.svg)](https://codeclimate.com/github/sensu-plugins/sensu-plugins-network-checks)
6
+ [![Dependency Status](https://gemnasium.com/sensu-plugins/sensu-plugins-network-checks.svg)](https://gemnasium.com/sensu-plugins/sensu-plugins-network-checks)
7
+
8
+ ## Functionality
9
+
10
+ ## Files
11
+ * bin/check-banner
12
+ * bin/check-multicast-groups
13
+ * bin/check-netstat-tcp
14
+ * bin/check-ping
15
+ * bin/check-ports
16
+ * bin/check-rbl
17
+ * bin/metrics-interface
18
+ * bin/metrics-net
19
+ * bin/metrics-netif
20
+ * bin/metrics-netstat-tcp
21
+
22
+ ## Usage
23
+
24
+ **check-multicast-groups**
25
+ ```
26
+ {
27
+ "check-multicast-groups": [
28
+ ["eth0", "224.2.2.4"]
29
+ ]
30
+ }
31
+ ```
32
+ ## Installation
33
+
34
+ Add the public key (if you haven’t already) as a trusted certificate
35
+
36
+ ```
37
+ gem cert --add <(curl -Ls https://raw.githubusercontent.com/sensu-plugins/sensu-plugins.github.io/master/certs/sensu-plugins.pem)
38
+ gem install sensu-plugins-network-checks -P MediumSecurity
39
+ ```
40
+
41
+ You can also download the key from /certs/ within each repository.
42
+
43
+ #### Rubygems
44
+
45
+ `gem install sensu-plugins-network`
46
+
47
+ #### Bundler
48
+
49
+ Add *sensu-plugins-network* to your Gemfile and run `bundle install` or `bundle update`
50
+
51
+ `gem install sensu-plugins-network-checks`
52
+
53
+ #### Chef
54
+
55
+ Using the Sensu **sensu_gem** LWRP
56
+ ```
57
+ sensu_gem 'sensu-plugins-network-checks' do
58
+ options('--prerelease')
59
+ version '0.0.1.alpha.2'
60
+ end
61
+ ```
62
+
63
+ Using the Chef **gem_package** resource
64
+ ```
65
+ gem_package 'sensu-plugins-network-checks' do
66
+ options('--prerelease')
67
+ version '0.0.1.alpha.2'
68
+ end
69
+ ```
70
+
71
+ ## Notes
@@ -0,0 +1,88 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-banner
4
+ #
5
+ # DESCRIPTION:
6
+ # Connect to a TCP port, read one line, test it against a pattern.
7
+ # Useful for SSH, ZooKeeper, etc.
8
+
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Linux
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ # gem: timeout
18
+ #
19
+ # USAGE:
20
+ #
21
+ # NOTES:
22
+ #
23
+ # LICENSE:
24
+ # Copyright 2012 Sonian, Inc <chefs@sonian.net>
25
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
26
+ # for details.
27
+ #
28
+
29
+ require 'sensu-plugin/check/cli'
30
+ require 'socket'
31
+ require 'timeout'
32
+
33
+ #
34
+ # Check Banner
35
+ #
36
+ class CheckBanner < Sensu::Plugin::Check::CLI
37
+ option :host,
38
+ short: '-H HOSTNAME',
39
+ long: '--hostname HOSTNAME',
40
+ description: 'Host to connect to',
41
+ default: 'localhost'
42
+
43
+ option :port,
44
+ short: '-p PORT',
45
+ long: '--port PORT',
46
+ proc: proc(&:to_i),
47
+ default: 22
48
+
49
+ option :write,
50
+ short: '-w STRING',
51
+ long: '--write STRING',
52
+ description: 'write STRING to the socket'
53
+
54
+ option :pattern,
55
+ short: '-q PAT',
56
+ long: '--pattern PAT',
57
+ description: 'Pattern to search for',
58
+ default: 'OpenSSH'
59
+
60
+ option :timeout,
61
+ short: '-t SECS',
62
+ long: '--timeout SECS',
63
+ description: 'Connection timeout',
64
+ proc: proc(&:to_i),
65
+ default: 30
66
+
67
+ def acquire_banner # rubocop:disable all
68
+ timeout(config[:timeout]) do
69
+ sock = TCPSocket.new(config[:host], config[:port])
70
+ sock.puts config[:write] if config[:write]
71
+ sock.readline
72
+ end
73
+ rescue Errno::ECONNREFUSED
74
+ critical "Connection refused by #{config[:host]}:#{config[:port]}"
75
+ rescue Timeout::Error
76
+ critical 'Connection or read timed out'
77
+ rescue Errno::EHOSTUNREACH
78
+ critical 'Check failed to run: No route to host'
79
+ rescue EOFError
80
+ critical 'Connection closed unexpectedly'
81
+ end
82
+
83
+ def run
84
+ banner = acquire_banner
85
+ message banner
86
+ banner =~ /#{config[:pattern]}/ ? ok : warning
87
+ end
88
+ end
@@ -0,0 +1,77 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-multicasr-groups
4
+ #
5
+ # DESCRIPTION:
6
+ # This plugin checks if specific multicast groups are configured
7
+ # on specific interfaces. The netstat command is required.
8
+ #
9
+ # The configurations can be put in the default sensu config directory
10
+ # and/or out of the sensu directory, as a JSON file. If the config file
11
+ # is not in the sensu directry, -c PATH option must be given.
12
+ #
13
+ # OUTPUT:
14
+ # plain text
15
+ #
16
+ # PLATFORMS:
17
+ # Linux
18
+ #
19
+ # DEPENDENCIES:
20
+ # gem: sensu-plugin
21
+ # gem: json
22
+ # gem: set
23
+ #
24
+ # USAGE:
25
+ # example commands
26
+ #
27
+ # NOTES:
28
+ # Does it behave differently on specific platforms, specific use cases, etc
29
+ #
30
+ # LICENSE:
31
+ # Copyright 2014 Mitsutoshi Aoe <maoe@foldr.in>
32
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
33
+ # for details.
34
+ #
35
+
36
+ require 'json'
37
+ require 'sensu-plugin/check/cli'
38
+ require 'sensu-plugin/utils'
39
+ require 'set'
40
+
41
+ #
42
+ # Check Multicast Groups
43
+ #
44
+ class CheckMulticastGroups < Sensu::Plugin::Check::CLI
45
+ include Sensu::Plugin::Utils
46
+
47
+ option :config,
48
+ short: '-c PATH',
49
+ long: '--config PATH',
50
+ required: true,
51
+ description: 'Path to a config file'
52
+
53
+ def run # rubocop:disable all
54
+ targets = settings['check-multicast-groups'] ||= []
55
+ extras = load_config(config[:config])['check-multicast-groups'] || []
56
+ targets.deep_merge(extras)
57
+
58
+ critical 'No target muticast groups are specified.' if targets.empty?
59
+
60
+ iface_pat = /[a-zA-Z0-9\.]+/
61
+ refcount_pat = /\d+/
62
+ group_pat = /[a-f0-9\.:]+/ # assumes that -n is given
63
+ pattern = /(#{iface_pat})\s+#{refcount_pat}\s+(#{group_pat})/
64
+
65
+ actual = Set.new(`netstat -ng`.scan(pattern))
66
+ expected = Set.new(targets)
67
+
68
+ diff = expected.difference(actual)
69
+ if diff.size > 0
70
+ diff_output = diff.map { |iface, addr| "#{iface}\t#{addr}" }.join("\n")
71
+ critical "#{diff.size} missing multicast group(s):\n#{diff_output}"
72
+ end
73
+ ok
74
+ rescue => ex
75
+ critical "Failed to check multicast groups: #{ex}"
76
+ end
77
+ end
@@ -0,0 +1,128 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-netstat-tcp
4
+ #
5
+ # DESCRIPTION:
6
+ # Alert based on thresholds of discrete TCP socket states reported by netstat
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: <?>
17
+ #
18
+ # USAGE:
19
+ # $ ./check-netstat-tcp.rb --states ESTABLISHED,CLOSE_WAIT --warning 10,3 --critical 100,30
20
+ #
21
+ # NOTES:
22
+ # - Thanks to metric-netstat-tcp.rb!
23
+ # https://github.com/sensu/sensu-community-plugins
24
+ # - Code for parsing Linux /proc/net/tcp from Anthony Goddard's ruby-netstat:
25
+ # https://github.com/agoddard/ruby-netstat
26
+ #
27
+ # LICENSE:
28
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
29
+ # for details.
30
+ #
31
+
32
+ require 'sensu-plugin/check/cli'
33
+ require 'socket'
34
+
35
+ TCP_STATES = {
36
+ '00' => 'UNKNOWN', # Bad state ... Impossible to achieve ...
37
+ 'FF' => 'UNKNOWN', # Bad state ... Impossible to achieve ...
38
+ '01' => 'ESTABLISHED',
39
+ '02' => 'SYN_SENT',
40
+ '03' => 'SYN_RECV',
41
+ '04' => 'FIN_WAIT1',
42
+ '05' => 'FIN_WAIT2',
43
+ '06' => 'TIME_WAIT',
44
+ '07' => 'CLOSE',
45
+ '08' => 'CLOSE_WAIT',
46
+ '09' => 'LAST_ACK',
47
+ '0A' => 'LISTEN',
48
+ '0B' => 'CLOSING'
49
+ }
50
+
51
+ #
52
+ # Check Netstat TCP
53
+ #
54
+ class CheckNetstatTCP < Sensu::Plugin::Check::CLI
55
+ option :states,
56
+ description: 'Comma delimited list of states to check',
57
+ short: '-s STATES',
58
+ long: '--states STATES',
59
+ default: ['ESTABLISHED'],
60
+ proc: proc { |a| a.split(',') }
61
+
62
+ option :critical,
63
+ description: "Comma delimited list of state values to set critical at (order follows 'states')",
64
+ short: '-c CRITICAL',
65
+ long: '--critical CRITICAL',
66
+ default: [1000],
67
+ proc: proc { |a| a.split(',').map(&:to_i) }
68
+
69
+ option :warning,
70
+ description: "Comma delimited list of state values to set warning at (order follows 'states')",
71
+ short: '-w WARNING',
72
+ long: '--warning WARNING',
73
+ default: [500],
74
+ proc: proc { |a| a.split(',').map(&:to_i) }
75
+
76
+ option :port,
77
+ description: 'Port you wish to check values on (default: all)',
78
+ short: '-p PORT',
79
+ long: '--port PORT',
80
+ proc: proc(&:to_i)
81
+
82
+ def netstat(protocols = ['tcp']) # rubocop:disable all
83
+ state_counts = Hash.new(0)
84
+ TCP_STATES.each_pair { |_hex, name| state_counts[name] = 0 }
85
+
86
+ protocols.select { |p| File.exist?('/proc/net/' + p) }.each do |protocol|
87
+ # #YELLOW
88
+ File.open('/proc/net/' + protocol).each do |line| # rubocop:disable Style/Next
89
+ line.strip!
90
+ if m = line.match(/^\s*\d+:\s+(.{8}|.{32}):(.{4})\s+(.{8}|.{32}):(.{4})\s+(.{2})/) # rubocop:disable AssignmentInCondition
91
+ connection_state = m[5]
92
+ connection_port = m[2].to_i(16)
93
+ connection_state = TCP_STATES[connection_state]
94
+ next unless config[:states].include?(connection_state)
95
+ if config[:port] && config[:port] == connection_port
96
+ state_counts[connection_state] += 1
97
+ elsif !config[:port]
98
+ state_counts[connection_state] += 1
99
+ end
100
+ end
101
+ end
102
+ end
103
+ state_counts
104
+ end
105
+
106
+ def run # rubocop:disable all
107
+ state_counts = netstat(%w(tcp tcp6))
108
+ is_critical = false
109
+ is_warning = false
110
+ message = ''
111
+
112
+ config[:states].each_index do |i|
113
+ if state_counts[config[:states][i]] >= config[:critical][i]
114
+ is_critical = true
115
+ message += " CRITICAL:#{config[:states][i]}=#{state_counts[config[:states][i]]}"
116
+ elsif state_counts[config[:states][i]] >= config[:warning][i]
117
+ is_warning = true
118
+ message += " WARNING:#{config[:states][i]}=#{state_counts[config[:states][i]]}"
119
+ else
120
+ message += " OK:#{config[:states][i]}=#{state_counts[config[:states][i]]}"
121
+ end
122
+ end
123
+
124
+ critical message if is_critical
125
+ warning message if is_warning
126
+ ok message
127
+ end
128
+ end
@@ -0,0 +1,105 @@
1
+ #! /usr/bin/env ruby
2
+ #
3
+ # check-ping
4
+ #
5
+ # DESCRIPTION:
6
+ # This is a simple Ping check script for Sensu.
7
+ #
8
+ # OUTPUT:
9
+ # plain text
10
+ #
11
+ # PLATFORMS:
12
+ # Linux
13
+ #
14
+ # DEPENDENCIES:
15
+ # gem: sensu-plugin
16
+ # gem: net-ping
17
+ #
18
+ # USAGE:
19
+ # check-ping -h host -T timeout [--report]
20
+ #
21
+ # NOTES:
22
+ #
23
+ # LICENSE:
24
+ # Deepak Mohan Dass <deepakmdass88@gmail.com>
25
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
26
+ # for details.
27
+ #
28
+
29
+ require 'sensu-plugin/check/cli'
30
+ require 'net/ping'
31
+
32
+ #
33
+ # Check Ping
34
+ #
35
+ class CheckPING < Sensu::Plugin::Check::CLI
36
+ option :host,
37
+ short: '-h host',
38
+ default: 'localhost'
39
+
40
+ option :timeout,
41
+ short: '-T timeout',
42
+ proc: proc(&:to_i),
43
+ default: 5
44
+
45
+ option :count,
46
+ short: '-c count',
47
+ description: 'The number of ping requests',
48
+ proc: proc(&:to_i),
49
+ default: 1
50
+
51
+ option :interval,
52
+ short: '-i interval',
53
+ description: 'The number of seconds to wait between ping requests',
54
+ proc: proc(&:to_f),
55
+ default: 1
56
+
57
+ option :warn_ratio,
58
+ short: '-W ratio',
59
+ description: 'Warn if successful ratio is under this value',
60
+ proc: proc(&:to_f),
61
+ default: 0.5
62
+
63
+ option :critical_ratio,
64
+ short: '-C ratio',
65
+ description: 'Critical if successful ratio is under this value',
66
+ proc: proc(&:to_f),
67
+ default: 0.2
68
+
69
+ option :report,
70
+ short: '-r',
71
+ long: '--report',
72
+ description: 'Attach MTR report if ping is failed',
73
+ default: false
74
+
75
+ def run # rubocop:disable all
76
+ result = []
77
+ pt = Net::Ping::External.new(config[:host], nil, config[:timeout])
78
+ config[:count].times do |i|
79
+ sleep(config[:interval]) unless i == 0
80
+ result[i] = pt.ping?
81
+ end
82
+
83
+ successful_count = result.count(true)
84
+ total_count = config[:count]
85
+ success_ratio = successful_count / total_count.to_f
86
+
87
+ if success_ratio > config[:warn_ratio]
88
+ success_message = "ICMP ping successful for host: #{config[:host]}"
89
+ ok success_message
90
+ else
91
+ failure_message = "ICMP ping unsuccessful for host: #{config[:host]} (successful: #{successful_count}/#{total_count})"
92
+
93
+ if config[:report]
94
+ report = `mtr --curses --report-cycles=1 --report --no-dns #{config[:host]}`
95
+ failure_message = failure_message + "\n" + report
96
+ end
97
+
98
+ if success_ratio <= config[:critical_ratio]
99
+ critical failure_message
100
+ else
101
+ warning failure_message
102
+ end
103
+ end
104
+ end
105
+ end