Class: Rbeapi::Api::Logging

Inherits:
Entity
  • Object
show all
Defined in:
lib/rbeapi/api/logging.rb

Overview

The Logging class manages logging settings on an EOS node.

Constant Summary collapse

SEV_NUM =
{
  'emergencies' => 0,
  'alerts' => 1,
  'critical' => 2,
  'errors' => 3,
  'warnings' => 4,
  'notifications' => 5,
  'informational' => 6,
  'debugging' => 7
}.freeze

Instance Attribute Summary

Attributes inherited from Entity

#config, #error, #node

Instance Method Summary collapse

Methods inherited from Entity

#command_builder, #configure, #configure_interface, #get_block, #initialize, instance

Constructor Details

This class inherits a constructor from Rbeapi::Api::Entity

Instance Method Details

#add_host(name, opts = {}) ⇒ Boolean

add_host configures a new logging destination host address or hostname to the list of logging destinations. If the host is already configured in the list of destinations, this method will return successfully.

Commands

logging host <name>

Parameters:

  • name (String)

    The host name or ip address of the destination node to send logging information to.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



331
332
333
334
335
336
337
# File 'lib/rbeapi/api/logging.rb', line 331

def add_host(name, opts = {})
  vrf = opts[:vrf] ? "vrf #{opts[:vrf]} " : ''
  cmd = "logging #{vrf}host #{name}"
  cmd += " #{opts[:port]}" if opts[:port]
  cmd += " protocol #{opts[:protocol]}" if opts[:protocol]
  configure cmd
end

#getHash<Symbol, Object>

get returns the current logging configuration hash extracted from the nodes running configuration.

Examples:

{
  enable: [true, false],
  hosts: array<strings>
}

Returns:

  • (Hash<Symbol, Object>)

    Returns the logging resource as a hash object from the nodes current configuration.



65
66
67
68
69
70
71
72
73
74
# File 'lib/rbeapi/api/logging.rb', line 65

def get
  response = {}
  response.merge!(parse_enable)
  response.merge!(parse_console_level)
  response.merge!(parse_monitor_level)
  response.merge!(parse_timestamp_units)
  response.merge!(parse_source)
  response.merge!(parse_hosts)
  response
end

#remove_host(name, opts = {}) ⇒ Boolean

remove_host deletes a logging destination host name or address form the list of logging destinations. If the host is not in the list of configured hosts, this method will still return successfully.

Commands

no logging host <name>

Parameters:

  • name (String)

    The host name or ip address of the destination host to remove from the nodes current configuration.

Returns:

  • (Boolean)

    Returns true if the commands completed successfully.

Since:

  • eos_version 4.13.7M



353
354
355
356
357
358
# File 'lib/rbeapi/api/logging.rb', line 353

def remove_host(name, opts = {})
  vrf = opts[:vrf] ? "vrf #{opts[:vrf]} " : ''
  # Hosts are uniquely identified by vrf and address, alone.
  cmd = "no logging #{vrf}host #{name}"
  configure cmd
end

#set_console(opts = {}) ⇒ Boolean

set_console configures the global logging level for the console. If the default keyword is specified and set to true, then the configuration is defaulted using the default keyword. The default keyword option takes precedence over the enable keyword if both options are specified.

Commands

logging console <level>
no logging console <level>
default logging console

Parameters:

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

    Optional keyword arguments

Options Hash (opts):

  • level (Int|String)

    Enables logging at the specified level. Accepts <0-7> and logging level keywords.

  • default (Boolean)

    Resets the monitor level to the default.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



242
243
244
245
246
247
# File 'lib/rbeapi/api/logging.rb', line 242

def set_console(opts = {})
  cmd = 'logging console'
  cmd += " #{opts[:level]}" if opts[:level]
  cmd = command_builder(cmd, opts)
  configure cmd
end

#set_enable(opts = {}) ⇒ Boolean

set_enable configures the global logging instance on the node as either enabled or disabled. If the enable keyword is set to true then logging is globally enabled and if set to false, it is globally disabled. If the default keyword is specified and set to true, then the configuration is defaulted using the default keyword. The default keyword option takes precedence over the enable keyword if both options are specified.

Commands

logging on
no logging on
default logging on

Parameters:

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

    Optional keyword arguments

Options Hash (opts):

  • enable (Boolean)

    Enables logging globally if value is true or disabled logging globally if value is false.

  • default (Boolean)

    Configure the ip address value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



214
215
216
217
# File 'lib/rbeapi/api/logging.rb', line 214

def set_enable(opts = {})
  cmd = command_builder('logging on', opts)
  configure cmd
end

#set_monitor(opts = {}) ⇒ Boolean

set_monitor configures the global logging level for terminals If the default keyword is specified and set to true, then the configuration is defaulted using the default keyword. The default keyword option takes precedence over the enable keyword if both options are specified.

Commands

logging monitor <level>
no logging monitor <level>
default logging monitor

Parameters:

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

    Optional keyword arguments

Options Hash (opts):

  • level (Int|String)

    Enables logging at the specified level. Accepts <0-7> and logging level keywords.

  • default (Boolean)

    Resets the monitor level to the default.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



272
273
274
275
276
277
# File 'lib/rbeapi/api/logging.rb', line 272

def set_monitor(opts = {})
  cmd = 'logging monitor'
  cmd += " #{opts[:level]}" if opts[:level]
  cmd = command_builder(cmd, opts)
  configure cmd
end

#set_time_stamp_units(opts = {}) ⇒ Boolean

set_time_stamp_units configures the global logging time_stamp_units If the default keyword is specified and set to true, then the configuration is defaulted using the default keyword. The default keyword option takes precedence over the enable keyword if both options are specified.

Commands

logging format timestamp <traditional|high-resolution>
no logging format timestamp <level>
default logging format timestamp

Parameters:

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

    Optional keyword arguments

Options Hash (opts):

  • units (String)

    Enables logging timestamps with the specified units. One of ‘traditional’ | ‘seconds’ or ‘high-resolution’ | ‘milliseconds’

  • default (Boolean)

    Resets the logging timestamp level to the default.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



303
304
305
306
307
308
309
310
311
312
313
314
315
# File 'lib/rbeapi/api/logging.rb', line 303

def set_time_stamp_units(opts = {})
  unit_map = {
    'traditional' => ' traditional',
    'seconds' => ' traditional',
    'high-resolution' => ' high-resolution',
    'milliseconds' => ' high-resolution'
  }
  units = ''
  units = unit_map[opts[:units]] if opts[:units]
  cmd = "logging format timestamp#{units}"
  cmd = command_builder(cmd, opts)
  configure cmd
end