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 =
''- DEFAULT_SNMP_CONTACT =
''- DEFAULT_SNMP_CHASSIS_ID =
''- DEFAULT_SNMP_SOURCE_INTERFACE =
''- CFG_TO_STATE =
{ 'default' => 'default', 'no' => 'off', nil => 'on' }
- STATE_TO_CFG =
{ 'default' => 'default', 'on' => nil, 'off' => 'no' }
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.
346 347 348 |
# File 'lib/rbeapi/api/snmp.rb', line 346 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
67 68 69 70 71 72 73 74 75 76 |
# File 'lib/rbeapi/api/snmp.rb', line 67 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.
364 365 366 |
# File 'lib/rbeapi/api/snmp.rb', line 364 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.
296 297 298 299 |
# File 'lib/rbeapi/api/snmp.rb', line 296 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.
415 416 417 |
# File 'lib/rbeapi/api/snmp.rb', line 415 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.
393 394 395 396 397 398 399 400 401 402 403 404 |
# File 'lib/rbeapi/api/snmp.rb', line 393 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.
265 266 267 268 |
# File 'lib/rbeapi/api/snmp.rb', line 265 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.
234 235 236 237 |
# File 'lib/rbeapi/api/snmp.rb', line 234 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.
201 202 203 204 205 206 207 |
# File 'lib/rbeapi/api/snmp.rb', line 201 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.
327 328 329 330 |
# File 'lib/rbeapi/api/snmp.rb', line 327 def set_source_interface(opts = {}) cmd = command_builder('snmp-server source-interface', opts) configure(cmd) end |