checkson 0.9 → 1.2

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: 5cac8e522bab24c578456dfb2c52f859989e63be405d2d63ec6d828059303a69
4
- data.tar.gz: 8f6c0543e1f88bb628a858e041073b1dbbb822ea7aa496edaadc302c6ef8ec7b
3
+ metadata.gz: 3034c81ee8dcdfd2144f5717ce4aab906401e1073c59e1d0c74c48579d2d36e1
4
+ data.tar.gz: 639e559b5370aa20637b9f78bfbf81399bc3332035df17e4025308666d384890
5
5
  SHA512:
6
- metadata.gz: 6f857be6d9da861cecbc4baa81095150b9cc6db6bca5883682dd5f5e7e0d9012a16c004deb784223101c07afd5b9fb16d73751c83de2fbfd2826a2c42f48b6e0
7
- data.tar.gz: 82b818b24e66189fc6ecc9af6f5643c7c25dc0cce0dec8eff45c24738983c02d57a8e9695f072e7a1c73d2f0018c4ca5a209e25e08f2640d43a205c35bbd21ed
6
+ metadata.gz: 6a2084ae9a54298000135078937cfdf1036e773ad591caf3377bb49c0e625116a160ddbdcda5a091e56968d8fd98ee7fabe0aae8d47c381540b1ff85cb2aff98
7
+ data.tar.gz: 5dc0b857a5c2a429eeac127ed8769219682da575f2a8c52cea7bfe67947965ce0572110001e58c33430ffaa4c89c77a1173d8332f202f8b1709e4e572db6de46
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 = {}
@@ -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
- output c, check if @opts[:verbose]
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 output(sym, check)
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 1
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.9'
4
+ version: '1.2'
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-13 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