Class: PuppetX::Eos::Snmp

Inherits:
Object
  • Object
show all
Defined in:
lib/puppet_x/eos/modules/snmp.rb

Overview

The Snmp class provides a base class instance for working with the global SNMP configuration

Instance Method Summary collapse

Constructor Details

#initialize(api) ⇒ PuppetX::Eos::Snmp

Initialize instance of Snmp

Parameters:



50
51
52
# File 'lib/puppet_x/eos/modules/snmp.rb', line 50

def initialize(api)
  @api = api
end

Instance Method Details

#getArray<Hash>

Returns the SNMP hash representing global snmp configuration

Example

{
  "contact": <String>,
  "location": <String>,
  "chassis_id": <String>,
  "source_interface": <String>
}

Returns:

  • (Array<Hash>)

    returns an Array of Hashes



66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# 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

#set_chassis_id(opts = {}) ⇒ Boolean

Configures the snmp chassis-id

Parameters:

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

    The configuration parameters for snmp

Options Hash (opts):

  • :value (string)

    The value to set the chassis-id to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



141
142
143
144
145
146
147
148
149
150
151
152
# 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

#set_contact(opts = {}) ⇒ Boolean

Configures the snmp contact

Parameters:

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

    The configuration parameters for snmp

Options Hash (opts):

  • :value (string)

    The value to set the contact to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



99
100
101
102
103
104
105
106
107
108
109
110
# 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

#set_location(opts = {}) ⇒ Boolean

Configures the snmp location

Parameters:

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

    The configuration parameters for snmp

Options Hash (opts):

  • :value (string)

    The value to set the location to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



120
121
122
123
124
125
126
127
128
129
130
131
# 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

#set_source_interface(opts = {}) ⇒ Boolean

Configures the snmp source-interface

Parameters:

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

    The configuration parameters for snmp

Options Hash (opts):

  • :value (string)

    The value to set the source-interface to

  • :default (Boolean)

    The value should be set to default

Returns:

  • (Boolean)

    True if the commands succeed otherwise False



162
163
164
165
166
167
168
169
170
171
172
173
174
# 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