class PuppetX::Eos::Snmp
The Snmp
class provides a base class instance for working with the global SNMP configuration
Public Class Methods
Public Instance Methods
Returns the SNMP hash representing global snmp configuration
Example
{ "contact": <String>, "location": <String>, "chassis_id": <String>, "source_interface": <String> }
@return [Array<Hash>] returns an Array of Hashes
# File lib/puppet_x/eos/modules/snmp.rb, line 66 def get result = @api.enable(['show snmp contact', 'show snmp location', 'show snmp chassis', 'show snmp source-interface'], format: 'text') attr_hash = {} (0..3).each do |i| m = /(?<=:\s)(.*)$/.match(result[i]['output']) case i when 0 attr_hash[:contact] = !m.nil? ? m[0] : '' when 1 attr_hash[:location] = !m.nil? ? m[0] : '' when 2 attr_hash[:chassis_id] = !m.nil? ? m[0] : '' when 3 attr_hash[:source_interface] = !m.nil? ? m[0] : '' end end attr_hash end
Configures the snmp chassis-id
@param [Hash] opts The configuration parameters for snmp @option opts [string] :value The value to set the chassis-id to @option opts [Boolean] :default The value should be set to default
@return [Boolean] True if the commands succeed otherwise False
# File lib/puppet_x/eos/modules/snmp.rb, line 141 def set_chassis_id(opts = {}) value = opts[:value] || false default = opts[:default] || false case default when true cmds = 'default snmp chassis' when false cmds = (value ? "snmp chassis #{value}" : 'no snmp chassis') end @api.config(cmds) == [{}] end
Configures the snmp contact
@param [Hash] opts The configuration parameters for snmp @option opts [string] :value The value to set the contact to @option opts [Boolean] :default The value should be set to default
@return [Boolean] True if the commands succeed otherwise False
# File lib/puppet_x/eos/modules/snmp.rb, line 99 def set_contact(opts = {}) value = opts[:value] || false default = opts[:default] || false case default when true cmds = 'default snmp contact' when false cmds = (value ? "snmp contact #{value}" : 'no snmp contact') end @api.config(cmds) == [{}] end
Configures the snmp location
@param [Hash] opts The configuration parameters for snmp @option opts [string] :value The value to set the location to @option opts [Boolean] :default The value should be set to default
@return [Boolean] True if the commands succeed otherwise False
# File lib/puppet_x/eos/modules/snmp.rb, line 120 def set_location(opts = {}) value = opts[:value] || false default = opts[:default] || false case default when true cmds = 'default snmp location' when false cmds = (value ? "snmp location #{value}" : 'no snmp location') end @api.config(cmds) == [{}] end
Configures the snmp source-interface
@param [Hash] opts The configuration parameters for snmp @option opts [string] :value The value to set the source-interface to @option opts [Boolean] :default The value should be set to default
@return [Boolean] True if the commands succeed otherwise False
# File lib/puppet_x/eos/modules/snmp.rb, line 162 def set_source_interface(opts = {}) value = opts[:value] || false default = opts[:default] || false case default when true cmds = 'default snmp source-interface' when false cmds = (value ? "snmp source-interface #{value}" : \ 'no snmp source-interface') end @api.config(cmds) == [{}] end