Example plugin with ActionCable support


We created an example plugin for Foreman that broadcasts all models events (create/update/destroy) through an ActionCable channel:

It’s pretty simple and there are only two commits of interest in this repo: the plugin changes and a small web client which logs ActionCable events and data to the javascript console.

It won’t work in production with Apache + Passenger, but works with Puma (and should work with NginX + passenger, if it’s supported by Foreman).



while this is definitely an option, I would like to disencourage from this low-level approach which did not pay off in the official foreman_hooks plugin. Users are hitting issues every time we changed our model, also not everything is an ActiveRecord event.

We are currently working hard on the new Subscription API which allows plugins to hook into Foreman events in a similar but more controlled manner. For end users, I would encourage users to consider using the new Foreman Webhooks plugin based on this API:

It makes use of our templating engine so everytime we change some internal data structure, webhooks should not break when using our own templates (or should be pretty easy to fix template clones by comparing the changes).

This all is work in progress but this is our priority now to deliver this in 2.3/2.4 timeframe. Feedback or contributions welcome!

Edit: After reading my post, I think the tone was not the best. To clarify, it’s awesome you share your work and we want to see as many plugins as possible. Thanks!

1 Like

Hi ! Thanks for your answer !

We know hooking in all events is not optimal; our use case would be to hook in models of interest instead, and to filter what is broadcasted. This is only an example on how to create ActionCable channels and broadcast data in the context of a Foreman plugin.

Edit: and the tone was OK, we’re here to build robust things and constructive notes are always good to read.


It’s great to see this working, since we are migrating to Puma ActionCable should also be a viable option for example for UI notifications.

With a small change, you can also use our hook event API, for now you can get similar results + two hooks we publish which are not ActiveRecord-based. But in the future we will add more events.

I’ll check foreman_webhooks to and see if I can manage to make it work with our example, that may be an interesting addtion.

We are actively working on this so expect some changes in few weeks. Thanks.

ActionCable is something we should implement in near future, thanks for looking into it! :slight_smile:
There is a PR https://github.com/theforeman/foreman/pull/7611 by @Ron_Lavi that would make it possible to emit redux actions from server, and thus directly project changes into our UI.

I think, that given we already have React/Redux in foreman, we should leverage it and go through redux actions instead of implementing native vanilla client.

Currently it was blocked as we were not 100% sure we are able to stick with Puma, as current stable release (2.1) is the first release containing it. So we didn’t want to depend on it heavily yet, but it should happen in next release cycle and end up in 2.4 if it goes well contributions and any help is definitelly welcome ! :slight_smile: