Enable/disable Foreman webhooks for individual hosts (and webhook template data access)

Hi all,

Problem:
Using foreman_hooks, it was possible to enable/disable hooks for individual hosts using a host parameter, depending on which an action could be triggered, or not. Now with webhooks, it seems that I’m unable to access a host’s parameters in a webhook template (I’m mostly concerned with the create/delete events).

I can enable/disable webhooks globally using the WebUI for example, but is it possible to achieve more granular control over when a hook is triggered like with foreman_hooks?

Apart from that, more generally in a webhook template, is it impossible to access a host’s IP or MAC address for “Host Created” or “Host Deleted” events? This data can be accessed in a “Host Updated” event.

Expected outcome:

  1. Being able to enable or disable specific webhooks for individual hosts.
  2. Being able to access additional host data (like IP, MAC, subnet gateway, etc) in webhook templates for “Host Created” or “Host Deleted” events.

Foreman and Proxy versions:
Version 3.1.3

Foreman and Proxy plugin versions:
foreman_webhooks 3.0.0

Additional data
These are the fields I’m able to access from a webhook template in the case of a “Host Created” event using:

<%=
  payload({
    "object": @object,
  }, with_defaults: false)
-%>

architecture_id
build
build_errors
certname
comment
compute_profile_id
compute_resource_id
content_facet_attributes
created_at
discovery_rule_id
disk
enabled
global_status
grub_pass
hostgroup_id
id
image_file
image_id
initiated_at
installed_at
last_compile
last_report
location_id
lookup_value_matcher
managed
medium_id
model_id
name
operatingsystem_id
organization_id
otp
owner_id
owner_type
provision_method
ptable_id
puppet_ca_proxy_id
puppet_proxy_id
pxe_loader
realm_id
root_pass
updated_at
use_image
uuid

Sorry if I’m missing something obvious and thanks for any help!

Hi @weird,

Thanks for informative feedback :slight_smile:

  1. Unfortunatelly it’s not yet possible to enable or disable specific webhooks for individual hosts, but I’ve created a RFE to track Feature #35085: Possibility to enable or disable specific webhooks for individual hosts. - Webhooks - Foreman.
  2. It’s possible :slight_smile: Due to internal logic of the whole application, it’s better to use properties/macros on the objects in templates. You can find them under https://foreman.example.com/templates_doc. You can find this link on the About page also.

So, for example, if you want to access IP of the host, you would need to slightly change your template like so:

<%=
  payload({
    "object": @object,
    "IPv4": @object.ip
  }, with_defaults: false)
-%>
1 Like