checkson 0.92 → 1.0

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
  SHA256:
3
- metadata.gz: d7ad04a8c8b91d20dc3fd54534a446f496959f9687010093509387435ae1c8dc
4
- data.tar.gz: 3900720954ee18c191869bcd57f3c0244316ece95f3d3e466e846130a875d567
3
+ metadata.gz: 1b76e9bdf83ad9a6c86e628c5bdabcac86d07be2ec46c4466ba0f3968c6e28bd
4
+ data.tar.gz: 82abf35550e9975fb3541601ab9726bc753e84ccdc309d7f9acf1a38c2f6a88b
5
5
  SHA512:
6
- metadata.gz: 4032138f405a0da0950f456a552ca134edbf69cc8c79d7103de08dd1c36e77965f15008247babd2c6ad8a4e80555acf023788817a7a89def55c899b64015a742
7
- data.tar.gz: 795d3cb0a1d1e9865c8b70b2447c6922d2b9a54cf6b67d6008126d7d0d4bd9303cdb4585eaea309a51669af3e5ceec8cc3c9c7cf4a62efb9f706b3e65b5b1065
6
+ metadata.gz: 754b5f0c8b01185b4d0c0b938b8d6a6cdae4b4309fee27b6bb825fb9d541fa0d6fbdfe894920579b35d29eb08655eb8f745f0f84a8116347e0396d734e07e69e
7
+ data.tar.gz: 8dd7bd04ea760424349955e6560b34242080d0ebdbde899820607d29d64fc96874e5e92dd039a4ec76bdae2155dd594f293288f47a7fb1de73d070e699e11619
@@ -11,5 +11,6 @@ module Checkson
11
11
  autoload :DNS, 'checkson/checks/dns'
12
12
  autoload :Shell, 'checkson/checks/shell'
13
13
  autoload :Process, 'checkson/checks/process'
14
+ autoload :Certificate, 'checkson/checks/certificate'
14
15
  end
15
16
  end
@@ -0,0 +1,52 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Checkson
4
+ module Check
5
+ class Certificate < Checkson::Check::Base
6
+ def initialize(opts = {})
7
+ @opts = (@opts || {}).merge(opts)
8
+ @opts[:port] ||= 443
9
+ super()
10
+ end
11
+
12
+ def check
13
+ raise ArgumentError, 'No options given' unless @opts[:domain] && @opts[:port] || @opts[:certfile] || @opts[:leftdays]
14
+
15
+ @opts[:domain] ? http_check : file_check
16
+ end
17
+
18
+ protected
19
+
20
+ def cert_check(cert)
21
+ time_left = @opts[:leftdays] * 86_400
22
+ failed! if Time.now + time_left > cert.not_after
23
+ end
24
+
25
+ def file_check
26
+ require 'openssl'
27
+ raw = File.read @opts[:certfile] if File.file? @opts[:certfile]
28
+ begin
29
+ certificate = OpenSSL::X509::Certificate.new raw
30
+ cert_check certificate
31
+ rescue StandardError
32
+ failed!
33
+ end
34
+ end
35
+
36
+ def http_check
37
+ require 'net/http'
38
+ require 'openssl'
39
+
40
+ uri = URI::HTTPS.build(host: @opts[:domain], port: @opts[:port])
41
+ begin
42
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: true)
43
+ cert = response.peer_cert
44
+
45
+ cert_check cert
46
+ rescue StandardError
47
+ failed!
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
@@ -110,7 +110,7 @@ module Checkson
110
110
 
111
111
  def die(msg)
112
112
  warn(msg)
113
- exit 1
113
+ exit(1)
114
114
  end
115
115
  end
116
116
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: checkson
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.92'
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Florian Bauer
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-05-22 00:00:00.000000000 Z
11
+ date: 2020-06-18 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple framework for checking node facts
14
14
  email: florian@fsrv.xyz
@@ -22,6 +22,7 @@ files:
22
22
  - lib/checkson.rb
23
23
  - lib/checkson/apiclient.rb
24
24
  - lib/checkson/checks/base.rb
25
+ - lib/checkson/checks/certificate.rb
25
26
  - lib/checkson/checks/dns.rb
26
27
  - lib/checkson/checks/packagemanagers/abstractpkgmgr.rb
27
28
  - lib/checkson/checks/packages.rb