checkson 0.91 → 1.3

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: df976ff2fcf7b747b191dd42d58ed08b21378592f6b5706fa32c26db32ff99b9
4
- data.tar.gz: ddbc6847732551eeb853db80394e1a8bf7931f7b487c4e5c0046589b4a4f2217
3
+ metadata.gz: 817a8a360afa83eb66bad78d1166da9e39e5c54fc1e1c191d51019b0ef43e12c
4
+ data.tar.gz: 1cd8c187bbd9136dddbfcc76588a5512189362bd5c49e2a56c6dc237db0147d5
5
5
  SHA512:
6
- metadata.gz: 64681b78f3914c5e0d74cd8d23076b912290002b7b070ff03b15033764952aa8741e11d6697b57c9fe904346028a1addb5e89e9901b96572bc520b4b9a6bee0d
7
- data.tar.gz: 9b79ac4cb702bb119cc99e9e88bb229df229a242960b6bb8c29c04c7a97c9e64edb205295683a074f82ee350257f33b105d138e5a09f96d2de6296256d46503f
6
+ metadata.gz: 1493aa962e357b4fc73d329a26eeb74c071a13e82f165a861158e2047dafb6bb7c78aeffd420ee83de2d778b4099accbea037884a2834be951634143f34a99ae
7
+ data.tar.gz: 70dc8fb1dda6fddabad5395d80ba7c4740442dd4ea04ae6be16ca4af6938eec04dd1c00d97826cfd32275c8df459aa47c94d5784af1740095ef6430868788773
data/README.md CHANGED
@@ -1,4 +1,24 @@
1
1
  # Checkson
2
- [![pipeline status](https://gitlab.fsrv.xyz/fsrv/checkson/badges/master/pipeline.svg)](https://gitlab.fsrv.xyz/fsrv/checkson/commits/master)
3
- [![Gem Version](https://badge.fury.io/rb/checkson.svg)](https://badge.fury.io/rb/checkson)
4
2
 
3
+ ## Basic information
4
+
5
+ Checkson is a simple framework for host and network checking. It supports multiple modules.
6
+
7
+ An example config will include multiple blocks, each for a singe test.
8
+
9
+ ## Example configuration
10
+
11
+ ```
12
+ check 'port 61000 is open' do
13
+ using Shell
14
+ set :code, %(sockstat -4 | grep \*:61000)
15
+ help 'Port 61000 is closed'
16
+ end
17
+
18
+ check 'ssh daemon is running' do
19
+ using Process
20
+ set :name, 'sshd'
21
+ help 'Enable and start sshd'
22
+ end
23
+
24
+ ```
@@ -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
@@ -10,8 +10,8 @@ require 'logger'
10
10
 
11
11
  module Checkson
12
12
  class APIClient
13
- attr_reader :apiaddr
14
- attr_reader :outfile
13
+ attr_reader :apiaddr, :outfile
14
+
15
15
  def initialize(apiaddr, outfile)
16
16
  @apiaddr = apiaddr
17
17
  @outfile = outfile
@@ -51,7 +51,7 @@ module Checkson
51
51
  private
52
52
 
53
53
  def remove_empty_lines(string)
54
- regex = /^[\s]*$\n/
54
+ regex = /^\s]$\n/
55
55
  string.gsub(regex, '')
56
56
  end
57
57
 
File without changes
@@ -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
+ begin
28
+ raw = File.read @opts[:certfile] if File.file? @opts[:certfile]
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
File without changes
File without changes
File without changes
File without changes
@@ -5,6 +5,7 @@ require 'ostruct'
5
5
  module Checkson
6
6
  class Config
7
7
  attr_reader :checks, :name
8
+
8
9
  include Checkson::Check
9
10
 
10
11
  def initialize(file)
@@ -3,6 +3,7 @@
3
3
  module Checkson
4
4
  class Context
5
5
  attr_reader :klass, :params
6
+
6
7
  def initialize(&block)
7
8
  @klass = nil
8
9
  @params = {}
@@ -99,7 +99,7 @@ module Checkson
99
99
  end
100
100
 
101
101
  def jsonadd(sym, check)
102
- data = { desription: check.description, status: sym.status }
102
+ data = { description: check.description, status: sym.status }
103
103
  @jsonout.append(data)
104
104
  end
105
105
 
@@ -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.91'
4
+ version: '1.3'
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-12-12 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
@@ -42,14 +43,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
42
43
  requirements:
43
44
  - - ">="
44
45
  - !ruby/object:Gem::Version
45
- version: '0'
46
+ version: '2.4'
46
47
  required_rubygems_version: !ruby/object:Gem::Requirement
47
48
  requirements:
48
49
  - - ">="
49
50
  - !ruby/object:Gem::Version
50
51
  version: '0'
51
52
  requirements: []
52
- rubygems_version: 3.1.2
53
+ rubygems_version: 3.1.4
53
54
  signing_key:
54
55
  specification_version: 4
55
56
  summary: A simple framework for checking