Class: Smarta::Sensor
- Inherits:
-
Object
- Object
- Smarta::Sensor
- Defined in:
- lib/smarta.rb
Constant Summary collapse
- DEFAULT_PORT =
Default errdb port.
7070
Instance Attribute Summary collapse
-
#host ⇒ Object
readonly
The server this client talks to.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#port ⇒ Object
readonly
Returns the value of attribute port.
Instance Method Summary collapse
- #crit(title, msg) ⇒ Object
- #info(title, msg) ⇒ Object
-
#initialize(options = {}) ⇒ Sensor
constructor
A new instance of Sensor.
- #inspect ⇒ Object
- #warn(title, msg) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Sensor
Returns a new instance of Sensor.
29 30 31 32 33 34 35 |
# File 'lib/smarta.rb', line 29 def initialize( = {}) @host = [:host] || "127.0.0.1" @port = ([:port] || DEFAULT_PORT).to_i @name = [:name] || "Rails" @sock = UDPSocket.new @sock.connect(@host, @port) end |
Instance Attribute Details
#host ⇒ Object (readonly)
The server this client talks to. Play at your own peril.
23 24 25 |
# File 'lib/smarta.rb', line 23 def host @host end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/smarta.rb', line 27 def name @name end |
#port ⇒ Object (readonly)
Returns the value of attribute port.
25 26 27 |
# File 'lib/smarta.rb', line 25 def port @port end |
Instance Method Details
#crit(title, msg) ⇒ Object
45 46 47 |
# File 'lib/smarta.rb', line 45 def crit(title, msg) @sock.send("sensor/$#{@name}$ 3 ##{@name} CRITICAL\n#{title}\n\n#{msg}", 0) end |
#info(title, msg) ⇒ Object
37 38 39 |
# File 'lib/smarta.rb', line 37 def info(title, msg) @sock.send("sensor/$#{@name}$ 1 ##{@name}\n#{title}\n\n#{msg}", 0) end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/smarta.rb', line 49 def inspect "<Sensor: %s , host: %s, port: %d>" % [@name, @host, @port] end |
#warn(title, msg) ⇒ Object
41 42 43 |
# File 'lib/smarta.rb', line 41 def warn(title, msg) @sock.send("sensor/$#{@name}$ 2 ##{@name} WARNING\n#{title}\n\n#{msg}", 0) end |