Class: Sensu::Transport::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sensu/transport/base.rb

Direct Known Subclasses

RabbitMQ

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBase

Returns a new instance of Base.



12
13
14
15
16
# File 'lib/sensu/transport/base.rb', line 12

def initialize
  @on_error = Proc.new {}
  @before_reconnect = Proc.new {}
  @after_reconnect = Proc.new {}
end

Instance Attribute Details

#loggerLogger

Returns the Sensu logger object.

Returns:

  • (Logger)

    the Sensu logger object.



10
11
12
# File 'lib/sensu/transport/base.rb', line 10

def logger
  @logger
end

Class Method Details

.connect(options = {}) ⇒ Transport

Connects to the transport.

Parameters:

  • options (Hash, String) (defaults to: {})

Returns:



64
65
66
67
68
69
# File 'lib/sensu/transport/base.rb', line 64

def self.connect(options={})
  options ||= {}
  transport = self.new
  transport.connect(options)
  transport
end

.descendantsObject

Discover available transports (Subclasses)



136
137
138
139
140
# File 'lib/sensu/transport/base.rb', line 136

def self.descendants
  ObjectSpace.each_object(Class).select do |klass|
    klass < self
  end
end

Instance Method Details

#ack(*args, &callback) ⇒ Object

Alias for acknowledge()



122
123
124
# File 'lib/sensu/transport/base.rb', line 122

def ack(*args, &callback)
  acknowledge(*args, &callback)
end

#acknowledge(info) {|info| ... } ⇒ Object

Acknowledge the delivery of a message from the transport.

Parameters:

  • info (Hash)

    message information, eg. contains its id.

Yields:

  • (info)

    passes acknowledgment info to an optional callback/block.



117
118
119
# File 'lib/sensu/transport/base.rb', line 117

def acknowledge(info, &callback)
  callback.call(info) if callback
end

#after_reconnect(&callback) ⇒ Proc

Sets the after reconnect callback.

Parameters:

  • callback (Proc)

    called after reconnecting to the transport.

Returns:

  • (Proc)

    the after reconnect callback.



41
42
43
# File 'lib/sensu/transport/base.rb', line 41

def after_reconnect(&callback)
  @after_reconnect = callback
end

#before_reconnect(&callback) ⇒ Proc

Sets the before reconnect callback.

Parameters:

  • callback (Proc)

    called before attempting to reconnect to the transport.

Returns:

  • (Proc)

    the before reconnect callback.



32
33
34
# File 'lib/sensu/transport/base.rb', line 32

def before_reconnect(&callback)
  @before_reconnect = callback
end

#closeObject

Close the transport connection.



58
# File 'lib/sensu/transport/base.rb', line 58

def close; end

#connect(options = {}) ⇒ Object

Transport connection setup.

Parameters:

  • options (Hash, String) (defaults to: {})


48
# File 'lib/sensu/transport/base.rb', line 48

def connect(options={}); end

#connected?TrueClass, FalseClass

Indicates if connected to the transport.

Returns:

  • (TrueClass, FalseClass)


53
54
55
# File 'lib/sensu/transport/base.rb', line 53

def connected?
  false
end

#on_error(&callback) ⇒ Proc

Sets the error callback.

Parameters:

  • callback (Proc)

    called in the event of a transport error, the exception object should be passed as a parameter.

Returns:

  • (Proc)

    the error callback.



23
24
25
# File 'lib/sensu/transport/base.rb', line 23

def on_error(&callback)
  @on_error = callback
end

#publish(type, pipe, message, options = {}) {|info| ... } ⇒ Object

Publish a message to the transport.

Parameters:

  • type (Symbol)

    the transport pipe type, possible values are: :direct and :fanout.

  • pipe (String)

    the transport pipe name.

  • message (String)

    the message to be published to the transport.

  • options (Hash) (defaults to: {})

    the options to publish the message with.

Yields:

  • (info)

    passes publish info to an optional callback/block.

Yield Parameters:

  • info (Hash)

    contains publish information, which may contain an error object.



81
82
83
84
# File 'lib/sensu/transport/base.rb', line 81

def publish(type, pipe, message, options={}, &callback)
  info = {:error => nil}
  callback.call(info) if callback
end

#stats(funnel, options = {}, &callback) ⇒ Object

Transport funnel stats, such as message and consumer counts.

Parameters:

  • funnel (String)

    the transport funnel to get stats for.

  • options (Hash) (defaults to: {})

    the options to get funnel stats with.



130
131
132
133
# File 'lib/sensu/transport/base.rb', line 130

def stats(funnel, options={}, &callback)
  info = {}
  callback.call(info)
end

#subscribe(type, pipe, funnel = nil, options = {}) {|info, message| ... } ⇒ Object

Subscribe to a transport pipe and/or funnel.

Parameters:

  • type (Symbol)

    the transport pipe type, possible values are: :direct and :fanout.

  • pipe (String)

    the transport pipe name.

  • funnel (String) (defaults to: nil)

    the transport funnel, which may be connected to multiple pipes.

  • options (Hash) (defaults to: {})

    the options to consume messages with.

Yields:

  • (info, message)

    passes message info and content to the consumer callback/block.

Yield Parameters:

  • info (Hash)

    contains message information.

  • message (String)

    message.



98
99
100
101
102
# File 'lib/sensu/transport/base.rb', line 98

def subscribe(type, pipe, funnel=nil, options={}, &callback)
  info = {}
  message = ''
  callback.call(info, message)
end

#unsubscribe {|info| ... } ⇒ Object

Unsubscribe from all transport pipes and/or funnels.

Yields:

  • (info)

    passes info to an optional callback/block.

Yield Parameters:

  • info (Hash)

    contains unsubscribe information.



108
109
110
111
# File 'lib/sensu/transport/base.rb', line 108

def unsubscribe(&callback)
  info = {}
  callback.call(info) if callback
end