pandur 0.0.0 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +9 -9
- data/bin/pandur +20 -1
- data/lib/pandur/check.rb +1 -1
- data/lib/pandur/config.rb +18 -5
- data/lib/pandur/host.rb +1 -1
- data/lib/pandur/version.rb +2 -2
- data/lib/pandur.rb +17 -35
- data/spec/spec_helper.rb +8 -0
- data/spec/units/pandur_config_spec.rb +21 -9
- data/spec/units/pandur_spec.rb +8 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 614232ea0b450bf6210f2f05435d76d9ce170cdf
|
4
|
+
data.tar.gz: 662cd1e5d5060a9b49fb4ebba82c32d87fe2d37d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
10
|
-
|
11
|
-
|
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 (
|
22
|
-
wich processes are meant to monitor.
|
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:
|
26
|
+
- name: 'web'
|
27
|
+
username: 'www-data'
|
28
28
|
check:
|
29
|
-
- name:
|
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
|
-
|
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
data/lib/pandur/config.rb
CHANGED
@@ -9,16 +9,29 @@
|
|
9
9
|
# end
|
10
10
|
# end
|
11
11
|
|
12
|
-
|
12
|
+
class Pandur
|
13
13
|
module Config
|
14
|
-
|
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
|
-
|
22
|
+
@@logger ||= Logger.new(STDERR)
|
18
23
|
end
|
19
24
|
|
20
|
-
def config(
|
21
|
-
|
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
data/lib/pandur/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
|
2
|
-
VERSION = '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
|
-
|
8
|
+
class Pandur
|
9
|
+
include Pandur::Config
|
9
10
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
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
|
-
|
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,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
|
-
@
|
10
|
+
@sut1 = PandurLoggerRspecTest.new
|
11
|
+
@sut2 = SecondPandurLoggerRspecTest.new
|
9
12
|
end
|
10
13
|
|
11
|
-
it '
|
12
|
-
|
13
|
-
@sut.logger
|
14
|
+
it 'provides logger' do
|
15
|
+
@sut1.logger.is_a? ::Logger
|
14
16
|
end
|
15
17
|
|
16
|
-
it '
|
17
|
-
|
18
|
-
|
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
|
-
|
23
|
-
@
|
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
|
data/spec/units/pandur_spec.rb
CHANGED
@@ -1,14 +1,17 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Pandur do
|
4
|
+
include Helpers
|
4
5
|
|
5
|
-
|
6
|
-
Pandur.
|
6
|
+
before(:each) do
|
7
|
+
@sut = Pandur.new :config_file => test_config_file
|
7
8
|
end
|
8
9
|
|
9
|
-
it '
|
10
|
-
|
11
|
-
|
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
|