pandur 0.0.0 → 0.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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a65c44db60d3634ce6a602513da833ef62b4d85
4
- data.tar.gz: 3b5380493d3c5fd6c2b119fe7854c4928e299e62
3
+ metadata.gz: 614232ea0b450bf6210f2f05435d76d9ce170cdf
4
+ data.tar.gz: 662cd1e5d5060a9b49fb4ebba82c32d87fe2d37d
5
5
  SHA512:
6
- metadata.gz: 668c7e031650ef7cee1b87915c991e57075ce7aa623796f49e7434b407b1eb14c6ad418ef8f47d2448df054833617a7d9c256aa61d074873da0fe7d4418ab4d4
7
- data.tar.gz: bcd8baf4122461d2fcae872230fcd7827413705a9bed434f1b2d027669cd768798958067c341c69e324175e868aba87b316507bf4a2dc72b6e30d2555155615d
6
+ metadata.gz: 07cf4fb25e3c2d67ac4bfbcd64c869858e9e896b412def997996ec2af2f11f77b86aa56db33c6fac98dfbf40fbc9afac756f56738dd8c558541ba992b8afaa53
7
+ data.tar.gz: f7e967d63c53d551421cd24152e74b225db7d5cd30e52084d527a399bf505491239e60c370ac384db1dba7096b8da348172052ab3526f7e3c3684b7384871be4
data/README.md CHANGED
@@ -6,10 +6,9 @@ This gem is yet alpha, so please don't expect to much.
6
6
  Usage
7
7
  -----
8
8
 
9
- To use run
10
-
11
- pandur [status] # query status
12
- pandur init # create configuration (not working yet)
9
+ Usage: pandur [options]
10
+ -c, --config [FILE] Define config-file
11
+ -h, --help Show this message
13
12
 
14
13
  To install run
15
14
 
@@ -18,15 +17,16 @@ To install run
18
17
  Configuration
19
18
  -------------
20
19
 
21
- You need to create a configuration (a yaml-file) of all hosts to connect to, and
22
- wich processes are meant to monitor. Here's a simple example:
20
+ You need to create a configuration (`~/.pandur.yaml` by default) of all hosts
21
+ to connect to, and wich processes are meant to monitor.
22
+ Here's a simple example:
23
23
 
24
24
  ---
25
25
  hosts:
26
- - name: web
27
- username: "www-data"
26
+ - name: 'web'
27
+ username: 'www-data'
28
28
  check:
29
- - name: "Elastic Search"
29
+ - name: 'Elastic Search'
30
30
  pid_file: /var/run/elasticsearch.pid
31
31
  - name: Memcached
32
32
  pid_file: /var/run/memcached.pid
data/bin/pandur CHANGED
@@ -1,4 +1,23 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
3
  require 'pandur'
4
- Pandur.run
4
+ require 'optparse'
5
+
6
+ options = {}
7
+
8
+ OptionParser.new do |opts|
9
+ opts.banner = 'Usage: pandur [options]'
10
+
11
+ options[:config_file] = '~/.pandur.yaml'
12
+ #options[:log_level] = Logger::DEBUG
13
+ opts.on('-c', '--config [FILE]', 'Define config-file') do |config_file|
14
+ options[:config_file] = config_file
15
+ end
16
+
17
+ opts.on_tail("-h", "--help", "Show this message") do
18
+ puts opts
19
+ exit
20
+ end
21
+ end.parse!
22
+
23
+ Pandur.new(options).run
data/lib/pandur/check.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Pandur
1
+ class Pandur
2
2
  class Check
3
3
  include Pandur::Config
4
4
 
data/lib/pandur/config.rb CHANGED
@@ -9,16 +9,29 @@
9
9
  # end
10
10
  # end
11
11
 
12
- module Pandur
12
+ class Pandur
13
13
  module Config
14
- @config = {}
14
+ @@config = {}
15
+
16
+ def load_config(file)
17
+ logger.debug("Loading configuration from #{file.to_s}")
18
+ @@config = YAML::load_file(File.expand_path(file))
19
+ end
15
20
 
16
21
  def logger
17
- Pandur.logger
22
+ @@logger ||= Logger.new(STDERR)
18
23
  end
19
24
 
20
- def config(conf)
21
- Pandur.config(conf)
25
+ def config(*params)
26
+ @@config ||= {}
27
+ case params.length()
28
+ when 0
29
+ @@config
30
+ when 1
31
+ @@config[params.first]
32
+ else
33
+ @@config[params[0]] = params[1]
34
+ end
22
35
  end
23
36
  end
24
37
  end
data/lib/pandur/host.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  require 'net/ssh'
2
2
  require 'pandur/check'
3
3
 
4
- module Pandur
4
+ class Pandur
5
5
  class Host
6
6
  include Pandur::Config
7
7
 
@@ -1,3 +1,3 @@
1
- module Pandur
2
- VERSION = '0.0.0'
1
+ class Pandur
2
+ VERSION = '0.0.1'
3
3
  end
data/lib/pandur.rb CHANGED
@@ -5,46 +5,28 @@ require 'net/ssh/errors'
5
5
  require 'logger'
6
6
  require 'yaml'
7
7
 
8
- module Pandur
8
+ class Pandur
9
+ include Pandur::Config
9
10
 
10
- class << self
11
-
12
- def run(conf = 'pandur.yaml')
13
- logger.debug("#{name} running ..")
14
- load_config(conf)
15
- config('hosts').each do |host|
16
- check(host)
17
- end
18
- logger.debug("#{name} .. finished")
19
- end
20
-
21
- def check(target)
22
- Pandur::Host.new(target).check
23
- rescue Net::SSH::AuthenticationFailed
24
- puts "Failed to connect: #{$!.message}"
25
- end
26
-
27
- def load_config(file)
28
- logger.debug("Loading configuration from #{file.to_s}")
29
- @@config = YAML::load_file(file)
30
- end
11
+ def initialize(conf = {})
12
+ logger.level = conf[:log_level] || Logger::ERROR
13
+ load_config(conf[:config_file] || '~/.pandur.yaml')
14
+ end
31
15
 
32
- def config(*params)
33
- @@config ||= {}
34
- case params.length()
35
- when 0
36
- @@config
37
- when 1
38
- @@config[params.first]
39
- else
40
- @@config[params[0]] = params[1]
41
- end
16
+ def run(conf = {})
17
+ logger.debug("running ..")
18
+ config('hosts').each do |host|
19
+ check(host)
42
20
  end
21
+ logger.debug(".. finished")
22
+ end
43
23
 
44
- def logger
45
- @@logger ||= Logger.new(STDERR)
46
- end
24
+ private
47
25
 
26
+ def check(target)
27
+ Pandur::Host.new(target).check
28
+ rescue Net::SSH::AuthenticationFailed
29
+ puts "Failed to connect: #{$!.message}"
48
30
  end
49
31
 
50
32
  end
data/spec/spec_helper.rb CHANGED
@@ -1 +1,9 @@
1
1
  require File.join(File.dirname(__FILE__), '..', 'lib', 'pandur')
2
+
3
+ module Helpers
4
+
5
+ def test_config_file
6
+ File.join(File.dirname(__FILE__), 'config.yaml')
7
+ end
8
+
9
+ end
@@ -1,26 +1,38 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Pandur::Config do
4
+ include Helpers
4
5
 
5
6
  class PandurLoggerRspecTest; include Pandur::Config; end
7
+ class SecondPandurLoggerRspecTest; include Pandur::Config; end
6
8
 
7
9
  before(:each) do
8
- @sut = PandurLoggerRspecTest.new
10
+ @sut1 = PandurLoggerRspecTest.new
11
+ @sut2 = SecondPandurLoggerRspecTest.new
9
12
  end
10
13
 
11
- it 'uses Pandur.logger' do
12
- Pandur.should_receive(:logger)
13
- @sut.logger
14
+ it 'provides logger' do
15
+ @sut1.logger.is_a? ::Logger
14
16
  end
15
17
 
16
- it 'uses Pandur.config' do
17
- Pandur.should_receive(:config).with('conf-name')
18
- @sut.config('conf-name')
18
+ it 'shares logger' do
19
+ @sut1.logger.should eq(@sut2.logger)
20
+ end
21
+
22
+ it 'loads config via YAML' do
23
+ File.should_receive(:expand_path).with('config').and_return('expanded')
24
+ YAML.should_receive(:load_file).with('expanded').and_return({})
25
+ @sut1.load_config('config')
19
26
  end
20
27
 
21
28
  it 'gets config' do
22
- Pandur.load_config(File.join(File.dirname(__FILE__), '..', 'config.yaml'))
23
- @sut.config('config_to_be_tested_by_pandur_spec.rb').should eql('success')
29
+ @sut1.load_config(test_config_file)
30
+ @sut1.config('config_to_be_tested_by_pandur_spec.rb').should eql('success')
31
+ end
32
+
33
+ it 'shares config' do
34
+ @sut1.load_config(test_config_file)
35
+ @sut2.config('config_to_be_tested_by_pandur_spec.rb').should eql('success')
24
36
  end
25
37
 
26
38
  end
@@ -1,14 +1,17 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Pandur do
4
+ include Helpers
4
5
 
5
- it 'can get logger' do
6
- Pandur.logger.should_not be(:nil)
6
+ before(:each) do
7
+ @sut = Pandur.new :config_file => test_config_file
7
8
  end
8
9
 
9
- it 'can load config from file' do
10
- Pandur.load_config(File.join(File.dirname(__FILE__), '..', 'config.yaml'))
11
- Pandur.config('config_to_be_tested_by_pandur_spec.rb').should eql('success')
10
+ it 'checks each configured host' do
11
+ @sut.should_receive(:config).with('hosts').and_return(['host1', 'host2'])
12
+ @sut.should_receive(:check).with('host1')
13
+ @sut.should_receive(:check).with('host2')
14
+ @sut.run
12
15
  end
13
16
 
14
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pandur
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rainer Jung <Rainer.Jung@gmail.com>