Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[change] NetJSON DeviceMonitoring compliance #2 #62

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions netengine/backends/snmp/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import binascii
import logging

import netaddr

from netengine.backends import BaseBackend
from netengine.exceptions import NetEngineError

Expand Down Expand Up @@ -57,6 +59,20 @@ def _octet_to_mac(self, octet_mac):
)
return mac_address

def _ascii_blocks_to_ipv6(self, ascii_string):
purhan marked this conversation as resolved.
Show resolved Hide resolved
"""
converts an ascii representation into ipv6 address
"""
blocks = ascii_string.split('.')
for b in range(len(blocks)):
blocks[b] = format(int(blocks[b]), '02x')
res = netaddr.IPAddress(
':'.join(
[''.join(blocks[slice(i, i + 2)]) for i in range(0, len(blocks), 2)]
)
)
return res
purhan marked this conversation as resolved.
Show resolved Hide resolved

def _oid(self, oid):
"""
returns valid oid value to be passed to getCmd() or nextCmd()
Expand Down
12 changes: 11 additions & 1 deletion netengine/backends/snmp/openwrt.py
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,11 @@ def neighbors(self):

for index, neighbor in enumerate(neighbors):
try:
oid = neighbor[0][0].getOid()
if oid[12] == 4:
ip = oid[13:]
else:
ip = self._ascii_blocks_to_ipv6(str(oid[13:]))
mac = EUI(
int(neighbor[0][1].prettyPrint(), 16), dialect=mac_unix_expanded
)
Expand All @@ -517,7 +522,12 @@ def neighbors(self):
continue
result.append(
self._dict(
{'mac': str(mac), 'state': str(state), 'interface': str(interface)}
{
'mac': str(mac),
'state': str(state),
'interface': str(interface),
'ip': str(ip),
}
)
)
return result
Expand Down