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

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: 313887c517630cb3ea1af2696f2177fd1d1dacc8
4
- data.tar.gz: 711ccebf4a7a2487d5387a7f1d3e1e11728f678e
3
+ metadata.gz: c31954aa9beb56d49f07b256b97ecbaa26492ea9
4
+ data.tar.gz: 7ec124eb4454ec3e819bd0c6db035a581742c2a9
5
5
  SHA512:
6
- metadata.gz: a1320cfabd4bc8ffb4ce71bcffe7bd709a017dda7e56809577024c8e02a4dbf3350874c38015b9ed8a4bef84c2effaca6ee14c7b5188bc793a0ef21cd95a0bf3
7
- data.tar.gz: d05ed8213e49614af6e433a70436b4b895aedaff86cc6e8a873c60a024bc6658d0440444881575874133298cb924a128d6a3e81a56feb755f224969d27b123c5
6
+ metadata.gz: ef3375f158d9e621a5c2e6e5c612de524f1f312e6d93d4d8d92fe087a4fed61a252190f9fbd942d80ad0450f87b15321bf8d05687a936324f063eb6475851071
7
+ data.tar.gz: 058a106f3dbe594ba1ecce3e7870b54baa06ed6ad1c8e31a09250c143dea901e86d17e8cdaeeb48c9ab1cd6268edb7ad69273f5e93aad9050828e70516fcba9b
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -1,8 +1,12 @@
1
- #### 0.1.0-alpha.1
1
+ #### 0.0.1.alpha.1
2
2
 
3
3
  * initial release, same as community repo
4
4
 
5
- #### 0.1.0-alpha.2
5
+ #### 0.0.1.alpha.2
6
6
 
7
7
  * all tests pass
8
8
  * initial gem release
9
+
10
+ #### 0.0.1.alpha.3
11
+
12
+ * additional functionality to check-banner #6
@@ -1,11 +1,14 @@
1
1
  #! /usr/bin/env ruby
2
2
  #
3
+ # encoding: UTF-8
3
4
  # check-banner
4
5
  #
5
6
  # DESCRIPTION:
6
- # Connect to a TCP port, read one line, test it against a pattern.
7
- # Useful for SSH, ZooKeeper, etc.
8
-
7
+ # Connect to a TCP port on one or more hosts, read till a char (EOF, EOL, etc)
8
+ # and test output against a pattern.
9
+ #
10
+ # Useful for SSH, ZooKeeper, etc.
11
+ #
9
12
  # OUTPUT:
10
13
  # plain text
11
14
  #
@@ -18,14 +21,21 @@
18
21
  #
19
22
  # USAGE:
20
23
  #
24
+ # To check there is only one zk leader
25
+ # ./check-banner.rb -h 'zk01,z02,zk03' -p 2181 -q leader -c 1 -w mntr -r EOF -O "ZK has one leader"
26
+ # -C "ZK has zero or more than one leader"
27
+ #
21
28
  # NOTES:
29
+ # By default, checks for openssh on localhost port 22 and reads till EOL
30
+ #
22
31
  #
23
32
  # LICENSE:
24
33
  # Copyright 2012 Sonian, Inc <chefs@sonian.net>
34
+ # Modified by Raghu Udiyar <raghu@helpshift.com>
25
35
  # Released under the same terms as Sensu (the MIT license); see LICENSE
26
36
  # for details.
27
- #
28
37
 
38
+ require 'rubygems' if RUBY_VERSION < '1.9.0'
29
39
  require 'sensu-plugin/check/cli'
30
40
  require 'socket'
31
41
  require 'timeout'
@@ -34,10 +44,10 @@ require 'timeout'
34
44
  # Check Banner
35
45
  #
36
46
  class CheckBanner < Sensu::Plugin::Check::CLI
37
- option :host,
38
- short: '-H HOSTNAME',
39
- long: '--hostname HOSTNAME',
40
- description: 'Host to connect to',
47
+ option :hosts,
48
+ short: '-H HOSTNAME(S)',
49
+ long: '--hostnames HOSTNAME(S)',
50
+ description: 'Host(s) to connect to, comma seperated',
41
51
  default: 'localhost'
42
52
 
43
53
  option :port,
@@ -64,14 +74,42 @@ class CheckBanner < Sensu::Plugin::Check::CLI
64
74
  proc: proc(&:to_i),
65
75
  default: 30
66
76
 
67
- def acquire_banner # rubocop:disable all
77
+ option :count_match,
78
+ short: '-c NUMBER',
79
+ long: '--count NUMBER',
80
+ description: 'Number of successful matches, default(1)',
81
+ proc: proc(&:to_i),
82
+ default: 1
83
+
84
+ option :read_till,
85
+ short: '-r CHAR',
86
+ long: '--readtill CHAR',
87
+ description: 'Read till CHAR is reached',
88
+ default: "\n"
89
+
90
+ option :ok_message,
91
+ short: '-O MESSAGE',
92
+ long: '--okmessage MESSAGE',
93
+ description: 'Custom ok message to send'
94
+
95
+ option :crit_message,
96
+ short: '-C MESSAGE',
97
+ long: '--critmessage MESSAGE',
98
+ description: 'Custom critical message to send'
99
+
100
+ def acquire_banner(host) # rubocop:disable all
68
101
  timeout(config[:timeout]) do
69
- sock = TCPSocket.new(config[:host], config[:port])
102
+ sock = TCPSocket.new(host, config[:port])
70
103
  sock.puts config[:write] if config[:write]
71
- sock.readline
104
+ if config[:read_till] == 'EOF'
105
+ banner = sock.gets(nil)
106
+ else
107
+ banner = sock.gets(config[:read_till])
108
+ end
109
+ return banner
72
110
  end
73
111
  rescue Errno::ECONNREFUSED
74
- critical "Connection refused by #{config[:host]}:#{config[:port]}"
112
+ critical "Connection refused by #{host}:#{config[:port]}"
75
113
  rescue Timeout::Error
76
114
  critical 'Connection or read timed out'
77
115
  rescue Errno::EHOSTUNREACH
@@ -81,8 +119,18 @@ class CheckBanner < Sensu::Plugin::Check::CLI
81
119
  end
82
120
 
83
121
  def run
84
- banner = acquire_banner
85
- message banner
86
- banner =~ /#{config[:pattern]}/ ? ok : warning
122
+ hosts = config[:hosts].split(',')
123
+ okarray = []
124
+ hosts.each do |host|
125
+ banner = acquire_banner host
126
+ okarray << 'ok' if banner =~ /#{config[:pattern]}/
127
+ end
128
+ if okarray.size == config[:count_match]
129
+ ok "pattern #{config[:pattern]} matched" unless config[:ok_message]
130
+ ok config[:ok_message]
131
+ else
132
+ critical "pattern #{config[:pattern]} does not match" unless config[:crit_message]
133
+ critical config[:crit_message]
134
+ end
87
135
  end
88
136
  end
@@ -3,5 +3,5 @@
3
3
  #
4
4
  module SensuPluginsNetworkChecks
5
5
  # Gem version
6
- VERSION = '0.0.1.alpha.2'
6
+ VERSION = '0.0.1.alpha.3'
7
7
  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.1.alpha.2
4
+ version: 0.0.1.alpha.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yieldbot, Inc. 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-03-19 00:00:00.000000000 Z
33
+ date: 2015-03-20 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: sensu-plugin
metadata.gz.sig CHANGED
Binary file