checkson 0.7 → 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 +4 -4
- data/lib/checkson.rb +1 -0
- data/lib/checkson/checks/certificate.rb +52 -0
- data/lib/checkson/checks/process.rb +1 -1
- data/lib/checkson/context.rb +1 -1
- data/lib/checkson/ui.rb +25 -7
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1b76e9bdf83ad9a6c86e628c5bdabcac86d07be2ec46c4466ba0f3968c6e28bd
|
4
|
+
data.tar.gz: 82abf35550e9975fb3541601ab9726bc753e84ccdc309d7f9acf1a38c2f6a88b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 754b5f0c8b01185b4d0c0b938b8d6a6cdae4b4309fee27b6bb825fb9d541fa0d6fbdfe894920579b35d29eb08655eb8f745f0f84a8116347e0396d734e07e69e
|
7
|
+
data.tar.gz: 8dd7bd04ea760424349955e6560b34242080d0ebdbde899820607d29d64fc96874e5e92dd039a4ec76bdae2155dd594f293288f47a7fb1de73d070e699e11619
|
data/lib/checkson.rb
CHANGED
@@ -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
|
data/lib/checkson/context.rb
CHANGED
data/lib/checkson/ui.rb
CHANGED
@@ -1,13 +1,15 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require 'optparse'
|
4
|
-
require 'logger'
|
5
4
|
require 'uri'
|
5
|
+
require 'json'
|
6
6
|
|
7
7
|
module Checkson
|
8
8
|
# Simple user interface for checkson
|
9
9
|
class UI
|
10
10
|
def initialize
|
11
|
+
@jsonout = []
|
12
|
+
|
11
13
|
set_default_options
|
12
14
|
parse_options
|
13
15
|
start_checks
|
@@ -29,16 +31,22 @@ module Checkson
|
|
29
31
|
c = check.klass.new(check.params)
|
30
32
|
c.check
|
31
33
|
@num_ok += 1 if c.status.eql? :ok
|
32
|
-
|
34
|
+
output_plain c, check if @opts[:verbose]
|
35
|
+
if @opts[:jsonexport]
|
36
|
+
@opts[:verbose] = false
|
37
|
+
jsonadd(c, check)
|
38
|
+
end
|
33
39
|
end
|
34
40
|
@num_failed = (@num_checks - @num_ok)
|
35
|
-
puts "-> #{@num_checks} checks performed: #{@num_ok} ok, #{@num_failed} failed"
|
41
|
+
puts "-> #{@num_checks} checks performed: #{@num_ok} ok, #{@num_failed} failed" unless @opts[:jsonexport]
|
42
|
+
output_json if @opts[:jsonexport]
|
36
43
|
end
|
37
44
|
|
38
45
|
def set_default_options
|
39
46
|
@opts = {
|
40
47
|
datasource: :file,
|
41
48
|
verbose: false,
|
49
|
+
jsonexport: false,
|
42
50
|
config_file: '/etc/checkson.rb',
|
43
51
|
endpoint: 'https://checkson.fsrv.services:8080'
|
44
52
|
}
|
@@ -50,6 +58,9 @@ module Checkson
|
|
50
58
|
opts.on('-v', '--[no-]verbose', 'Run verbosely') do |v|
|
51
59
|
@opts[:verbose] = v
|
52
60
|
end
|
61
|
+
opts.on('-j', '--[no-]jsonexport', 'do output as json') do |j|
|
62
|
+
@opts[:jsonexport] = j
|
63
|
+
end
|
53
64
|
opts.on('-d', '--datasource [TYPE]', %i[file api], 'Set datasource type', '(file, api)') do |d|
|
54
65
|
@opts[:datasource] = d
|
55
66
|
end
|
@@ -68,11 +79,13 @@ module Checkson
|
|
68
79
|
end
|
69
80
|
end
|
70
81
|
end.parse!
|
71
|
-
logger = Logger.new(STDOUT)
|
72
|
-
logger.info "Using datasource `#{@opts[:datasource]}`"
|
73
82
|
end
|
74
83
|
|
75
|
-
def
|
84
|
+
def output_json
|
85
|
+
puts @jsonout.to_json
|
86
|
+
end
|
87
|
+
|
88
|
+
def output_plain(sym, check)
|
76
89
|
status_column = winsize[1] / 3 * 2
|
77
90
|
print check.description
|
78
91
|
case sym.status
|
@@ -85,6 +98,11 @@ module Checkson
|
|
85
98
|
end
|
86
99
|
end
|
87
100
|
|
101
|
+
def jsonadd(sym, check)
|
102
|
+
data = { description: check.description, status: sym.status }
|
103
|
+
@jsonout.append(data)
|
104
|
+
end
|
105
|
+
|
88
106
|
def winsize
|
89
107
|
require 'io/console'
|
90
108
|
IO.console.winsize
|
@@ -92,7 +110,7 @@ module Checkson
|
|
92
110
|
|
93
111
|
def die(msg)
|
94
112
|
warn(msg)
|
95
|
-
exit
|
113
|
+
exit(1)
|
96
114
|
end
|
97
115
|
end
|
98
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
|
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-
|
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
|