Skip to content

Commit

Permalink
Merge branch 'main' of git.scaleuptech.com:su_pub/ansible-utils
Browse files Browse the repository at this point in the history
  • Loading branch information
ScaleupTechnologies committed Jan 31, 2023
2 parents 6cea6bb + 4bec213 commit 72c6499
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
16 changes: 14 additions & 2 deletions plugins/modules/advanced_snmp_get.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# -*- coding: utf-8 -*-

from __future__ import (absolute_import, division, print_function)
from pprint import pprint
from pprint import pprint, pformat
from ansible.module_utils.basic import AnsibleModule
__metaclass__ = type

Expand Down Expand Up @@ -117,7 +117,7 @@ def snmp_fetch(handler, count, prefix_to_check=None):
if prefix_to_check is not None:
doit = (str(var_bind[0]).startswith(prefix_to_check))
if doit:
items[str(var_bind[0])] = str(var_bind[1])
items[str(var_bind[0])] = var_bind[1].prettyPrint()
if len(items.keys()) > 0:
result.append(items)
else:
Expand Down Expand Up @@ -166,6 +166,13 @@ def snmp_bulk_walk(target, bulk_block, credentials, port=161,
rtn_list.append(rtn)
return rtn_list

def int_to_mac(macint):
if type(macint) != int:
raise ValueError('invalid integer')
return ':'.join(['{}{}'.format(a, b)
for a, b
in zip(*[iter('{:012x}'.format(macint))]*2)])


def value_end_calc(value, field_dict):
dest_type = 'str'
Expand All @@ -175,6 +182,11 @@ def value_end_calc(value, field_dict):
value = int(value)
elif dest_type == 'float':
value = float(value)
elif dest_type == 'mac_address':
if value!='':
if not(value.startswith('0x')):
raise RuntimeError('Wrong macAddress Format %s'% value)
value = int_to_mac(int(value,base=16)).upper()
elif dest_type != 'str':
raise RuntimeError('Wrong type %s ' % dest_type)
if 'divide_by' in field_dict:
Expand Down
10 changes: 10 additions & 0 deletions test/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@
oid: "1.3.6.1.4.1.674.10892.5.4.600.12.1.14.1"
type: float
divide_by: 10
network:
mac_address:
oid: "1.3.6.1.4.1.674.10892.5.4.1100.90.1.16"
type: mac_address
fqdd:
oid: "1.3.6.1.4.1.674.10892.5.4.1100.90.1.30"
manufacturer:
oid: "1.3.6.1.4.1.674.10892.5.4.1100.90.1.7"
model:
oid: "1.3.6.1.4.1.674.10892.5.4.1100.90.1.6"
delegate_to: localhost

0 comments on commit 72c6499

Please sign in to comment.