Skip to content

Commit

Permalink
continue parsing even if the command return is different from 0
Browse files Browse the repository at this point in the history
  • Loading branch information
clbu committed Oct 17, 2024
1 parent 3a2bb85 commit 1a1574c
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions netbox_agent/ipmi.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ class IPMI():
def __init__(self):
self.ret, self.output = subprocess.getstatusoutput('ipmitool lan print')
if self.ret != 0:
logging.error('Cannot get ipmi info: {}'.format(self.output))
logging.warning('IPMI command failed: {}'.format(self.output))

def parse(self):
_ipmi = {}
if self.ret != 0:
return _ipmi

for line in self.output.splitlines():
key = line.split(':')[0].strip()
Expand All @@ -57,11 +55,15 @@ def parse(self):
ret['name'] = 'IPMI'
ret["mtu"] = 1500
ret['bonding'] = False
ret['mac'] = _ipmi['MAC Address']
ret['vlan'] = int(_ipmi['802.1q VLAN ID']) \
if _ipmi['802.1q VLAN ID'] != 'Disabled' else None
ip = _ipmi['IP Address']
netmask = _ipmi['Subnet Mask']
try:
ret['mac'] = _ipmi['MAC Address']
ret['vlan'] = int(_ipmi['802.1q VLAN ID']) \
if _ipmi['802.1q VLAN ID'] != 'Disabled' else None
ip = _ipmi['IP Address']
netmask = _ipmi['Subnet Mask']
except KeyError as e:
logging.error("IPMI decoding failed, missing: ", e.args[0])
return {}
address = str(IPNetwork('{}/{}'.format(ip, netmask)))

ret['ip'] = [address]
Expand Down

0 comments on commit 1a1574c

Please sign in to comment.