observium-agent 0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +51 -0
- data/Rakefile +1 -0
- data/lib/observium/agent.rb +18 -0
- data/lib/observium/agent/errors.rb +8 -0
- data/lib/observium/agent/parser.rb +65 -0
- data/lib/observium/agent/poller.rb +39 -0
- data/lib/observium/agent/version.rb +5 -0
- data/observium-agent.gemspec +23 -0
- metadata +83 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 81d722138539283adf3e5e292761d3d2d6a9aa08
|
4
|
+
data.tar.gz: 2dda368805a064fa459b367886b6e0643a56574e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: a959cd3319e53dd9c257e7c06b9b0aee9afeb67c1da70e63f854b421e7137fdcef504d37e8ed6c180b2982c91cce25de9ab050486cc0ef4be37cd65cc1763f0b
|
7
|
+
data.tar.gz: 2a54d0faa54f87ca47cbb55945f9fd5cf9a17742cf30319e5d5e2db0e6999d3dc089d03022d0b1e8de7b735701f8d0a492b68214f39a2bc230465e57c257a460
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Robert McLeod
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
# Observium::Agent
|
2
|
+
|
3
|
+
This gem provides a way to get data from an Observium or Check_MK agent using ruby.
|
4
|
+
It polls the information, and parses the output allowing you to use the information
|
5
|
+
wherever you need it.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
gem 'observium-agent'
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install observium-agent
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
Here's how to use the gem in your code, it's pretty simple:
|
24
|
+
|
25
|
+
```ruby
|
26
|
+
# Poll and parse
|
27
|
+
output = Observium::Agent::Poller.new("host.example.com").poll
|
28
|
+
parser = Observium::Agent::Parser.new(output)
|
29
|
+
|
30
|
+
# See what sections are available
|
31
|
+
parser.sections # ["dmi", "dpkg", "kernel", "ps", "uptime"]
|
32
|
+
|
33
|
+
# or check if a section is available
|
34
|
+
parser.has_section? "dmi" # we will be using :symbols soon
|
35
|
+
|
36
|
+
# Get the section and dump a field
|
37
|
+
dmi = parser.section "dmi"
|
38
|
+
puts dmi[:processor_version] # outputs Genuine Intel(R) CPU N270 @ 1.60GHz
|
39
|
+
```
|
40
|
+
|
41
|
+
## Future plans
|
42
|
+
|
43
|
+
We want to make it so you can keep your agent ports closed but still access the agent securely. We hope to do this through the use of an optional SSH proxy.
|
44
|
+
|
45
|
+
## Contributing
|
46
|
+
|
47
|
+
1. Fork it ( http://github.com/AutogrowSystems/observium-agent/fork )
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
49
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require "observium/agent/version"
|
2
|
+
require "observium/agent/errors"
|
3
|
+
require "observium/agent/poller"
|
4
|
+
require "observium/agent/parser"
|
5
|
+
|
6
|
+
module Observium
|
7
|
+
module Agent
|
8
|
+
extend self
|
9
|
+
|
10
|
+
def defaults
|
11
|
+
{
|
12
|
+
port: 6556,
|
13
|
+
timeout: 5
|
14
|
+
}
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
module Observium
|
2
|
+
module Agent
|
3
|
+
class Parser
|
4
|
+
attr_reader :sections
|
5
|
+
|
6
|
+
def initialize(text)
|
7
|
+
@text = text
|
8
|
+
|
9
|
+
validate!
|
10
|
+
preprocess
|
11
|
+
end
|
12
|
+
|
13
|
+
def section(title, postprocess=true)
|
14
|
+
return {} unless has_section?(title)
|
15
|
+
|
16
|
+
index = @lines.index("<<<#{title}>>>")
|
17
|
+
|
18
|
+
array = []
|
19
|
+
@lines[(index+1)..@lines.size].each do |line|
|
20
|
+
break if line.include? "<<<"
|
21
|
+
array << line
|
22
|
+
end
|
23
|
+
|
24
|
+
return array.join("\n") unless postprocess
|
25
|
+
|
26
|
+
hash = Hash.new
|
27
|
+
array.each do |line|
|
28
|
+
if m = line.match(/^(\S+)=(.*)$/)
|
29
|
+
hash[ symbolize_field( m[1] ) ] = m[2]
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
hash
|
34
|
+
end
|
35
|
+
|
36
|
+
def has_section?(title)
|
37
|
+
@sections.include? title
|
38
|
+
end
|
39
|
+
|
40
|
+
def symbolize_field(field)
|
41
|
+
field.downcase!
|
42
|
+
field.tr! "-", "_"
|
43
|
+
field.to_sym
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def validate!
|
49
|
+
valid_text? or raise Errors::ParsingFailed, "Invalid text passed to the parser"
|
50
|
+
end
|
51
|
+
|
52
|
+
def valid_text?
|
53
|
+
!@text.nil? and
|
54
|
+
!@text.strip.empty? and
|
55
|
+
!@text.lines.count.zero? and
|
56
|
+
@text.lines.count != 1
|
57
|
+
end
|
58
|
+
|
59
|
+
def preprocess
|
60
|
+
@lines = @text.split("\n")
|
61
|
+
@sections = @text.scan(/<<<([^>]*)>>>/).map {|s| s.first }
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
module Observium
|
2
|
+
module Agent
|
3
|
+
class Poller
|
4
|
+
def initialize(host, **args)
|
5
|
+
@host = host
|
6
|
+
@port = args[:port] || Observium::Agent.defaults[:port]
|
7
|
+
@timeout = args[:timeout] || Observium::Agent.defaults[:timeout]
|
8
|
+
end
|
9
|
+
|
10
|
+
# Connects to the given host on the agent port to get the agent
|
11
|
+
# output. Connection times out after 5 seconds.
|
12
|
+
#
|
13
|
+
# Raises a PollingFailed error if no data was output, or the command failed
|
14
|
+
#
|
15
|
+
# Returns the raw output returned by the agent as a multiline string
|
16
|
+
def poll
|
17
|
+
@output = %x(nc -w #{@timeout} #{@host} #{@port} 2>&1)
|
18
|
+
|
19
|
+
$?.success? or raise Errors::PollingFailed, "Agent check failed: #{error_msg}"
|
20
|
+
has_data? or raise Errors::PollingFailed, "Agent didn't return any data"
|
21
|
+
|
22
|
+
@output
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
# Checks if the agent returned any data, usually signified by more than a
|
28
|
+
# single line being present in the output
|
29
|
+
def has_data?
|
30
|
+
@output.lines.count > 1
|
31
|
+
end
|
32
|
+
|
33
|
+
# Parses the error message from the netcat error output to stderr
|
34
|
+
def error_msg
|
35
|
+
@output.split(":").last.strip
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'observium/agent/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "observium-agent"
|
8
|
+
spec.version = Observium::Agent::VERSION
|
9
|
+
spec.authors = ["Robert McLeod"]
|
10
|
+
spec.email = ["robert@autogrow.com"]
|
11
|
+
spec.summary = %q{Ruby gem to interface with Observium Agents}
|
12
|
+
spec.description = %q{Interface with Observium Agents using ruby to gather system information}
|
13
|
+
spec.homepage = "https://github.com/AutogrowSystems/observium-agent-gem"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.5"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
end
|
metadata
ADDED
@@ -0,0 +1,83 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: observium-agent
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Robert McLeod
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-06-17 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.5'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.5'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
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: Interface with Observium Agents using ruby to gather system information
|
42
|
+
email:
|
43
|
+
- robert@autogrow.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- Gemfile
|
50
|
+
- LICENSE.txt
|
51
|
+
- README.md
|
52
|
+
- Rakefile
|
53
|
+
- lib/observium/agent.rb
|
54
|
+
- lib/observium/agent/errors.rb
|
55
|
+
- lib/observium/agent/parser.rb
|
56
|
+
- lib/observium/agent/poller.rb
|
57
|
+
- lib/observium/agent/version.rb
|
58
|
+
- observium-agent.gemspec
|
59
|
+
homepage: https://github.com/AutogrowSystems/observium-agent-gem
|
60
|
+
licenses:
|
61
|
+
- MIT
|
62
|
+
metadata: {}
|
63
|
+
post_install_message:
|
64
|
+
rdoc_options: []
|
65
|
+
require_paths:
|
66
|
+
- lib
|
67
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
68
|
+
requirements:
|
69
|
+
- - ">="
|
70
|
+
- !ruby/object:Gem::Version
|
71
|
+
version: '0'
|
72
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
73
|
+
requirements:
|
74
|
+
- - ">="
|
75
|
+
- !ruby/object:Gem::Version
|
76
|
+
version: '0'
|
77
|
+
requirements: []
|
78
|
+
rubyforge_project:
|
79
|
+
rubygems_version: 2.2.2
|
80
|
+
signing_key:
|
81
|
+
specification_version: 4
|
82
|
+
summary: Ruby gem to interface with Observium Agents
|
83
|
+
test_files: []
|