Method: Rbeapi::Netdev::Snmp#parse_snmp_hosts
- Defined in:
- lib/rbeapi/netdev/snmp.rb
#parse_snmp_hosts(text) ⇒ Array<Hash<Symbol,Object>>
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
parse_snmp_hosts parses the raw text from the ‘show snmp host` command and returns an Array of resource hashes.
99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/rbeapi/netdev/snmp.rb', line 99 def parse_snmp_hosts(text) re = /host: ([^\s]+)\s+.*?port: (\d+)\s+type: (\w+)\s*user: (.*?)\s+security model: (.*?)\n/m # rubocop:disable Metrics/LineLength text.scan(re).map do |(host, port, type, username, auth)| resource_hash = { name: host, ensure: :present, port: port.to_i } sec_match = /^v3 (\w+)/.match(auth) resource_hash[:security] = sec_match[1] if sec_match ver_match = /^(v\d)/.match(auth) # first 2 characters resource_hash[:version] = ver_match[1] if ver_match resource_hash[:type] = type =~ /trap/ ? :traps : :informs resource_hash[:username] = username resource_hash end end |