Skip to content

Commit

Permalink
Add warning if no MAC was found but requested as identifier
Browse files Browse the repository at this point in the history
  • Loading branch information
ribetm committed Jan 21, 2025
1 parent d53e650 commit 777100b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 1 deletion.
2 changes: 1 addition & 1 deletion netbox_agent/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ def get_config():
"--network.nic_id",
choices=("name", "mac"),
default="name",
help="What property to use as NIC identifier. Always fallback to name if choice is not available",
help="What property to use as NIC identifier",
)
p.add_argument(
"--network.primary_mac",
Expand Down
4 changes: 4 additions & 0 deletions netbox_agent/network.py
Original file line number Diff line number Diff line change
Expand Up @@ -435,10 +435,14 @@ def create_or_update_netbox_ip_on_interface(self, ip, interface):
def _nic_identifier(self, nic):
if isinstance(nic, dict):
if config.network.nic_id == "mac":
if not nic["mac"]:
logging.warning("MAC not available while trying to use it as the NIC identifier")
return nic["mac"]
return nic["name"]
else:
if config.network.nic_id == "mac":
if not nic.mac_address:
logging.warning("MAC not available while trying to use it as the NIC identifier")
return nic.mac_address
return nic.name

Expand Down

0 comments on commit 777100b

Please sign in to comment.