sensu-plugins-network-checks 2.2.0 → 2.3.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
  SHA256:
3
- metadata.gz: e4fe3ce670028be6e730e1dc630814320751dc37f3a463afe18c6dfe44c98bfc
4
- data.tar.gz: 71e2789dd43b014154cc55e3e39dec64e1d4b90f208823fd2607fd6af41ff35b
3
+ metadata.gz: 6b9838fcbdec2087aba8d8fb8de4b7dc319d7e529cda950b9143ed6e3410f770
4
+ data.tar.gz: dfee7221ae2a11f4525b9c4afa97da7b375b9a031a19bdf9514b924867844d13
5
5
  SHA512:
6
- metadata.gz: ccb6b577dd63fb7ed02813bf5059612ec5a7605eab3ec8a0e8a6e5fd640214e177a86a9910585d9045f7d423294f6fe4dd25e0e656192726405cc0c6d6e2e3c0
7
- data.tar.gz: d7436091135499b7561d3f71ce03f4de8078a320ccd062d86be0f37e76368ec9ae82d64528ea5d7bf62346cf3ea877849c1deceda06edc4a9b592ed920d60dee
6
+ metadata.gz: 629163838de440d93eb3b21dab0976fdbeae3d6aac460b32f7d9a1157f45049595703d5b4462b4232e10ed50facaed260a73597af3eb3950952b8325ab46068f
7
+ data.tar.gz: e769e77553edd10d09bd1ff8c56db4c43fb2a6451ebc9614cb5e2c71c0ed53d4f1233701fe5993ff9a7b6e5104015df89b64cb835138b032cb33f9a0b866f411
@@ -5,6 +5,10 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugin
5
5
 
6
6
  ## [Unreleased]
7
7
 
8
+ ## [2.3.0] - 2018-02-09
9
+ ### Changed
10
+ - check-whois-domain-expiration.rb, check-whois-domain-expiration-multi.rb and check-jsonwhois-domain-expiration.rb: better resilience against errors, better reporting of erroneous responses (@DrMurx)
11
+
8
12
  ## [2.2.0] - 2018-02-02
9
13
  ### Added
10
14
  - check-ports.rb: support for multiple hosts (@DDSloan96)
@@ -194,7 +198,8 @@ This CHANGELOG follows the format listed [here](https://github.com/sensu-plugin
194
198
 
195
199
  * initial release, same as community repo
196
200
 
197
- [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/2.2.0...HEAD
201
+ [Unreleased]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/2.3.0...HEAD
202
+ [2.3.0]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/2.2.0...2.3.0
198
203
  [2.2.0]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/2.1.1...2.2.0
199
204
  [2.1.1]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/2.1.0...2.1.1
200
205
  [2.1.0]: https://github.com/sensu-plugins/sensu-plugins-network-checks/compare/2.0.1...2.1.0
@@ -61,6 +61,21 @@ class JSONWhoisDomainExpirationCheck < Sensu::Plugin::Check::CLI
61
61
  default: 7,
62
62
  description: 'Critical if a domain expires in fewer than DAYS days'
63
63
 
64
+ option :'ignore-errors',
65
+ short: '-i',
66
+ long: '--ignore-errors',
67
+ boolean: true,
68
+ default: false,
69
+ description: 'Ignore connection or parsing errors'
70
+
71
+ option :'report-errors',
72
+ short: '-r LEVEL',
73
+ long: '--report-errors LEVEL',
74
+ proc: proc(&:to_sym),
75
+ in: %i(unknown warning critical),
76
+ default: :unknown,
77
+ description: 'Level for reporting connection or parsing errors'
78
+
64
79
  option :help,
65
80
  short: '-h',
66
81
  long: '--help',
@@ -77,19 +92,26 @@ class JSONWhoisDomainExpirationCheck < Sensu::Plugin::Check::CLI
77
92
  domains = config[:domain].split(',')
78
93
  warning_days = config[:warning].to_i
79
94
  critical_days = config[:critical].to_i
80
- results = {}
81
- results['critical'] = {}
82
- results['warning'] = {}
83
- results['ok'] = {}
95
+ results = {
96
+ critical: {},
97
+ warning: {},
98
+ ok: {},
99
+ unknown: {}
100
+ }
84
101
 
85
102
  domains.each do |domain|
86
- domain_result = (get_domain_expiration(domain) - DateTime.now).to_i
87
- if domain_result <= critical_days
88
- results['critical'][domain] = domain_result
89
- elsif domain_result <= warning_days
90
- results['warning'][domain] = domain_result
91
- else
92
- results['ok'] = domain_result
103
+ begin
104
+ expires_on = get_domain_expiration(domain)
105
+ domain_result = (expires_on - DateTime.now).to_i
106
+ if domain_result <= critical_days
107
+ results[:critical][domain] = domain_result
108
+ elsif domain_result <= warning_days
109
+ results[:warning][domain] = domain_result
110
+ else
111
+ results[:ok][domain] = domain_result
112
+ end
113
+ rescue
114
+ results[:unknown][domain] = 'Connection or parsing error' unless config[:'ignore-errors']
93
115
  end
94
116
  end
95
117
  results
@@ -109,15 +131,23 @@ class JSONWhoisDomainExpirationCheck < Sensu::Plugin::Check::CLI
109
131
  http.request(req)
110
132
  end
111
133
 
112
- DateTime.parse(JSON.parse(res.body)['expires_on'])
134
+ json = JSON.parse(res.body)
135
+ DateTime.parse(json['expires_on'])
113
136
  end
114
137
 
115
138
  def run
116
- status = expiration_results
117
- if !status['critical'].empty?
118
- critical status['critical'].map { |u, v| "#{u} days left:#{v}" }.join(',')
119
- elsif !status['warning'].empty?
120
- warning status['warning'].map { |u, v| "#{u} days left:#{v}" }.join(',')
139
+ results = expiration_results
140
+
141
+ warn_results = results[:critical].merge(results[:warning]).map { |u, v| "#{u} (#{v} days left)" }
142
+ unknown_results = results[:unknown].map { |u, v| "#{u} (#{v})" }
143
+ message warn_results.concat(unknown_results).join(', ')
144
+
145
+ if !results[:critical].empty? || (!results[:unknown].empty? && config[:'report-errors'] == :critical)
146
+ critical
147
+ elsif !results[:warning].empty? || (!results[:unknown].empty? && config[:'report-errors'] == :warning)
148
+ warning
149
+ elsif !results[:unknown].empty?
150
+ unknown
121
151
  else
122
152
  ok 'No domains expire in the near term'
123
153
  end
@@ -55,6 +55,21 @@ class WhoisDomainExpirationCheck < Sensu::Plugin::Check::CLI
55
55
  default: 7,
56
56
  description: 'Critical if fewer than DAYS away'
57
57
 
58
+ option :'ignore-errors',
59
+ short: '-i',
60
+ long: '--ignore-errors',
61
+ boolean: true,
62
+ default: false,
63
+ description: 'Ignore connection or parsing errors'
64
+
65
+ option :'report-errors',
66
+ short: '-r LEVEL',
67
+ long: '--report-errors LEVEL',
68
+ proc: proc(&:to_sym),
69
+ in: %i(unknown warning critical),
70
+ default: :unknown,
71
+ description: 'Level for reporting connection or parsing errors'
72
+
58
73
  option :timeout,
59
74
  short: '-t SECONDS',
60
75
  long: '--timeout SECONDS',
@@ -77,44 +92,60 @@ class WhoisDomainExpirationCheck < Sensu::Plugin::Check::CLI
77
92
  domains = config[:domain].split(',')
78
93
  warning_days = config[:warning].to_i
79
94
  critical_days = config[:critical].to_i
80
- results = {}
81
- results['critical'] = {}
82
- results['warning'] = {}
83
- results['ok'] = {}
84
95
  max_retries = 4
85
96
 
97
+ results = {
98
+ critical: {},
99
+ warning: {},
100
+ ok: {},
101
+ unknown: {}
102
+ }
103
+ whois = Whois::Client.new(timeout: config[:timeout])
104
+
86
105
  domains.each do |domain|
87
- whois = Whois::Client.new(timeout: config[:timeout])
88
106
  begin
89
107
  tries ||= 0
90
108
  whois_result = whois.lookup(domain).parser
91
109
  rescue Timeout::Error, Errno::ECONNRESET, Whois::ConnectionError
92
110
  tries += 1
93
- tries < max_retries ? retry : next
111
+ if tries < max_retries
112
+ retry
113
+ else
114
+ results[:unknown][domain] = 'Connection error' unless config[:'ignore-errors']
115
+ next
116
+ end
94
117
  end
95
118
 
96
- if whois_result.expires_on.nil?
97
- results['critical'][domain] = domain_result
98
- else
99
- domain_result = (DateTime.parse(whois_result.expires_on.to_s) - DateTime.now).to_i
119
+ begin
120
+ expires_on = DateTime.parse(whois_result.expires_on.to_s)
121
+ domain_result = (expires_on - DateTime.now).to_i
100
122
  if domain_result <= critical_days
101
- results['critical'][domain] = domain_result
123
+ results[:critical][domain] = domain_result
102
124
  elsif domain_result <= warning_days
103
- results['warning'][domain] = domain_result
125
+ results[:warning][domain] = domain_result
104
126
  else
105
- results['ok'] = domain_result
127
+ results[:ok][domain] = domain_result
106
128
  end
129
+ rescue
130
+ results[:unknown][domain] = 'Parsing error' unless config[:'ignore-errors']
107
131
  end
108
132
  end
109
133
  results
110
134
  end
111
135
 
112
136
  def run
113
- status = expiration_results
114
- if !status['critical'].empty?
115
- critical status['critical'].map { |u, v| "#{u} days left:#{v}" }.join(',')
116
- elsif !status['warning'].empty?
117
- warning status['warning'].map { |u, v| "#{u} days left:#{v}" }.join(',')
137
+ results = expiration_results
138
+
139
+ warn_results = results[:critical].merge(results[:warning]).map { |u, v| "#{u} (#{v} days left)" }
140
+ unknown_results = results[:unknown].map { |u, v| "#{u} (#{v})" }
141
+ message warn_results.concat(unknown_results).join(', ')
142
+
143
+ if !results[:critical].empty? || (!results[:unknown].empty? && config[:'report-errors'] == :critical)
144
+ critical
145
+ elsif !results[:warning].empty? || (!results[:unknown].empty? && config[:'report-errors'] == :warning)
146
+ warning
147
+ elsif !results[:unknown].empty?
148
+ unknown
118
149
  else
119
150
  ok 'No domains expire in the near term'
120
151
  end
@@ -60,27 +60,22 @@ class WhoisDomainExpirationCheck < Sensu::Plugin::Check::CLI
60
60
  show_options: true,
61
61
  exit: 0
62
62
 
63
- def check_days(num_days,
64
- warning_days = config[:warning].to_i,
65
- critical_days = config[:critical].to_i)
66
- if num_days <= critical_days
63
+ def run
64
+ whois = Whois.whois(config[:domain])
65
+
66
+ expires_on = DateTime.parse(whois.parser.expires_on.to_s)
67
+ num_days = (expires_on - DateTime.now).to_i
68
+
69
+ message "#{config[:domain]} expires on #{expires_on.strftime('%m-%d-%Y')} (#{num_days} days away)"
70
+
71
+ if num_days <= config[:warning].to_i
67
72
  critical
68
- elsif num_days <= warning_days
73
+ elsif num_days <= config[:critical].to_i
69
74
  warning
70
75
  else
71
76
  ok
72
77
  end
73
- end
74
-
75
- def initialize
76
- super()
77
- whois = Whois.whois(config[:domain])
78
- @expires_on = DateTime.parse(whois.parser.expires_on.to_s)
79
- @num_days = (@expires_on - DateTime.now).to_i
80
- end
81
-
82
- def run
83
- message "#{config[:domain]} expires on #{@expires_on.strftime('%m-%d-%Y')} (#{@num_days} days away)"
84
- check_days @num_days
78
+ rescue
79
+ unknown "#{config[:domain]} can't be checked"
85
80
  end
86
81
  end
@@ -1,7 +1,7 @@
1
1
  module SensuPluginsNetworkChecks
2
2
  module Version
3
3
  MAJOR = 2
4
- MINOR = 2
4
+ MINOR = 3
5
5
  PATCH = 0
6
6
 
7
7
  VER_STRING = [MAJOR, MINOR, PATCH].compact.join('.')
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: 2.2.0
4
+ version: 2.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sensu-Plugins and contributors