Class: Rbeapi::Api::Snmp

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

Overview

The Snmp class provides a class implementation for working with the nodes SNMP configuration entity. This class presents an abstraction of the node’s snmp configuration from the running config.

Since:

  • eos_version 4.13.7M

Constant Summary collapse

DEFAULT_SNMP_LOCATION =

Since:

  • eos_version 4.13.7M

''.freeze
DEFAULT_SNMP_CONTACT =

Since:

  • eos_version 4.13.7M

''.freeze
DEFAULT_SNMP_CHASSIS_ID =

Since:

  • eos_version 4.13.7M

''.freeze
DEFAULT_SNMP_SOURCE_INTERFACE =

Since:

  • eos_version 4.13.7M

''.freeze
CFG_TO_STATE =

Since:

  • eos_version 4.13.7M

{ 'default' => 'default', 'no' => 'off', nil => 'on' }
.freeze
STATE_TO_CFG =

Since:

  • eos_version 4.13.7M

{ 'default' => 'default', 'on' => nil, 'off' => 'no' }
.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_community(name, access = 'ro') ⇒ Boolean

add_community adds a new snmp community to the nodes running configuration. This function is a convenience function that passes the message to set_community_access.

Parameters:

  • name (String)

    The name of the snmp community to add to the nodes running configuration.

  • access (String) (defaults to: 'ro')

    Specifies the access level to assign to the new snmp community. Valid values are ‘rw’ or ‘ro’.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

See Also:

Since:

  • eos_version 4.13.7M



350
351
352
# File 'lib/rbeapi/api/snmp.rb', line 350

def add_community(name, access = 'ro')
  set_community_access(name, access)
end

#getObject

get returns the snmp resource Hash that represents the nodes snmp configuration abstraction from the running config.

@return[Hash<Symbol, Object>] Returns the snmp resource as a Hash.

Examples:

{
  location: <string>,
  contact: <string>,
  chassis_id: <string>,
  source_interface: <string>
}

Since:

  • eos_version 4.13.7M



69
70
71
72
73
74
75
76
77
78
# File 'lib/rbeapi/api/snmp.rb', line 69

def get
  response = {}
  response.merge!(parse_location)
  response.merge!(parse_contact)
  response.merge!(parse_chassis_id)
  response.merge!(parse_source_interface)
  response.merge!(parse_communities)
  response.merge!(parse_notifications)
  response
end

#remove_community(name) ⇒ Boolean

remove_community removes the specified community from the nodes running configuration. If the specified name is not configured, this method will still return successfully.

Commands

no snmp-server community <name>

Parameters:

  • name (String)

    The name of the snmp community to add to the nodes running configuration.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



368
369
370
# File 'lib/rbeapi/api/snmp.rb', line 368

def remove_community(name)
  configure "no snmp-server community #{name}"
end

#set_chassis_id(opts = {}) ⇒ Boolean

set_chassis_id updates the snmp chassis id value in the nodes running configuration. If enable is false in the opts Hash then the snmp chassis id value is negated using the no keyword. If the default keyword is set to true, then the snmp chassis id value is defaulted using the default keyword. The default keyword takes precedence over the enable keyword.

Commands

snmp-server chassis-id <value>
no snmp-server chassis-id
default snmp-server chassis-id

Parameters:

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

    The configuration parameters

Options Hash (opts):

  • value (string)

    The snmp chassis id value to configure

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configures the snmp chassis id value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



300
301
302
303
# File 'lib/rbeapi/api/snmp.rb', line 300

def set_chassis_id(opts = {})
  cmd = command_builder('snmp-server chassis-id', opts)
  configure(cmd)
end

#set_community_access(name, access) ⇒ Boolean

set_community_access configures snmp-server community with designated

name and access values.

Parameters:

  • name (String)

    The snmp-server community name value.

  • access (String)

    The snmp-server community access value.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



421
422
423
# File 'lib/rbeapi/api/snmp.rb', line 421

def set_community_access(name, access)
  configure "snmp-server community #{name} #{access}"
end

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

set_community_acl configures the acl to apply to the specified community name. When enable is true, it will remove the the named community and then add the new acl entry.

Commands

no snmp-server <name> [ro|rw] <value>
snmp-server <name> [ro|rw] <value>

Parameters:

  • name (String)

    The name of the snmp community to add to the nodes running configuration.

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

    The configuration parameters.

Options Hash (opts):

  • value (String)

    The name of the acl to apply to the snmp community in the nodes config. If nil, then the community name allows access to all objects.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configure the snmp community name using the default keyword. Default takes precedence over enable.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



399
400
401
402
403
404
405
406
407
408
409
410
# File 'lib/rbeapi/api/snmp.rb', line 399

def set_community_acl(name, opts = {})
  value = opts[:value]
  enable = opts.fetch(:enable, true)
  default = opts.fetch(:default, false)
  # Default is same as negate for this command
  enable = default ? false : enable
  communities = parse_communities[:communities]
  access = communities[name][:access] if communities.include?(name)
  cmds = ["no snmp-server community #{name}"]
  cmds << "snmp-server community #{name} #{access} #{value}" if enable
  configure cmds
end

#set_contact(opts = {}) ⇒ Boolean

set_contact updates the snmp contact value in the nodes running configuration. If enable is false in the opts Hash then the snmp contact value is negated using the no keyword. If the default keyword is set to true, then the snmp contact value is defaulted using the default keyword. The default parameter takes precedence over the enable keyword.

Commands

snmp-server contact <value>
no snmp-server contact
default snmp-server contact

Parameters:

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

    The configuration parameters.

Options Hash (opts):

  • value (string)

    The snmp contact value to configure.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configures the snmp contact value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



269
270
271
272
# File 'lib/rbeapi/api/snmp.rb', line 269

def set_contact(opts = {})
  cmd = command_builder('snmp-server contact', opts)
  configure(cmd)
end

#set_location(opts = {}) ⇒ Boolean

set_location updates the snmp location value in the nodes running configuration. If enable is false, then the snmp location value is negated using the no keyword. If the default keyword is set to true, then the snmp location value is defaulted using the default keyword. The default parameter takes precedence over the enable keyword.

Commands

snmp-server location <value>
no snmp-server location
default snmp-server location

Parameters:

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

    The configuration parameters.

Options Hash (opts):

  • value (string)

    The snmp location value to configure.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configure the snmp location value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



238
239
240
241
# File 'lib/rbeapi/api/snmp.rb', line 238

def set_location(opts = {})
  cmd = command_builder('snmp-server location', opts)
  configure(cmd)
end

#set_notification(opts = {}) ⇒ Object

set_notification configures the snmp trap notification for the specified trap. The name option accepts the snmp trap name to configure or the keyword all to globally enable or disable notifications. If the optional state argument is not provided then the default state is default.

Commands

snmp-server enable traps <name>
no snmp-server enable traps <name>
default snmp-server enable traps <name>

Parameters:

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

    The configuration parameters.

Options Hash (opts):

  • name (String)

    The name of the trap to configure or the keyword all. If this option is not specified, then the value of ‘all’ is used as the default.

  • state (String)

    The state to configure the trap notification. Valid values include ‘on’, ‘off’ or ‘default’.

Since:

  • eos_version 4.13.7M



205
206
207
208
209
210
211
# File 'lib/rbeapi/api/snmp.rb', line 205

def set_notification(opts = {})
  name = opts[:name]
  name = nil if name == 'all'
  state = opts[:state] || 'default'
  state = STATE_TO_CFG[state]
  configure "#{state} snmp-server enable traps #{name}"
end

#set_source_interface(opts = {}) ⇒ Boolean

set_source_interface updates the snmp source interface value in the nodes running configuration. If enable is false in the opts Hash then the snmp source interface is negated using the no keyword. If the default keyword is set to true, then the snmp source interface value is defaulted using the default keyword. The default keyword takes precedence over the enable keyword.

Commands

snmp-server source-interface <value>
no snmp-server source-interface
default snmp-server source-interface

Parameters:

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

    The configuration parameters.

Options Hash (opts):

  • value (string)

    The snmp source interface value to configure. This method will not ensure the interface is present in the configuration.

  • enable (Boolean)

    If false then the command is negated. Default is true.

  • default (Boolean)

    Configures the snmp source interface value using the default keyword.

Returns:

  • (Boolean)

    Returns true if the command completed successfully.

Since:

  • eos_version 4.13.7M



331
332
333
334
# File 'lib/rbeapi/api/snmp.rb', line 331

def set_source_interface(opts = {})
  cmd = command_builder('snmp-server source-interface', opts)
  configure(cmd)
end