sensu-plugins-network-checks 0.0.6 → 0.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b91c2cab0f43f5200c2dc825c026040771355009
4
- data.tar.gz: 48c3b6298d8d6b8771e9580e2cc120692cd236d3
3
+ metadata.gz: d466f531d029bcc1c59483501fa2cf0bd84c383f
4
+ data.tar.gz: 385c7db0b4ba4988c57e356bfcce850d52573c8a
5
5
  SHA512:
6
- metadata.gz: 629b7ed21e7ee2f22f852ae5f6f0724fbf21e576238b9e53f8cb4aafbc40784eed7f9dfd6d42053af73d6e78cc40b8550ff56cb763e182ebb483dabb7db0da17
7
- data.tar.gz: ba7c01d145a66fad0ed4aa3d9a7efc538a2a19974afd6e8d52a3009b9f460964047593050bc1aae8a5023f1462a5afb7a825627f0b04f3d7942449ec3026961e
6
+ metadata.gz: 06bce8b5c8d82f66010452aeaa87a69efcfb16cfe992739561beb29695abeaf787fb7b7f51783f5eecfb64528c6f32f2fa1340948d37241e1b40deeaf25b8ad4
7
+ data.tar.gz: b149379e5f451c513c7cedf9ff7df8105d7952684efc7dbdbecd7706e35ce9f27f9023e6831b5eed20477451353cd0f281e9afc98887e3c3fda8a4c46a24aaea
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
data/CHANGELOG.md CHANGED
@@ -4,6 +4,11 @@ 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][unreleased]
7
+ - nothing
8
+
9
+ ## [0.0.7] - 2015-10-27
10
+ ### Added
11
+ - Added `check-jsonwhois-domain-expiration.rb` plugin which uses the API at https://jsonwhois.com to check domain expiry.
7
12
 
8
13
  ## [0.0.6] - 2015-10-01
9
14
  ### Added
@@ -38,6 +43,10 @@ This CHANGELOG follows the format listed at [Keep A Changelog](http://keepachang
38
43
  - renamed check-ports.rb to check-ports-nmap.rb
39
44
  - added check-ports.rb based in TCPSocket instead of nmap
40
45
 
46
+ ### Refactored
47
+ - renamed check-ports.rb to check-ports-nmap.rb
48
+ - added check-ports.rb based in TCPSocket instead of nmap
49
+
41
50
  ## [0.0.2] - 2015-06-03
42
51
 
43
52
  ### Fixed
data/README.md CHANGED
@@ -10,6 +10,7 @@
10
10
 
11
11
  ## Files
12
12
  * bin/check-banner.rb
13
+ * bin/check-jsonwhois-domain-expiration.rb
13
14
  * bin/check-multicast-groups.rb
14
15
  * bin/check-netstat-tcp.rb
15
16
  * bin/check-ping.rb
@@ -0,0 +1,124 @@
1
+ #!/usr/bin/env ruby
2
+ # encoding: utf-8
3
+ #
4
+ # check-jsonwhois-domain-expiration
5
+ #
6
+ # DESCRIPTION:
7
+ # This plugin checks domain expiration dates using the https://jsonwhois.com API
8
+ #
9
+ # OUTPUT:
10
+ # plain text
11
+ #
12
+ # PLATFORMS:
13
+ # Any
14
+ #
15
+ # DEPENDENCIES:
16
+ # gem: sensu-plugin
17
+ #
18
+ # USAGE:
19
+ # ./check-jsonwhois-domain-expiration.rb -a [YOUR API KEY] -d foo.com,bar.com
20
+ # JSONWhoisDomainExpirationCheck WARNING: foo.com: 30 days
21
+ #
22
+ # LICENSE:
23
+ # Copyright 2015 Matt Greensmith (mgreensmith@cozy.co) - Cozy Services Ltd.
24
+ # Based on check-whois-domain-expiration-multi, Copyright 2015 Tim Smith (tim@cozy.co) - Cozy Services Ltd.
25
+ # Based on check-whois-domain-expiration, Copyright 2015 michael j talarczyk <mjt@mijit.com>
26
+ # and contributors.
27
+ # Released under the same terms as Sensu (the MIT license); see LICENSE
28
+ # for details.
29
+
30
+ require 'sensu-plugin/check/cli'
31
+
32
+ require 'net/http'
33
+ require 'json'
34
+ require 'date'
35
+
36
+ #
37
+ # Check Whois domain expiration
38
+ #
39
+ class JSONWhoisDomainExpirationCheck < Sensu::Plugin::Check::CLI
40
+ option :domain,
41
+ short: '-d DOMAINS',
42
+ long: '--domains DOMAIN',
43
+ required: true,
44
+ description: 'Comma-separated list of domains to check.'
45
+
46
+ option :apikey,
47
+ short: '-a APIKEY',
48
+ long: '--apikey APIKEY',
49
+ required: true,
50
+ description: 'API key for jsonwhois.com'
51
+
52
+ option :warning,
53
+ short: '-w DAYS',
54
+ long: '--warn DAYS',
55
+ default: 30,
56
+ description: 'Warn if a domain expires in fewer than DAYS days'
57
+
58
+ option :critical,
59
+ short: '-c DAYS',
60
+ long: '--critical DAYS',
61
+ default: 7,
62
+ description: 'Critical if a domain expires in fewer than DAYS days'
63
+
64
+ option :help,
65
+ short: '-h',
66
+ long: '--help',
67
+ description: 'Show this message',
68
+ on: :tail,
69
+ boolean: true,
70
+ show_options: true,
71
+ exit: 0
72
+
73
+ # Split the provided domain list and perform whois lookups on each
74
+ #
75
+ # @return [Hash] a hash of severity_level -> domain -> days until expiry
76
+ def expiration_results
77
+ domains = config[:domain].split(',')
78
+ warning_days = config[:warning].to_i
79
+ critical_days = config[:critical].to_i
80
+ results = {}
81
+ results['critical'] = {}
82
+ results['warning'] = {}
83
+ results['ok'] = {}
84
+
85
+ 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
93
+ end
94
+ end
95
+ results
96
+ end
97
+
98
+ # Fetch whois data from the JSONWhois API and return the "expires_on" date
99
+ #
100
+ # @param domain [String] the domain to fetch from JSONWhois
101
+ # @return [DateTime] the expiration date for the domain
102
+ def get_domain_expiration(domain)
103
+ uri = URI('https://jsonwhois.com/api/v1/whois')
104
+ uri.query = URI.encode_www_form(domain: domain)
105
+ req = Net::HTTP::Get.new(uri)
106
+ req['Authorization'] = "Token token=#{config[:apikey]}"
107
+
108
+ res = Net::HTTP.start(uri.hostname, uri.port, use_ssl: uri.scheme == 'https') do |http|
109
+ http.request(req)
110
+ end
111
+
112
+ DateTime.parse(JSON.parse(res.body)['expires_on'])
113
+ end
114
+
115
+ 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
+ else
121
+ ok 'No domains expire in the near term'
122
+ end
123
+ end
124
+ end
@@ -2,7 +2,7 @@ module SensuPluginsNetworkChecks
2
2
  module Version
3
3
  MAJOR = 0
4
4
  MINOR = 0
5
- PATCH = 6
5
+ PATCH = 7
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.6
4
+ version: 0.0.7
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-10-01 00:00:00.000000000 Z
33
+ date: 2015-10-29 00:00:00.000000000 Z
34
34
  dependencies:
35
35
  - !ruby/object:Gem::Dependency
36
36
  name: dnsbl-client
@@ -235,6 +235,7 @@ executables:
235
235
  - check-netstat-tcp.rb
236
236
  - check-multicast-groups.rb
237
237
  - check-mtu.rb
238
+ - check-jsonwhois-domain-expiration.rb
238
239
  - check-banner.rb
239
240
  extensions: []
240
241
  extra_rdoc_files: []
@@ -243,6 +244,7 @@ files:
243
244
  - LICENSE
244
245
  - README.md
245
246
  - bin/check-banner.rb
247
+ - bin/check-jsonwhois-domain-expiration.rb
246
248
  - bin/check-mtu.rb
247
249
  - bin/check-multicast-groups.rb
248
250
  - bin/check-netstat-tcp.rb
metadata.gz.sig CHANGED
Binary file