Class: Cisco::SnmpNotificationReceiver

Inherits:
NodeUtil
  • Object
show all
Defined in:
lib/cisco_node_utils/snmp_notification_receiver.rb

Overview

SnmpNotificationReceiver - node utility class for SNMP server management

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from NodeUtil

config_get, #config_get, config_get_default, #config_get_default, #config_set, config_set, #node, node, #show

Constructor Details

#initialize(name, instantiate: true, type: '', version: '', security: '', username: '', port: '', vrf: '', source_interface: '') ⇒ SnmpNotificationReceiver

Returns a new instance of SnmpNotificationReceiver.



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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/cisco_node_utils/snmp_notification_receiver.rb', line 24

def initialize(name,
               instantiate:      true,
               type:             '',
               version:          '',
               security:         '',
               username:         '',
               port:             '',
               vrf:              '',
               source_interface: '')

  fail TypeError unless name.is_a?(String)
  @name = name

  fail TypeError unless type.is_a?(String)

  fail TypeError unless version.is_a?(String) || version.is_a?(Integer)

  fail TypeError unless security.is_a?(String)

  fail TypeError unless username.is_a?(String)

  fail TypeError unless port.is_a?(String) || port.is_a?(Integer)

  fail TypeError unless vrf.is_a?(String)

  fail TypeError unless source_interface.is_a?(String)

  return unless instantiate

  # Mandatory Properties
  fail TypeError unless name.length > 0
  fail TypeError unless type.length > 0

  if version.is_a?(Integer)
    fail TypeError if version <= 0
  else
    fail TypeError if version.length <= 0
  end

  fail TypeError unless username.length > 0

  config_set('snmp_notification_receiver',
             'receivers',
             state:    '',
             ip:       name,
             type:     type,
             version:  version,
             security: security,
             username: username,
             udp_port: port.empty? ? '' : "udp-port #{port}")

  unless source_interface.empty?
    config_set('snmp_notification_receiver',
               'source_interface',
               ip:               name,
               source_interface: source_interface,
               port:             port.empty? ? '' : "udp-port #{port}")
  end

  return if vrf.empty?
  config_set('snmp_notification_receiver',
             'vrf',
             ip:   name,
             vrf:  vrf,
             port: port.empty? ? '' : "udp-port #{port}")
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



22
23
24
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 22

def name
  @name
end

Class Method Details

.receiversObject



91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 91

def self.receivers
  hash = {}

  receivers_list = config_get('snmp_notification_receiver', 'receivers')
  return hash if receivers_list.nil?

  receivers_list.each do |arr|
    next if !arr.is_a?(Array) || arr.empty?
    id = arr[0]
    hash[id] = SnmpNotificationReceiver.new(id, instantiate: false)
  end

  hash
end

Instance Method Details

#==(other) ⇒ Object



106
107
108
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 106

def ==(other)
  name == other.name
end

#destroyObject



110
111
112
113
114
115
116
117
118
119
120
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 110

def destroy
  config_set('snmp_notification_receiver',
             'receivers',
             state:    'no',
             ip:       name,
             type:     type,
             version:  version,
             security: security.nil? ? '' : "#{security}",
             username: username,
             udp_port: port.nil? ? '' : "udp-port #{port}")
end

#portObject



122
123
124
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 122

def port
  config_get('snmp_notification_receiver', 'port', @name)
end

#securityObject



144
145
146
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 144

def security
  config_get('snmp_notification_receiver', 'security', @name)
end

#source_interfaceObject



152
153
154
155
156
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 152

def source_interface
  val = config_get('snmp_notification_receiver', 'source_interface', @name)
  val = val.downcase unless val.nil?
  val
end

#typeObject



140
141
142
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 140

def type
  config_get('snmp_notification_receiver', 'type', @name)
end

#usernameObject



126
127
128
129
130
131
132
133
134
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 126

def username
  if !port.nil?
    endpoint = 'username_with_port'
  else
    endpoint = 'username'
  end

  config_get('snmp_notification_receiver', endpoint, @name)
end

#versionObject



136
137
138
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 136

def version
  config_get('snmp_notification_receiver', 'version', @name)
end

#vrfObject



148
149
150
# File 'lib/cisco_node_utils/snmp_notification_receiver.rb', line 148

def vrf
  config_get('snmp_notification_receiver', 'vrf', @name)
end