ruby_xymon 0.0.2
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.
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/.travis.yml +6 -0
- data/Gemfile +9 -0
- data/LICENSE +22 -0
- data/README.md +51 -0
- data/Rakefile +2 -0
- data/lib/ruby_xymon.rb +57 -0
- data/lib/ruby_xymon/version.rb +3 -0
- data/ruby_xymon.gemspec +20 -0
- data/spec/ruby_xymon_spec.rb +101 -0
- data/spec/spec_helper.rb +29 -0
- metadata +63 -0
data/.gitignore
ADDED
data/.rspec
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
--colour --require 'spec_helper'
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
Copyright (c) 2013 Bryan Taylor
|
|
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
|
+
RubyXymon [](https://travis-ci.org/rubyisbeautiful/ruby_xymon)
|
|
2
|
+
========
|
|
3
|
+
|
|
4
|
+
A simple gem for Xymon
|
|
5
|
+
|
|
6
|
+
Thanks to Greg Faust
|
|
7
|
+
|
|
8
|
+
## Installation
|
|
9
|
+
|
|
10
|
+
Add this line to your application's Gemfile:
|
|
11
|
+
|
|
12
|
+
gem 'xymon'
|
|
13
|
+
|
|
14
|
+
And then execute:
|
|
15
|
+
|
|
16
|
+
$ bundle
|
|
17
|
+
|
|
18
|
+
Or install it yourself as:
|
|
19
|
+
|
|
20
|
+
$ gem install xymon
|
|
21
|
+
|
|
22
|
+
## Usage
|
|
23
|
+
|
|
24
|
+
In its current state, the gem is simple to use. You can set two configuration variables, host and port, like this:
|
|
25
|
+
>> RubyXymon.config[:host] = 'localhost'
|
|
26
|
+
>> RubyXymon.config[:port] = '1984'
|
|
27
|
+
The values in the example are the defaults.
|
|
28
|
+
You can also set the configuration at once, using either a Hash or a String, which points to a file:
|
|
29
|
+
>> RubyXymon.config = { :host => 'localhost' }
|
|
30
|
+
>> RubyXymon.config = "/some/dir/xymon.yml"
|
|
31
|
+
|
|
32
|
+
You can send a raw Xymon message using the send method:
|
|
33
|
+
>> RubyXymon.send("status www.http green `date` Web OK")
|
|
34
|
+
|
|
35
|
+
For more information on Xymon, see the []
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
##
|
|
39
|
+
|
|
40
|
+
Future improvements:
|
|
41
|
+
* methods based on Xymon messages. Each message has its own syntax, e.g. RubyXymon.status(lifetime, group, hostname, testname, color, txt)
|
|
42
|
+
* methods to read from Xymon, e.g. "query" message
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
## Contributing
|
|
46
|
+
|
|
47
|
+
1. Fork it
|
|
48
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
|
49
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
|
50
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
|
51
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/ruby_xymon.rb
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
require "ruby_xymon/version"
|
|
2
|
+
require 'socket'
|
|
3
|
+
|
|
4
|
+
module RubyXymon
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def self.send(msg, this_host=nil, this_port=nil)
|
|
8
|
+
host = this_host.nil? ? self.config[:host] : this_host
|
|
9
|
+
port = this_port.nil? ? self.config[:port] : this_port
|
|
10
|
+
|
|
11
|
+
# create
|
|
12
|
+
t = self.new_socket(host, port)
|
|
13
|
+
|
|
14
|
+
# write
|
|
15
|
+
t.puts(msg)
|
|
16
|
+
|
|
17
|
+
# close
|
|
18
|
+
t.close
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def self.config=(hash_or_yml_file={})
|
|
23
|
+
|
|
24
|
+
case hash_or_yml_file
|
|
25
|
+
when Hash
|
|
26
|
+
@_xymon_config = default_config.merge(hash_or_yml_file)
|
|
27
|
+
when String
|
|
28
|
+
@_xymon_config = default_config.merge(YAML.load_file(hash_or_yml_file))
|
|
29
|
+
else
|
|
30
|
+
raise ArgumentError.new("config takes either a Hash type object or a filename pointing to a YAML")
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
end
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def self.config
|
|
37
|
+
if @_xymon_config.nil?
|
|
38
|
+
@_xymon_config = default_config
|
|
39
|
+
end
|
|
40
|
+
@_xymon_config
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def self.new_socket(host, port)
|
|
45
|
+
TCPSocket.new(host, port)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def self.default_config
|
|
50
|
+
{
|
|
51
|
+
:host => 'localhost',
|
|
52
|
+
:port => '1984'
|
|
53
|
+
}
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
end
|
data/ruby_xymon.gemspec
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
|
2
|
+
require 'base64'
|
|
3
|
+
require File.expand_path('../lib/ruby_xymon/version', __FILE__)
|
|
4
|
+
|
|
5
|
+
Gem::Specification.new do |gem|
|
|
6
|
+
gem.authors = ["Bryan Taylor"]
|
|
7
|
+
gem.email = ['YmNwdGF5bG9yQGdtYWlsLmNvbQ==\n'].collect{ |foo| Base64.decode64(foo) }
|
|
8
|
+
gem.description = %q{ A very simple way to send messages to Xymon }
|
|
9
|
+
gem.summary = %q{ An incredibly simple way to send messages to Xymon, with no frills at all }
|
|
10
|
+
gem.homepage = "http://github.com/rubyisbeautiful/ruby_xymon"
|
|
11
|
+
|
|
12
|
+
gem.files = `git ls-files`.split($\)
|
|
13
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
|
14
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
|
15
|
+
gem.name = "ruby_xymon"
|
|
16
|
+
gem.require_paths = ["lib"]
|
|
17
|
+
gem.version = RubyXymon::VERSION
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
end
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
require 'spec_helper'
|
|
2
|
+
|
|
3
|
+
describe "RubyXymon" do
|
|
4
|
+
|
|
5
|
+
before :each do
|
|
6
|
+
RubyXymon.instance_variable_set('@_xymon_config', nil)
|
|
7
|
+
end
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
describe 'default_config' do
|
|
11
|
+
|
|
12
|
+
it "should have a port of 1984" do
|
|
13
|
+
RubyXymon.default_config[:port].should == '1984'
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
it "should have a host of localhost" do
|
|
17
|
+
RubyXymon.default_config[:host].should == 'localhost'
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
describe 'new_socket' do
|
|
24
|
+
|
|
25
|
+
it "should return a TCPSocket" do
|
|
26
|
+
TCPSocket.should_receive(:new).with('localhost', '1984')
|
|
27
|
+
|
|
28
|
+
RubyXymon.new_socket('localhost', '1984')
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
describe 'config' do
|
|
35
|
+
|
|
36
|
+
it "should set @_xymon_config if it was nil" do
|
|
37
|
+
RubyXymon.instance_variable_get("@_xymon_config").nil?.should be_true
|
|
38
|
+
|
|
39
|
+
RubyXymon.config
|
|
40
|
+
|
|
41
|
+
RubyXymon.instance_variable_get("@_xymon_config").nil?.should be_false
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
it "should return @_xymon_config if it was not nil" do
|
|
45
|
+
RubyXymon.instance_variable_set("@_xymon_config", 'foo')
|
|
46
|
+
|
|
47
|
+
RubyXymon.config.should == 'foo'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
describe 'config=' do
|
|
54
|
+
|
|
55
|
+
it 'should accept a hash and merge it to defaults' do
|
|
56
|
+
RubyXymon.config = { :host => 'foo' }
|
|
57
|
+
|
|
58
|
+
RubyXymon.config.should == { :host => 'foo', :port => '1984' }
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
it 'should accept a YAML file and merge it to defaults' do
|
|
63
|
+
YAML.should_receive(:load_file).with('some_file').and_return({ :host => 'foo' })
|
|
64
|
+
|
|
65
|
+
RubyXymon.config = 'some_file'
|
|
66
|
+
|
|
67
|
+
RubyXymon.config.should == { :host => 'foo', :port => '1984' }
|
|
68
|
+
end
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
|
|
73
|
+
describe 'send' do
|
|
74
|
+
|
|
75
|
+
it 'should use default host if not passed' do
|
|
76
|
+
RubyXymon.should_receive(:new_socket).with('localhost', '1984').and_return(double.as_null_object)
|
|
77
|
+
|
|
78
|
+
RubyXymon.send('foo')
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
it 'should use default port if not passed' do
|
|
83
|
+
RubyXymon.should_receive(:new_socket).with('baconhost', '1984').and_return(double.as_null_object)
|
|
84
|
+
|
|
85
|
+
RubyXymon.send('foo', 'baconhost')
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
it "the socket should receive the message" do
|
|
90
|
+
duck = double.as_null_object
|
|
91
|
+
duck.should_receive(:puts).with('foo')
|
|
92
|
+
|
|
93
|
+
RubyXymon.stub(:new_socket).and_return(duck)
|
|
94
|
+
|
|
95
|
+
RubyXymon.send('foo')
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
end
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
require 'rubygems'
|
|
2
|
+
require 'simplecov'
|
|
3
|
+
require File.join(File.dirname(__FILE__), '..', 'lib/ruby_xymon')
|
|
4
|
+
|
|
5
|
+
SimpleCov.start
|
|
6
|
+
|
|
7
|
+
RSpec.configure do |config|
|
|
8
|
+
|
|
9
|
+
# == Mock Framework
|
|
10
|
+
#
|
|
11
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
|
12
|
+
#
|
|
13
|
+
# config.mock_with :mocha
|
|
14
|
+
# config.mock_with :flexmock
|
|
15
|
+
# config.mock_with :rr
|
|
16
|
+
config.mock_with :rspec
|
|
17
|
+
|
|
18
|
+
# Remove this line if you're not using ActiveRecord or ActiveRecord fixtures
|
|
19
|
+
# config.fixture_path = "#{::Rails.root}/spec/fixtures"
|
|
20
|
+
|
|
21
|
+
# If you're not using ActiveRecord, or you'd prefer not to run each of your
|
|
22
|
+
# examples within a transaction, remove the following line or assign false
|
|
23
|
+
# instead of true.
|
|
24
|
+
# config.use_transactional_fixtures = true
|
|
25
|
+
|
|
26
|
+
# config.fixture_path = File.expand_path(File.join(File.dirname(__FILE__), 'fixtures'))
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: ruby_xymon
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.2
|
|
5
|
+
prerelease:
|
|
6
|
+
platform: ruby
|
|
7
|
+
authors:
|
|
8
|
+
- Bryan Taylor
|
|
9
|
+
autorequire:
|
|
10
|
+
bindir: bin
|
|
11
|
+
cert_chain: []
|
|
12
|
+
date: 2013-02-05 00:00:00.000000000 Z
|
|
13
|
+
dependencies: []
|
|
14
|
+
description: ! ' A very simple way to send messages to Xymon '
|
|
15
|
+
email:
|
|
16
|
+
- !binary |-
|
|
17
|
+
YmNwdGF5bG9yQGdtYWlsLmNvbQ==
|
|
18
|
+
executables: []
|
|
19
|
+
extensions: []
|
|
20
|
+
extra_rdoc_files: []
|
|
21
|
+
files:
|
|
22
|
+
- .gitignore
|
|
23
|
+
- .rspec
|
|
24
|
+
- .travis.yml
|
|
25
|
+
- Gemfile
|
|
26
|
+
- LICENSE
|
|
27
|
+
- README.md
|
|
28
|
+
- Rakefile
|
|
29
|
+
- lib/ruby_xymon.rb
|
|
30
|
+
- lib/ruby_xymon/version.rb
|
|
31
|
+
- ruby_xymon.gemspec
|
|
32
|
+
- spec/ruby_xymon_spec.rb
|
|
33
|
+
- spec/spec_helper.rb
|
|
34
|
+
homepage: http://github.com/rubyisbeautiful/ruby_xymon
|
|
35
|
+
licenses: []
|
|
36
|
+
post_install_message:
|
|
37
|
+
rdoc_options: []
|
|
38
|
+
require_paths:
|
|
39
|
+
- lib
|
|
40
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
41
|
+
none: false
|
|
42
|
+
requirements:
|
|
43
|
+
- - ! '>='
|
|
44
|
+
- !ruby/object:Gem::Version
|
|
45
|
+
version: '0'
|
|
46
|
+
segments:
|
|
47
|
+
- 0
|
|
48
|
+
hash: -1473618950636672990
|
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
50
|
+
none: false
|
|
51
|
+
requirements:
|
|
52
|
+
- - ! '>='
|
|
53
|
+
- !ruby/object:Gem::Version
|
|
54
|
+
version: '0'
|
|
55
|
+
requirements: []
|
|
56
|
+
rubyforge_project:
|
|
57
|
+
rubygems_version: 1.8.24
|
|
58
|
+
signing_key:
|
|
59
|
+
specification_version: 3
|
|
60
|
+
summary: An incredibly simple way to send messages to Xymon, with no frills at all
|
|
61
|
+
test_files:
|
|
62
|
+
- spec/ruby_xymon_spec.rb
|
|
63
|
+
- spec/spec_helper.rb
|