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

.descendantsObject

Discover available transports (Subclasses)


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

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

Instance Method Details

#ack(*args, &callback) ⇒ Object

Alias for acknowledge()


114
115
116
# File 'lib/sensu/transport/base.rb', line 114

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.


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

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

#after_reconnect(&callback) ⇒ Proc

Set 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

Set 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.


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

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)

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

def connected?
  false
end

#on_error(&callback) ⇒ Proc

Set 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.


73
74
75
76
# File 'lib/sensu/transport/base.rb', line 73

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

#reconnectObject

Reconnect to the transport.


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

def reconnect; 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.


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

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.


90
91
92
93
94
# File 'lib/sensu/transport/base.rb', line 90

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.


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

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