pandur 0.0.0
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 +7 -0
- data/Gemfile +3 -0
- data/LICENSE +19 -0
- data/README.md +33 -0
- data/Rakefile +9 -0
- data/bin/pandur +4 -0
- data/lib/pandur/check.rb +57 -0
- data/lib/pandur/config.rb +24 -0
- data/lib/pandur/host.rb +23 -0
- data/lib/pandur/version.rb +3 -0
- data/lib/pandur.rb +50 -0
- data/pandur.gemspec +27 -0
- data/spec/config.yaml +9 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/units/pandur_config_spec.rb +26 -0
- data/spec/units/pandur_spec.rb +14 -0
- metadata +92 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0a65c44db60d3634ce6a602513da833ef62b4d85
|
4
|
+
data.tar.gz: 3b5380493d3c5fd6c2b119fe7854c4928e299e62
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 668c7e031650ef7cee1b87915c991e57075ce7aa623796f49e7434b407b1eb14c6ad418ef8f47d2448df054833617a7d9c256aa61d074873da0fe7d4418ab4d4
|
7
|
+
data.tar.gz: bcd8baf4122461d2fcae872230fcd7827413705a9bed434f1b2d027669cd768798958067c341c69e324175e868aba87b316507bf4a2dc72b6e30d2555155615d
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Copyright (c) 2013 Rainer Jung <Rainer.Jung@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
pandur - AdHoc Monitoring
|
2
|
+
=========================
|
3
|
+
|
4
|
+
This gem is yet alpha, so please don't expect to much.
|
5
|
+
|
6
|
+
Usage
|
7
|
+
-----
|
8
|
+
|
9
|
+
To use run
|
10
|
+
|
11
|
+
pandur [status] # query status
|
12
|
+
pandur init # create configuration (not working yet)
|
13
|
+
|
14
|
+
To install run
|
15
|
+
|
16
|
+
gem install pandur
|
17
|
+
|
18
|
+
Configuration
|
19
|
+
-------------
|
20
|
+
|
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:
|
23
|
+
|
24
|
+
---
|
25
|
+
hosts:
|
26
|
+
- name: web
|
27
|
+
username: "www-data"
|
28
|
+
check:
|
29
|
+
- name: "Elastic Search"
|
30
|
+
pid_file: /var/run/elasticsearch.pid
|
31
|
+
- name: Memcached
|
32
|
+
pid_file: /var/run/memcached.pid
|
33
|
+
|
data/Rakefile
ADDED
data/bin/pandur
ADDED
data/lib/pandur/check.rb
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
module Pandur
|
2
|
+
class Check
|
3
|
+
include Pandur::Config
|
4
|
+
|
5
|
+
def initialize(target)
|
6
|
+
@config = target
|
7
|
+
end
|
8
|
+
|
9
|
+
def check(ssh)
|
10
|
+
logger.debug("Checking #{@config['name']}")
|
11
|
+
if @config['pid_file']
|
12
|
+
print "Checking #{@config['name']}: "
|
13
|
+
escaped_pid_file = @config['pid_file'].gsub('\'', '\\\'')
|
14
|
+
if(ssh_exec!(ssh, "test -r '#{escaped_pid_file}' && test -n '`ps -ef | grep -v grep | grep \`cat '#{escaped_pid_file}'\``'")[2] > 0)
|
15
|
+
puts "FAIL"
|
16
|
+
else
|
17
|
+
puts "OK"
|
18
|
+
end
|
19
|
+
else
|
20
|
+
logger.debug("cannot check #{@config.inspect}")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def ssh_exec!(ssh, command)
|
27
|
+
stdout_data = ""
|
28
|
+
stderr_data = ""
|
29
|
+
exit_code = nil
|
30
|
+
exit_signal = nil
|
31
|
+
ssh.open_channel do |channel|
|
32
|
+
channel.exec(command) do |ch, success|
|
33
|
+
unless success
|
34
|
+
abort "FAILED: couldn't execute command (ssh.channel.exec)"
|
35
|
+
end
|
36
|
+
channel.on_data do |ch,data|
|
37
|
+
stdout_data+=data
|
38
|
+
end
|
39
|
+
|
40
|
+
channel.on_extended_data do |ch,type,data|
|
41
|
+
stderr_data+=data
|
42
|
+
end
|
43
|
+
|
44
|
+
channel.on_request("exit-status") do |ch,data|
|
45
|
+
exit_code = data.read_long
|
46
|
+
end
|
47
|
+
|
48
|
+
channel.on_request("exit-signal") do |ch, data|
|
49
|
+
exit_signal = data.read_long
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
53
|
+
ssh.loop
|
54
|
+
[stdout_data, stderr_data, exit_code, exit_signal]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# To access configuration (and logging), just include this module to your class,
|
2
|
+
# and you can directly access all configuration and the logging.
|
3
|
+
#
|
4
|
+
# class ExampleClass
|
5
|
+
# include Pandur::Config
|
6
|
+
#
|
7
|
+
# def some_method
|
8
|
+
# logger.debug(config('some_config'))
|
9
|
+
# end
|
10
|
+
# end
|
11
|
+
|
12
|
+
module Pandur
|
13
|
+
module Config
|
14
|
+
@config = {}
|
15
|
+
|
16
|
+
def logger
|
17
|
+
Pandur.logger
|
18
|
+
end
|
19
|
+
|
20
|
+
def config(conf)
|
21
|
+
Pandur.config(conf)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/lib/pandur/host.rb
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'net/ssh'
|
2
|
+
require 'pandur/check'
|
3
|
+
|
4
|
+
module Pandur
|
5
|
+
class Host
|
6
|
+
include Pandur::Config
|
7
|
+
|
8
|
+
def initialize(target)
|
9
|
+
@config = target
|
10
|
+
end
|
11
|
+
|
12
|
+
def check
|
13
|
+
logger.debug("Connecting to #{@config['username']}@#{@config['hostname']}")
|
14
|
+
Net::SSH.start(@config['hostname'], @config['username'],
|
15
|
+
:password => @config['password']) do |ssh|
|
16
|
+
@config['check'].each do |check|
|
17
|
+
Pandur::Check.new(check).check(ssh)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
data/lib/pandur.rb
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'pandur/version'
|
2
|
+
require 'pandur/config'
|
3
|
+
require 'pandur/host'
|
4
|
+
require 'net/ssh/errors'
|
5
|
+
require 'logger'
|
6
|
+
require 'yaml'
|
7
|
+
|
8
|
+
module Pandur
|
9
|
+
|
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
|
31
|
+
|
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
|
42
|
+
end
|
43
|
+
|
44
|
+
def logger
|
45
|
+
@@logger ||= Logger.new(STDERR)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
data/pandur.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'pandur/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'pandur'
|
7
|
+
s.version = Pandur::VERSION
|
8
|
+
s.date = '2013-04-03'
|
9
|
+
s.license = 'MIT'
|
10
|
+
s.summary = 'AdHoc monitoring'
|
11
|
+
s.description = 'Check your services when you need to'
|
12
|
+
s.authors = ['Rainer Jung <Rainer.Jung@gmail.com>']
|
13
|
+
s.email = 'rj@pandur.org'
|
14
|
+
s.executables << 'pandur'
|
15
|
+
s.bindir = 'bin'
|
16
|
+
s.homepage = 'http://github.com/rynr/pandur'
|
17
|
+
s.post_install_message =
|
18
|
+
'Pandur yet comes without a config-generation'
|
19
|
+
|
20
|
+
s.files = `git ls-files`.split("\n")
|
21
|
+
s.test_files = `git ls-files -- spec/*`.split("\n")
|
22
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
23
|
+
s.extra_rdoc_files = 'README.md'
|
24
|
+
|
25
|
+
s.add_runtime_dependency('net-ssh')
|
26
|
+
s.add_development_dependency('rspec')
|
27
|
+
end
|
data/spec/config.yaml
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'pandur')
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pandur::Config do
|
4
|
+
|
5
|
+
class PandurLoggerRspecTest; include Pandur::Config; end
|
6
|
+
|
7
|
+
before(:each) do
|
8
|
+
@sut = PandurLoggerRspecTest.new
|
9
|
+
end
|
10
|
+
|
11
|
+
it 'uses Pandur.logger' do
|
12
|
+
Pandur.should_receive(:logger)
|
13
|
+
@sut.logger
|
14
|
+
end
|
15
|
+
|
16
|
+
it 'uses Pandur.config' do
|
17
|
+
Pandur.should_receive(:config).with('conf-name')
|
18
|
+
@sut.config('conf-name')
|
19
|
+
end
|
20
|
+
|
21
|
+
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')
|
24
|
+
end
|
25
|
+
|
26
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Pandur do
|
4
|
+
|
5
|
+
it 'can get logger' do
|
6
|
+
Pandur.logger.should_not be(:nil)
|
7
|
+
end
|
8
|
+
|
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')
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pandur
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Rainer Jung <Rainer.Jung@gmail.com>
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-04-03 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: net-ssh
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rspec
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Check your services when you need to
|
42
|
+
email: rj@pandur.org
|
43
|
+
executables:
|
44
|
+
- pandur
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files:
|
47
|
+
- README.md
|
48
|
+
files:
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- bin/pandur
|
54
|
+
- lib/pandur.rb
|
55
|
+
- lib/pandur/check.rb
|
56
|
+
- lib/pandur/config.rb
|
57
|
+
- lib/pandur/host.rb
|
58
|
+
- lib/pandur/version.rb
|
59
|
+
- pandur.gemspec
|
60
|
+
- spec/config.yaml
|
61
|
+
- spec/spec_helper.rb
|
62
|
+
- spec/units/pandur_config_spec.rb
|
63
|
+
- spec/units/pandur_spec.rb
|
64
|
+
homepage: http://github.com/rynr/pandur
|
65
|
+
licenses:
|
66
|
+
- MIT
|
67
|
+
metadata: {}
|
68
|
+
post_install_message: Pandur yet comes without a config-generation
|
69
|
+
rdoc_options: []
|
70
|
+
require_paths:
|
71
|
+
- lib
|
72
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - '>='
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - '>='
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
version: '0'
|
82
|
+
requirements: []
|
83
|
+
rubyforge_project:
|
84
|
+
rubygems_version: 2.0.3
|
85
|
+
signing_key:
|
86
|
+
specification_version: 4
|
87
|
+
summary: AdHoc monitoring
|
88
|
+
test_files:
|
89
|
+
- spec/config.yaml
|
90
|
+
- spec/spec_helper.rb
|
91
|
+
- spec/units/pandur_config_spec.rb
|
92
|
+
- spec/units/pandur_spec.rb
|