Get MAC address of a host in a Foreman hook script

Hi, Is it possible to capture the host’s MAC address in a foreman-hook script? I know that the first and second args are the event name and hostname but I need the MAC address.

Hello, yes.

A JSON representation of the hook object will be passed in on stdin. A utility to read this with jgrep is provided in examples/hook_functions.sh and sourcing this utility script will be enough for most users. Otherwise, you may want to ensure stdin is closed to prevent pipe buffer from filling.

Thanks Lukas.
I used /usr/share/foreman/vendor/ruby/2.3.0/gems/foreman_hooks-0.3.14/examples/python/host/managed/create/10-logger.py as reference. However that script has an error:
Instead of
mac_address = HOOK_JSON.get('host').get('mac', None)
it should be
mac_address = HOOK_JSON.get('host').get('host').get('mac', None)

1 Like

Looks like there is already an open issue for this:
https://github.com/theforeman/foreman_hooks/issues/46

1 Like