From 9dafd4b4ebb9d916df4b1ed6803d22b11fd41dc2 Mon Sep 17 00:00:00 2001 From: pavel Date: Thu, 23 Oct 2025 17:57:39 +0300 Subject: [PATCH 1/3] first commit --- files/empty_file | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 files/empty_file diff --git a/files/empty_file b/files/empty_file new file mode 100644 index 0000000..e69de29 From 432dab483fee82818b8ec11b941ea82910eae864 Mon Sep 17 00:00:00 2001 From: pavel Date: Thu, 23 Oct 2025 18:02:46 +0300 Subject: [PATCH 2/3] 1802 --- files/empty_file | 1 + 1 file changed, 1 insertion(+) diff --git a/files/empty_file b/files/empty_file index e69de29..5e40c08 100644 --- a/files/empty_file +++ b/files/empty_file @@ -0,0 +1 @@ +asdf \ No newline at end of file From 80a8b22a35f5e2b9c4fb91220af8ad1194b40a90 Mon Sep 17 00:00:00 2001 From: pavel Date: Sat, 25 Oct 2025 08:38:10 +0300 Subject: [PATCH 3/3] 0838 --- files/netbox-reporter.sh | 45 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/files/netbox-reporter.sh b/files/netbox-reporter.sh index 784fd70..93e42ac 100644 --- a/files/netbox-reporter.sh +++ b/files/netbox-reporter.sh @@ -55,9 +55,30 @@ nb_find_device_id() { jq -r '.results[0].id // empty' <<<"$resp" } +# --- READ a custom field value for a device (prints current value or empty if unset) --- +nb_read_custom_field() { + local dev_id="$1" key="$2" + local resp + resp="$(curl -sS \ + -H "Authorization: Token $NB_TOKEN" \ + -H "Accept: application/json" \ + "$NB_URL/api/dcim/devices/$dev_id/")" || return 1 + jq -r --arg k "$key" ' + (.custom_fields[$k] // empty) + | (if type=="object" or type=="array" then tojson else . end) + ' <<<"$resp" +} + # PATCH NetBox custom fields (update_wo_restart) nb_patch_update_wo_restart() { local dev_id="$1" update_progress="$2" updating_to="$3" + + # Pre-read current values and print + local prev_p prev_u + prev_p="$(nb_read_custom_field "$dev_id" "update_progress" || true)" + prev_u="$(nb_read_custom_field "$dev_id" "updating_to" || true)" + echo ">>> Pre-change (id=$dev_id): update_progress='${prev_p:-}'; updating_to='${prev_u:-}'" + local body body="$(jq -n --arg p "$update_progress" --arg u "$updating_to" \ '{custom_fields: {update_progress: $p, updating_to: $u}}')" @@ -81,6 +102,12 @@ nb_patch_update_wo_restart() { # PATCH NetBox custom field: wifidebug (deploy_wifidebug) nb_patch_wifidebug() { local dev_id="$1" value="$2" + + # Pre-read current value and print + local prev + prev="$(nb_read_custom_field "$dev_id" "wifidebug" || true)" + echo ">>> Pre-change (id=$dev_id): wifidebug='${prev:-}'" + local body body="$(jq -n --arg v "$value" '{custom_fields: {wifidebug: $v}}')" @@ -150,6 +177,12 @@ nb_add_journal_raw() { # PATCH custom field: multiple_ssids = "yes" — used for task_notify path nb_set_multiple_ssids_yes() { local dev_id="$1" + + # Pre-read current value and print + local prev + prev="$(nb_read_custom_field "$dev_id" "multiple_ssids" || true)" + echo ">>> Pre-change (id=$dev_id): multiple_ssids='${prev:-}'" + local body='{"custom_fields":{"multiple_ssids":"yes"}}' local code @@ -319,6 +352,12 @@ nb_remove_tag_by_slug() { # --- clear only custom_field update_progress (set to null) --- nb_clear_update_progress() { local dev_id="$1" + + # Pre-read current value and print + local prev + prev="$(nb_read_custom_field "$dev_id" "update_progress" || true)" + echo ">>> Pre-change (id=$dev_id): update_progress='${prev:-}'" + local body='{"custom_fields":{"update_progress":null}}' local code code="$(curl -sS -o /dev/null -w "%{http_code}" \ @@ -338,6 +377,12 @@ nb_clear_update_progress() { # --- NEW: generic single custom field patch --- nb_patch_custom_field() { local dev_id="$1" key="$2" value="$3" + + # Pre-read current value and print + local prev + prev="$(nb_read_custom_field "$dev_id" "$key" || true)" + echo ">>> Pre-change (id=$dev_id): ${key}='${prev:-}'" + # Build {"custom_fields": { "": "" }} local body body="$(jq -n --arg k "$key" --arg v "$value" '{custom_fields: {($k): $v}}')"