From 34f18c0b0188db3c8af369a3b0e3a4ab5508b041 Mon Sep 17 00:00:00 2001 From: shbatm Date: Mon, 19 Jan 2026 14:12:40 -0600 Subject: [PATCH] Move debug print before netbox_create_or_update and document Previously, if an error occurred during netbox_create_or_update(), the debug information would never be printed since print_debug() was called after the update. This moves the debug print to occur before the update attempt, ensuring debug data is visible even when errors occur. Also adds documentation for the --debug flag which was previously undocumented in both README.md and the example config file. Co-Authored-By: Claude Sonnet 4.5 --- README.md | 23 +++++++++++++++++++++++ netbox_agent.yaml.example | 5 +++++ netbox_agent/cli.py | 4 ++-- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index f7c66ae5..86cd94bf 100644 --- a/README.md +++ b/README.md @@ -85,6 +85,29 @@ INFO:root:Create new IP 42.42.42.43/24 on enp1s0f1 INFO:root:Creating Disk Samsung SSD 850 S2RBNX0K101698D ``` +## Debug Mode + +The `--debug` flag prints detailed information about the device before attempting to create or update it in Netbox. This is useful for troubleshooting issues or verifying what data will be sent to Netbox. + +``` +# netbox_agent -c /etc/netbox_agent.yaml --debug --register +Datacenter: dc-1 +Netbox Datacenter: dc-1 +Rack: rack-01 +Netbox Rack: rack-01 +Is blade: False +Got expansion: False +Product Name: ProLiant DL380 Gen10 +Platform: x86-64 +Chassis: Default string +Chassis service tag: 2M25XX0020 +Service tag: 2M25XX0020 +NIC: +[{'name': 'eno1', 'mac': 'a8:1e:84:f2:9e:69', ...}, ...] +INFO:root:Creating chassis blade (serial: QTFCQ574502EF) +... +``` + # Configuration ``` diff --git a/netbox_agent.yaml.example b/netbox_agent.yaml.example index a1a8e028..609b2532 100644 --- a/netbox_agent.yaml.example +++ b/netbox_agent.yaml.example @@ -51,3 +51,8 @@ rack_location: # regex: '.*-(\d+)' inventory: true + +# Enable debug mode to print detailed device information +# This is useful for troubleshooting before registration or updates +# Same as using the --debug or -d command line flag +# debug: true diff --git a/netbox_agent/cli.py b/netbox_agent/cli.py index f277533e..3455b0de 100644 --- a/netbox_agent/cli.py +++ b/netbox_agent/cli.py @@ -45,6 +45,8 @@ def run(config): print("netbox-agent is not compatible with Netbox prior to version 3.7") return 1 + if config.debug: + server.print_debug() if ( config.register or config.update_all @@ -54,8 +56,6 @@ def run(config): or config.update_psu ): server.netbox_create_or_update(config) - if config.debug: - server.print_debug() return 0