Class: Rbeapi::Api::Snmp
Overview
The Snmp class provides a class implementation for working with the nodes SNMP conifguration 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) ⇒ Object
-
#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 notificaiton 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
#configure, #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.
373 374 375 |
# File 'lib/rbeapi/api/snmp.rb', line 373 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
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rbeapi/api/snmp.rb', line 68 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.
391 392 393 |
# File 'lib/rbeapi/api/snmp.rb', line 391 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 the value is not provided 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 value keyword.
307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/rbeapi/api/snmp.rb', line 307 def set_chassis_id(opts = {}) value = opts[:value] default = opts[:default] || false case default when true cmds = 'default snmp-server chassis-id' when false cmds = (value.nil? ? "no snmp-server chassis-id" : \ "snmp-server chassis-id #{value}") end configure(cmds) end |
#set_community_access(name, access) ⇒ Object
422 423 424 |
# File 'lib/rbeapi/api/snmp.rb', line 422 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. If the value option is not specified, the acl is removed from the community name
413 414 415 416 417 418 419 420 |
# File 'lib/rbeapi/api/snmp.rb', line 413 def set_community_acl(name, opts = {}) value = opts[:value] communities = parse_communities[:communities] access = communities[name][:access] if communities.include?(name) cmds = ["no snmp-server community #{name}", "snmp-server community #{name} #{access} #{value}"] configure cmds end |
#set_contact(opts = {}) ⇒ Boolean
set_contact updates the snmp contact value in the nodes running configuration. If the value is not provided 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 value keyword.
270 271 272 273 274 275 276 277 278 279 280 281 282 |
# File 'lib/rbeapi/api/snmp.rb', line 270 def set_contact(opts = {}) value = opts[:value] default = opts[:default] || false case default when true cmds = ['default snmp-server contact'] when false cmds = (value.nil? ? "no snmp-server contact" : \ "snmp-server contact #{value}") end configure(cmds) end |
#set_location(opts = {}) ⇒ Boolean
set_location updates the snmp location value in the nodes running configuration. If the value is not provided in the opts Hash 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 value keyword.
233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'lib/rbeapi/api/snmp.rb', line 233 def set_location(opts = {}) value = opts[:value] default = opts[:default] || false case default when true cmds = ['default snmp-server location'] when false cmds = (value.nil? ? "no snmp-server location" : \ "snmp-server location #{value}") end configure(cmds) end |
#set_notification(opts = {}) ⇒ Object
set_notification configures the snmp trap notificaiton 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.
202 203 204 205 206 207 208 |
# File 'lib/rbeapi/api/snmp.rb', line 202 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 the value is not provided in the opts Hash then the snmp source interface is negated using the no keyword. If the deafult keyword is set to true, then the snmp source interface value is defaulted using the default keyword. The deafult keyword takes precedence over the value keyword.
345 346 347 348 349 350 351 352 353 354 355 356 357 |
# File 'lib/rbeapi/api/snmp.rb', line 345 def set_source_interface(opts = {}) value = opts[:value] default = opts[:default] || false case default when true cmds = ['default snmp-server source-interface'] when false cmds = (value.nil? ? "no snmp-server source-interface" : \ "snmp-server source-interface #{value}") end configure(cmds) end |