checkson 0.1

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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 7ab2f87748c7e3e77a1039fd9b7fff153687069c01edfb7ac94e8594cab6f04f
4
+ data.tar.gz: 022660ab8a3dc7b6c324bf109e8a598793702f29fad90b426a7e7afc432d4fb3
5
+ SHA512:
6
+ metadata.gz: 86a5f89b4cd75ee3302a40decd676c8f9b0b38fc4963fcecb92055fddae5a4b1a0d5fcdf59a5fab7ce92066cd3afdfe6533897a97b8c5aad3ecc580cd49d5ceb
7
+ data.tar.gz: 7adaf87b8b50bb79a28900eae335f35930bc0413f9c8e5ac61fb826356296adcd6ea9df0cb541ff79f78300dc55ebeca7b455eb4aaa00163796334c840b458a6
@@ -0,0 +1,3 @@
1
+ # Checkson
2
+ [![pipeline status](https://gitlab.fsrv.xyz/fsrv/checkson/badges/master/pipeline.svg)](https://gitlab.fsrv.xyz/fsrv/checkson/commits/master)
3
+
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ require_relative '../lib/checkson'
5
+ Checkson::UI.new
@@ -0,0 +1,7 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'checkson/ui'
4
+ require_relative 'checkson/context'
5
+ require_relative 'checkson/config'
6
+ require_relative 'checkson/checks/base'
7
+ require_relative 'checkson/checks/shell'
@@ -0,0 +1,31 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Base
4
+ attr_reader :messages
5
+
6
+ def initialize(_opts = {})
7
+ @status = :ok
8
+ end
9
+
10
+ def ok?
11
+ @status == :ok
12
+ end
13
+
14
+ def failed?
15
+ !ok?
16
+ end
17
+
18
+ protected
19
+
20
+ def log(message)
21
+ @messages << message
22
+ end
23
+
24
+ def ok!
25
+ @status = :ok
26
+ end
27
+
28
+ def failed!
29
+ @status = :failed
30
+ end
31
+ end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ class Shell < Base
4
+ def initialize(opts = {})
5
+ @opts = (@opts || {}).merge(opts)
6
+ super()
7
+ end
8
+
9
+ def check
10
+ raise ArgumentError, 'No code given' unless @opts[:code]
11
+
12
+ execute(@opts[:code])
13
+ failed! unless $?.exitstatus.zero?
14
+ end
15
+
16
+ protected
17
+
18
+ def execute(command)
19
+ `sh -c "#{command.gsub(/"/, '\"')}"`
20
+ end
21
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ostruct'
4
+
5
+ module Checkson
6
+ class Config
7
+ attr_reader :checks, :name
8
+
9
+ def initialize(file)
10
+ @checks = []
11
+ instance_eval(File.read(file))
12
+ end
13
+
14
+ protected
15
+
16
+ def check(description, &block)
17
+ context = Checkson::Context.new(&block)
18
+ @checks << OpenStruct.new(
19
+ klass: context.klass,
20
+ description: description,
21
+ params: context.params
22
+ )
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Checkson
4
+ class Context
5
+ attr_reader :klass, :params
6
+ def initialize(&block)
7
+ @kass = nil
8
+ @params = {}
9
+ instance_eval(&block)
10
+ end
11
+
12
+ def using(klass)
13
+ @klass = klass
14
+ end
15
+
16
+ def set(key, value)
17
+ @params[key.to_sym] = value
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'optparse'
4
+
5
+ module Checkson
6
+ # Simple user interface for checkson
7
+ class UI
8
+ def initialize
9
+ set_default_options
10
+ parse_options
11
+ start_cfgd
12
+ end
13
+
14
+ protected
15
+
16
+ def start_cfgd
17
+ @config = Checkson::Config.new(@opts[:config])
18
+ @config.checks.each do |check|
19
+ c = check.klass.new(check.params)
20
+ c.check
21
+ puts c.ok?
22
+ end
23
+ end
24
+
25
+ def set_default_options
26
+ @opts = {
27
+ config: '/etc/checkson.rb'
28
+ }
29
+ end
30
+
31
+ def parse_options
32
+ OptionParser.new do |opts|
33
+ opts.banner = 'Usage: checkson [options]'
34
+ opts.on('-c', '--config FILE', 'Config file to use') do |file|
35
+ if File.exist?(file)
36
+ @opts[:config] = file
37
+ else
38
+ die("Config file #{file} does not exist")
39
+ end
40
+ end
41
+ end.parse!
42
+ end
43
+
44
+ def die(msg)
45
+ warn(msg)
46
+ exit 1
47
+ end
48
+ end
49
+ end
metadata ADDED
@@ -0,0 +1,51 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: checkson
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Florian Bauer
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-03-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A simple framework for checking node facts
14
+ email: florian@fsrv.xyz
15
+ executables:
16
+ - checkson
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - README.md
21
+ - bin/checkson
22
+ - lib/checkson.rb
23
+ - lib/checkson/checks/base.rb
24
+ - lib/checkson/checks/shell.rb
25
+ - lib/checkson/config.rb
26
+ - lib/checkson/context.rb
27
+ - lib/checkson/ui.rb
28
+ homepage: https://gitlab.fsrv.xyz/fsrv/checkson
29
+ licenses:
30
+ - BSD-3-Clause
31
+ metadata: {}
32
+ post_install_message:
33
+ rdoc_options: []
34
+ require_paths:
35
+ - lib
36
+ required_ruby_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ required_rubygems_version: !ruby/object:Gem::Requirement
42
+ requirements:
43
+ - - ">="
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ requirements: []
47
+ rubygems_version: 3.1.2
48
+ signing_key:
49
+ specification_version: 4
50
+ summary: A simple framework for checking
51
+ test_files: []