Class: Smarta::Sensor

Inherits:
Object
  • Object
show all
Defined in:
lib/smarta.rb

Constant Summary collapse

DEFAULT_PORT =

Default errdb port.

7070

Instance Attribute Summary collapse

Instance Method Summary collapse

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(options = {})
  @host = options[:host] || "127.0.0.1"
  @port = (options[:port] || DEFAULT_PORT).to_i
  @name = options[:name] || "Rails"
	@sock = UDPSocket.new
	@sock.connect(@host, @port)
end

Instance Attribute Details

#hostObject (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

#nameObject (readonly)

Returns the value of attribute name.



27
28
29
# File 'lib/smarta.rb', line 27

def name
  @name
end

#portObject (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

#inspectObject



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