checkson 0.3 → 0.4

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: 0d96211a8a64dbfbc3d84af7825432105a02c024fe2309b6dc09993ad6d402df
4
- data.tar.gz: e133df83fcdfdb21c3f2c48ac941edbf17e21d3ddd3a9b6415f25df979fd0d87
3
+ metadata.gz: 51822a5c369e2adc14eaaed79d77185c5be8cbd2b8440d6a4d8bd91931c4b575
4
+ data.tar.gz: a3acb19f04b2ad45bf23aa3b4e1e253fa233f1cd9048469671e36c8425613499
5
5
  SHA512:
6
- metadata.gz: 9df0c30156b15cbb707d7ef889f731b835058a7d5516907d2c164c452cd34d79ce95417c931431d8f2365133fe30e280ef4be9851c7cd99ab8036359673b5229
7
- data.tar.gz: e59a8be148940843a85c7d21f572a6796231bfd5df8b653d57c886a91d36337984f8bf6a27fe7b0877f22566673549811072199b0436f183abba22425a427bab
6
+ metadata.gz: 484fd6551a5e85ba91b4abcd57e93f5ab584edc21b5dc130e389e867b4d014ebc91cd5953fad10b1f5a065ed5bc4212f715e40d1d9d54a7ce66c1230c7935378
7
+ data.tar.gz: a4a3c2af236cf05534e99a86093c14026a331ac60e8749a8422997a7e071dcd9ef50ffd1d438baa3678faa2014fbdbe25d5e117a7cc98dcbce46c77cfedca171
data/README.md CHANGED
@@ -1,3 +1,4 @@
1
1
  # Checkson
2
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)
3
4
 
data/bin/checkson CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
2
  # frozen_string_literal: true
3
3
 
4
- require_relative '../lib/checkson'
4
+ require 'checkson'
5
5
  Checkson::UI.new
data/lib/checkson.rb CHANGED
@@ -1,6 +1,14 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'checkson/ui'
4
- require_relative 'checkson/context'
5
- require_relative 'checkson/config'
6
- require_relative 'checkson/check'
3
+ module Checkson
4
+ autoload :Config, 'checkson/config'
5
+ autoload :Context, 'checkson/context'
6
+ autoload :UI, 'checkson/ui'
7
+
8
+ module Check
9
+ autoload :Base, 'checkson/checks/base'
10
+ autoload :DNS, 'checkson/checks/dns'
11
+ autoload :Shell, 'checkson/checks/shell'
12
+ autoload :Process, 'checkson/checks/process'
13
+ end
14
+ end
@@ -1,32 +1,36 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Base
4
- attr_reader :status, :messages
5
-
6
- def initialize(_opts = {})
7
- @messages = []
8
- @status = :ok
9
- end
10
-
11
- def ok?
12
- @status == :ok
13
- end
14
-
15
- def failed?
16
- !ok?
17
- end
18
-
19
- protected
20
-
21
- def log(message)
22
- @messages << message
23
- end
24
-
25
- def ok!
26
- @status = :ok
27
- end
28
-
29
- def failed!
30
- @status = :failed
3
+ module Checkson
4
+ module Check
5
+ class Base
6
+ attr_reader :status, :messages
7
+
8
+ def initialize(_opts = {})
9
+ @messages = []
10
+ @status = :ok
11
+ end
12
+
13
+ def ok?
14
+ @status == :ok
15
+ end
16
+
17
+ def failed?
18
+ !ok?
19
+ end
20
+
21
+ protected
22
+
23
+ def log(message)
24
+ @messages << message
25
+ end
26
+
27
+ def ok!
28
+ @status = :ok
29
+ end
30
+
31
+ def failed!
32
+ @status = :failed
33
+ end
34
+ end
31
35
  end
32
36
  end
@@ -1,25 +1,29 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class DNS < Base
4
- def initialize(opts = {})
5
- @opts = { domain: 'heise.de',
6
- timeout: 1,
7
- host: 'localhost' }.merge(opts)
8
- super()
9
- end
3
+ module Checkson
4
+ module Check
5
+ class DNS < Checkson::Check::Base
6
+ def initialize(opts = {})
7
+ @opts = { domain: 'heise.de',
8
+ timeout: 1,
9
+ host: 'localhost' }.merge(opts)
10
+ super()
11
+ end
10
12
 
11
- def check
12
- require 'resolv'
13
- resolver = Resolv::DNS.new(nameserver: [@opts[:host]])
14
- resolver.timeouts = @opts[:timeout]
15
- begin
16
- resolver.getaddress(@opts[:domain])
17
- rescue Resolv::ResolvTimeout
18
- failed!
19
- log("Resolving #{@opts[:domain]} timed out")
20
- rescue Resolv::ResolvError
21
- failed!
22
- log("Could not resolve #{@opts[:domain]}")
13
+ def check
14
+ require 'resolv'
15
+ resolver = Resolv::DNS.new(nameserver: [@opts[:host]])
16
+ resolver.timeouts = @opts[:timeout]
17
+ begin
18
+ resolver.getaddress(@opts[:domain])
19
+ rescue Resolv::ResolvTimeout
20
+ failed!
21
+ log("Resolving #{@opts[:domain]} timed out")
22
+ rescue Resolv::ResolvError
23
+ failed!
24
+ log("Could not resolve #{@opts[:domain]}")
25
+ end
26
+ end
23
27
  end
24
28
  end
25
29
  end
@@ -0,0 +1,49 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'ipaddr'
4
+
5
+ module Checkson
6
+ module Check
7
+ class Process < Checkson::Check::Shell
8
+ def initialize(opts = {})
9
+ @opts = opts
10
+ unless @opts[:pidfile] || @opts[:name]
11
+ raise ArgumentError, 'Neither pidfile nor process name given'
12
+ end
13
+
14
+ super()
15
+ end
16
+
17
+ def check
18
+ @opts[:pidfile] ? check_pidfile : check_name
19
+ end
20
+
21
+ protected
22
+
23
+ def check_pidfile
24
+ pid = File.read(@opts[:pidfile]).strip
25
+ execute("kill -0 #{pid} 2>&1")
26
+
27
+ unless $?.exitstatus.zero?
28
+ failed!
29
+ log("Process ID #{pid} is not running")
30
+ end
31
+ rescue Errno::ENOENT
32
+ failed!
33
+ log("Cannot open pidfile: #{@opts[:pidfile]}")
34
+ end
35
+
36
+ def check_name
37
+ ps = execute('ps aux')
38
+
39
+ if @opts[:name].is_a?(Regexp) && ps !~ (@opts[:name])
40
+ failed!
41
+ log("No process found matching regular expression `#{@opts[:name].source}`")
42
+ elsif !ps.include?(@opts[:name])
43
+ failed!
44
+ log("No process found matching name `#{@opts[:name]}`")
45
+ end
46
+ end
47
+ end
48
+ end
49
+ end
@@ -1,21 +1,25 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- class Shell < Base
4
- def initialize(opts = {})
5
- @opts = (@opts || {}).merge(opts)
6
- super()
7
- end
3
+ module Checkson
4
+ module Check
5
+ class Shell < Checkson::Check::Base
6
+ def initialize(opts = {})
7
+ @opts = (@opts || {}).merge(opts)
8
+ super()
9
+ end
8
10
 
9
- def check
10
- raise ArgumentError, 'No code given' unless @opts[:code]
11
+ def check
12
+ raise ArgumentError, 'No code given' unless @opts[:code]
11
13
 
12
- execute(@opts[:code])
13
- failed! unless $?.exitstatus.zero?
14
- end
14
+ execute(@opts[:code])
15
+ failed! unless $?.exitstatus.zero?
16
+ end
15
17
 
16
- protected
18
+ protected
17
19
 
18
- def execute(command)
19
- `sh -c "#{command.gsub(/"/, '\"')}"`
20
+ def execute(command)
21
+ `sh -c "#{command.gsub(/"/, '\"')}"`
22
+ end
23
+ end
20
24
  end
21
25
  end
@@ -5,6 +5,7 @@ require 'ostruct'
5
5
  module Checkson
6
6
  class Config
7
7
  attr_reader :checks, :name
8
+ include Checkson::Check
8
9
 
9
10
  def initialize(file)
10
11
  @checks = []
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.3'
4
+ version: '0.4'
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-03-18 00:00:00.000000000 Z
11
+ date: 2020-03-19 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A simple framework for checking node facts
14
14
  email: florian@fsrv.xyz
@@ -20,9 +20,9 @@ files:
20
20
  - README.md
21
21
  - bin/checkson
22
22
  - lib/checkson.rb
23
- - lib/checkson/check.rb
24
23
  - lib/checkson/checks/base.rb
25
24
  - lib/checkson/checks/dns.rb
25
+ - lib/checkson/checks/process.rb
26
26
  - lib/checkson/checks/shell.rb
27
27
  - lib/checkson/config.rb
28
28
  - lib/checkson/context.rb
@@ -1,5 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'checks/base'
4
- require_relative 'checks/shell'
5
- require_relative 'checks/dns'