smarta 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.
- data/CHANGELOG.md +4 -0
- data/LICENSE +20 -0
- data/README.md +31 -0
- data/examples/basic.rb +11 -0
- data/lib/smarta/version.rb +3 -0
- data/lib/smarta.rb +59 -0
- metadata +53 -0
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Ery Lee <ery.lee@gmail.com>
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
# Smarta Sensor for ruby and rails
|
2
|
+
|
3
|
+
## What's smarta
|
4
|
+
|
5
|
+
Smarta is smarta agent for nodebus (social system monitoring)
|
6
|
+
|
7
|
+
NodeBus/Smarta Home: http://nodebus.com
|
8
|
+
|
9
|
+
## What's smarta sensor
|
10
|
+
|
11
|
+
A Passive sensor that could emit events to Smarta.
|
12
|
+
|
13
|
+
## Gem Install
|
14
|
+
|
15
|
+
gem install smarta
|
16
|
+
|
17
|
+
## How to use
|
18
|
+
|
19
|
+
require "rubygems"
|
20
|
+
|
21
|
+
require "smarta"
|
22
|
+
|
23
|
+
sensor = Smarta::Sensor.new(:host => "localhost", :port => 7070, :name => "Sensor")
|
24
|
+
|
25
|
+
sensor.info("import ap successfully", "import 200 ap");
|
26
|
+
|
27
|
+
sensor.warn("exception caught", "exception details");
|
28
|
+
|
29
|
+
sensor.crit("xxx error", "error details");
|
30
|
+
|
31
|
+
|
data/examples/basic.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
|
3
|
+
require 'smarta'
|
4
|
+
|
5
|
+
sensor = Smarta::Sensor.new(:host => "localhost", :port => 7070, :name => "rails")
|
6
|
+
|
7
|
+
sensor.info("test info", "test info content");
|
8
|
+
sensor.warn("test warn", "test warn content");
|
9
|
+
sensor.crit("test crit", "test crit content");
|
10
|
+
|
11
|
+
|
data/lib/smarta.rb
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'socket'
|
4
|
+
|
5
|
+
require 'smarta/version.rb'
|
6
|
+
|
7
|
+
##
|
8
|
+
# A Ruby client library for errdb.
|
9
|
+
#
|
10
|
+
|
11
|
+
module Smarta
|
12
|
+
|
13
|
+
class Sensor
|
14
|
+
|
15
|
+
##
|
16
|
+
# Default errdb port.
|
17
|
+
|
18
|
+
DEFAULT_PORT = 7070
|
19
|
+
|
20
|
+
##
|
21
|
+
# The server this client talks to. Play at your own peril.
|
22
|
+
|
23
|
+
attr_reader :host
|
24
|
+
|
25
|
+
attr_reader :port
|
26
|
+
|
27
|
+
attr_reader :name
|
28
|
+
|
29
|
+
def initialize(options = {})
|
30
|
+
@host = options[:host] || "127.0.0.1"
|
31
|
+
@port = (options[:port] || DEFAULT_PORT).to_i
|
32
|
+
@name = options[:name] || "Rails"
|
33
|
+
@sock = UDPSocket.new
|
34
|
+
@sock.connect(@host, @port)
|
35
|
+
end
|
36
|
+
|
37
|
+
def info(title, msg)
|
38
|
+
emit("INFO", title, msg)
|
39
|
+
end
|
40
|
+
|
41
|
+
def warn(title, msg)
|
42
|
+
emit("WARNING", title, msg)
|
43
|
+
end
|
44
|
+
|
45
|
+
def crit(title, msg)
|
46
|
+
emit("CRITICAL", title, msg)
|
47
|
+
end
|
48
|
+
|
49
|
+
def emit(severity, title, msg)
|
50
|
+
@sock.send("sensor/p #{@name}\n#{severity} - #{title}\n\n#{msg}", 0)
|
51
|
+
end
|
52
|
+
|
53
|
+
def inspect
|
54
|
+
"<Sensor: %s , host: %s, port: %d>" % [@name, @host, @port]
|
55
|
+
end
|
56
|
+
|
57
|
+
end
|
58
|
+
|
59
|
+
end
|
metadata
ADDED
@@ -0,0 +1,53 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: smarta
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: '0.1'
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ery Lee
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-12-05 00:00:00.000000000Z
|
13
|
+
dependencies: []
|
14
|
+
description: Ruby smarta sensor
|
15
|
+
email: ery.lee@gmail.com
|
16
|
+
executables: []
|
17
|
+
extensions: []
|
18
|
+
extra_rdoc_files:
|
19
|
+
- LICENSE
|
20
|
+
- README.md
|
21
|
+
- CHANGELOG.md
|
22
|
+
files:
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- CHANGELOG.md
|
26
|
+
- lib/smarta.rb
|
27
|
+
- lib/smarta/version.rb
|
28
|
+
- examples/basic.rb
|
29
|
+
homepage: http://github.com/nodebus
|
30
|
+
licenses: []
|
31
|
+
post_install_message:
|
32
|
+
rdoc_options: []
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
none: false
|
37
|
+
requirements:
|
38
|
+
- - ! '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ! '>='
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '0'
|
47
|
+
requirements: []
|
48
|
+
rubyforge_project:
|
49
|
+
rubygems_version: 1.8.10
|
50
|
+
signing_key:
|
51
|
+
specification_version: 3
|
52
|
+
summary: Ruby smarta sensor
|
53
|
+
test_files: []
|