Class: Rbeapi::Api::Snmp
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.
Constant Summary collapse
- DEFAULT_SNMP_LOCATION =
''.freeze
- DEFAULT_SNMP_CONTACT =
''.freeze
- DEFAULT_SNMP_CHASSIS_ID =
''.freeze
- DEFAULT_SNMP_SOURCE_INTERFACE =
''.freeze
- CFG_TO_STATE =
{ 'default' => 'default', 'no' => 'off', nil => 'on' } .freeze
- STATE_TO_CFG =
{ 'default' => 'default', 'on' => nil, 'off' => 'no' } .freeze
Instance Attribute Summary
Attributes inherited from Entity
Instance Method Summary collapse
-
#add_community(name, access = 'ro') ⇒ Boolean
add_community adds a new snmp community to the nodes running configuration.
-
#get ⇒ Object
get returns the snmp resource Hash that represents the nodes snmp configuration abstraction from the running config.
-
#remove_community(name) ⇒ Boolean
remove_community removes the specified community from the nodes running configuration.
-
#set_chassis_id(opts = {}) ⇒ Boolean
set_chassis_id updates the snmp chassis id value in the nodes running configuration.
-
#set_community_access(name, access) ⇒ Boolean
set_community_access configures snmp-server community with designated name and access values.
-
#set_community_acl(name, opts = {}) ⇒ Boolean
set_community_acl configures the acl to apply to the specified community name.
-
#set_contact(opts = {}) ⇒ Boolean
set_contact updates the snmp contact value in the nodes running configuration.
-
#set_location(opts = {}) ⇒ Boolean
set_location updates the snmp location value in the nodes running configuration.
-
#set_notification(opts = {}) ⇒ Object
set_notification configures the snmp trap notification for the specified trap.
-
#set_source_interface(opts = {}) ⇒ Boolean
set_source_interface updates the snmp source interface value in the nodes running configuration.
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.
350 351 352 |
# File 'lib/rbeapi/api/snmp.rb', line 350 def add_community(name, access = 'ro') set_community_access(name, access) end |
#get ⇒ Object
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.
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>
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
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.
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>
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
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
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>
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
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 |