Incomplete JSON received by host-managed/destroy script when host is deleted

Problem:
When a host is deleted, I captured the JSON passed through stdin to a host-managed/destroy hook script.
It looks like this:
{"host":{"host":{"ip":null,"ip6":null,"environment_id":null,"environment_name":null,"last_report":null,"mac":null,....

Because of this I am not able to capture the MAC address of the host getting deleted.
I think the host gets deleted before it’s details are passed to the destroy script.

Expected outcome:
For other host-managed hook scripts, the JSON looks fine
{"host":{"host":{"ip":"10.10.10.20","ip6":"","environment_id":null,"environment_name":null,"last_report":null,"mac":"00:50:56:88:1e:d9",....

Foreman and Proxy plugin versions:
foreman/now 1.15.6-1
foreman-cli/now 1.15.6-1
foreman-debug/now 1.15.6-1
foreman-installer/now 1.15.6-1
foreman-postgresql/now 1.15.6-1
foreman-proxy/now 1.15.6-1
ruby-foreman-hooks/plugins,plugins,now 0.3.14-1
ruby-foreman-setup/plugins,plugins,now 5.0.0-1
ruby-hammer-cli-foreman/now 0.10.2-1

Please pastebin whole JSON, feel free to randomize names, IPs and stuff but keep everything. I believe your MAC address will be in interfaces subhash.

{
	"host": {
		"host": {
			"ip": null,
			"ip6": null,
			"environment_id": null,
			"environment_name": null,
			"last_report": null,
			"mac": null,
			"realm_id": null,
			"realm_name": null,
			"sp_mac": null,
			"sp_ip": null,
			"sp_name": null,
			"domain_id": null,
			"domain_name": null,
			"architecture_id": 1,
			"architecture_name": "x86_64",
			"operatingsystem_id": 3,
			"operatingsystem_name": "ESXi 6.7",
			"subnet_id": null,
			"subnet_name": null,
			"subnet6_id": null,
			"subnet6_name": null,
			"sp_subnet_id": null,
			"ptable_id": 90,
			"ptable_name": "Kickstart default",
			"medium_id": 12,
			"medium_name": "ESXi Dummy",
			"pxe_loader": "ESXi PXELinux BIOS",
			"build": true,
			"comment": null,
			"disk": null,
			"installed_at": null,
			"model_id": null,
			"hostgroup_id": null,
			"owner_id": 3,
			"owner_type": "User",
			"enabled": true,
			"managed": true,
			"use_image": null,
			"image_file": "",
			"uuid": null,
			"compute_resource_id": null,
			"compute_resource_name": null,
			"compute_profile_id": null,
			"compute_profile_name": null,
			"capabilities": ["build"],
			"provision_method": "build",
			"certname": "00-50-56-88-b4-ff.helab.in",
			"image_id": null,
			"image_name": null,
			"created_at": "2018-06-15T16:33:42.719+05:30",
			"updated_at": "2018-06-15T16:33:42.719+05:30",
			"last_compile": null,
			"global_status": 0,
			"global_status_label": "OK",
			"puppet_status": 0,
			"model_name": null,
			"build_status": 1,
			"build_status_label": "Pending installation",
			"name": "00-50-56-88-b4-ff.helab.in",
			"id": 19,
			"puppet_proxy_id": null,
			"puppet_proxy_name": null,
			"puppet_ca_proxy_id": null,
			"puppet_ca_proxy_name": null,
			"puppet_proxy": null,
			"puppet_ca_proxy": null,
			"token": "b7342aa7-3eba-43db-ad26-5810ec397931",
			"hostgroup_name": null,
			"hostgroup_title": null,
			"parameters": [],
			"all_parameters": [],
			"interfaces": [],
			"puppetclasses": [],
			"config_groups": [],
			"all_puppetclasses": [],
			"permissions": {
				"view_hosts": true,
				"create_hosts": true,
				"edit_hosts": true,
				"destroy_hosts": true,
				"build_hosts": true,
				"power_hosts": true,
				"console_hosts": true,
				"ipmi_boot_hosts": true,
				"puppetrun_hosts": true
			}
		}
	}
}

Error. Invalid JSON given
Error - only generation of JSON objects or arrays allowed

Which destroy hook you work with? If this is an “after” hook, this might be too late - ActiveRecord probably already deleted interfaces and it’s all gone, thus MAC address is nil (it’s just a reference to primary interface). Try using “host/managed/destroy” orchestration hook, that runs in “before_destroy” AR callback.

I am using host/managed/destroy hook only. From production.log
2018-06-15T17:07:25 [app] [D] Found hook to Host::Managed#destroy, filename 01-del-tftp-mac-dir.sh

I believe you are hitting this bug:

It was not yet release, foreman_hooks release for 1.17 and 1.18 is still pending.

Okay…thank you again for the support. Will wait for this release.

Patch your hooks plugin its not big deal, just few lines.

Yep! Doing that now.:grinning: