Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
33 changes: 26 additions & 7 deletions ansible/library/snmp_facts.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,11 @@
required: false
is_dell:
description:
- Whether the bos is dell or not
- Whether the nos is dell or not
required: false
is_eos:
description:
- Whether the nos is eos or not
required: false
level:
description:
Expand Down Expand Up @@ -291,6 +295,7 @@ def main():
authkey=dict(required=False),
privkey=dict(required=False),
is_dell=dict(required=False, default=False, type='bool'),
is_eos=dict(required=False, default=False, type='bool'),
removeplaceholder=dict(required=False)),
required_together = ( ['username','level','integrity','authkey'],['privacy','privkey'],),
supports_check_mode=False)
Expand Down Expand Up @@ -371,8 +376,6 @@ def main():
cmdgen.MibVariable(p.sysContact,),
cmdgen.MibVariable(p.sysName,),
cmdgen.MibVariable(p.sysLocation,),
cmdgen.MibVariable(p.sysTotalMemery,),
cmdgen.MibVariable(p.sysTotalFreeMemery,),
lookupMib=False, lexicographicMode=False
)

Expand All @@ -392,10 +395,6 @@ def main():
results['ansible_sysname'] = current_val
elif current_oid == v.sysLocation:
results['ansible_syslocation'] = current_val
elif current_oid == v.sysTotalMemery:
results['ansible_sysTotalMemery'] = decode_type(module, current_oid, val)
elif current_oid == v.sysTotalFreeMemery:
results['ansible_sysTotalFreeMemery'] = decode_type(module, current_oid, val)

errorIndication, errorStatus, errorIndex, varTable = cmdGen.nextCmd(
snmp_auth,
Expand Down Expand Up @@ -849,6 +848,26 @@ def main():
psuIndex = int(current_oid.split('.')[-1])
results['snmp_psu'][psuIndex]['operstatus'] = current_val

if not m_args['is_eos']:
errorIndication, errorStatus, errorIndex, varBinds = cmdGen.getCmd(
snmp_auth,
cmdgen.UdpTransportTarget((m_args['host'], 161)),
cmdgen.MibVariable(p.sysTotalMemery,),
cmdgen.MibVariable(p.sysTotalFreeMemery,),
lookupMib=False, lexicographicMode=False
)

if errorIndication:
module.fail_json(msg=str(errorIndication) + ' querying system infomation.')

for oid, val in varBinds:
current_oid = oid.prettyPrint()
current_val = val.prettyPrint()
if current_oid == v.sysTotalMemery:
results['ansible_sysTotalMemery'] = decode_type(module, current_oid, val)
elif current_oid == v.sysTotalFreeMemery:
results['ansible_sysTotalFreeMemery'] = decode_type(module, current_oid, val)

module.exit_json(ansible_facts=results)

main()
2 changes: 1 addition & 1 deletion tests/test_nbr_health.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def test_neighbors_health(duthost, testbed_devices, eos):
nei_meta = config_facts.get('DEVICE_NEIGHBOR_METADATA', {})
for k, v in nei_meta.items():
logger.info("Check neighbor {}, mgmt ip {} snmp".format(k, v['mgmt_addr']))
res = localhost.snmp_facts(host=v['mgmt_addr'], version='v2c', community=eos['snmp_rocommunity'])
res = localhost.snmp_facts(host=v['mgmt_addr'], version='v2c', is_eos=True, community=eos['snmp_rocommunity'])
try:
snmp_data = res['ansible_facts']
except:
Expand Down