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.

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) ⇒ 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.

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



127
128
129
# File 'lib/rbeapi/api/logging.rb', line 127

def add_host(name)
  configure "logging host #{name}"
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



55
56
57
58
59
60
# File 'lib/rbeapi/api/logging.rb', line 55

def get
  response = {}
  response.merge!(parse_enable)
  response.merge!(parse_hosts)
  response
end

#parse_enableObject

parse_enable scans the nodes current running configuration and extracts the current enabled state of the logging facility. The logging enable command is expected to always be in the node’s configuration. This methods return value is intended to be merged into the logging resource hash.



68
69
70
71
# File 'lib/rbeapi/api/logging.rb', line 68

def parse_enable
  value = /no logging on/ !~ config
  { enable: value }
end

#parse_hostsObject

parse_hosts scans the nodes current running configuration and extracts the configured logging host destinations if any are configured. If no logging hosts are configured, then the value for hosts will be an empty array. The return value is intended to be merged into the logging resource hash



79
80
81
82
# File 'lib/rbeapi/api/logging.rb', line 79

def parse_hosts
  hosts = config.scan(/(?<=^logging\shost\s)[^\s]+/)
  { hosts: hosts }
end

#remove_host(name) ⇒ 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.

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



145
146
147
# File 'lib/rbeapi/api/logging.rb', line 145

def remove_host(name)
  configure "no logging host #{name}"
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.

Parameters:

  • :opts (Hash)

    Optional keyword arguments

Returns:

  • (Boolean)

    returns true if the command completed successfully



108
109
110
111
# File 'lib/rbeapi/api/logging.rb', line 108

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