theforeman / foreman_hooks

Run custom hook scripts on Foreman events
http://m0dlx.com/blog/Extending_Foreman_quickly_with_hook_scripts.html
GNU General Public License v3.0
56 stars 50 forks source link

Not able to render json because the rabl file is not found fore host/discovereds #24

Closed phirince closed 9 years ago

phirince commented 9 years ago

I'm trying to run a hook fore after_save event of Host::Discoverd object.

I'm getting the following error: 2015-08-07 07:58:28 [W] Unable to render mac002128a5131e (Host::Discovered) using RABL: Cannot find rabl template 'api/v2/host/discovereds/show' within registered (["app/views", "/usr/share/foreman/app/views"]) view paths!

this line of code assumes that there is a rabl file for the host object. Only that in this case, the object is not of Host::Managed class. Since foreman_discovery is a plugin, it doesn't make sense to ship the rabl file with the foreman code. https://github.com/theforeman/foreman_hooks/blob/master/lib/foreman_hooks/util.rb#L18https://github.com/theforeman/foreman_hooks/blob/master/lib/foreman_hooks/util.rb#L18

What could be the best solution in this case?

-PP

phirince commented 9 years ago

The rabl files are available inside the app/views directory of foreman_discovery gem. But it is named discovered_hosts and not host/discovereds. But in order for the Rabl module to find this, patches are needed in foreman_discovery, foreman and foreman_hooks. I'll submit pull requests to these. Please review them and let me know any better solution is available.

-PP

phirince commented 9 years ago

These are the pull requests I made in foreman and foreman_discovery

https://github.com/theforeman/foreman/pull/2596

https://github.com/theforeman/foreman_discovery/pull/205

domcleal commented 9 years ago

Looks like a good direction, thanks for the PRs - comments on them!