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

Audit hook never called #33

Closed treydock closed 7 years ago

treydock commented 8 years ago

I am attempting to setup the examples/ scripts to verify that audit events are logged, but I can't get any audit events to write to /tmp/hook.log. I copied the same scripts to config/hooks/host/managed/after_update/ and changing host group was logged. I've tried config/hooks/audited/adapters/active_record/audit/after_create/log.sh per the documentation but nothing is logged. When I start rails via rails s -d in development, this plugin prints the hooks are registered. This is using foreman_hooks 0.3.9 and current develop branch of Foreman.

domcleal commented 8 years ago

When I start rails via rails s -d in development, this plugin prints the hooks are registered

Are the hooks registered when in production? Does it log that it's running the hooks at the time? Ensure you have debug logs on.

Note that if you're using httpd on EL7 or higher, then /tmp will be namespaced and you'll be unable to view httpd's copy.

treydock commented 8 years ago

So initially I was trying this in development on OS X...I am now trying the same approach on RedHat 6 in production rails environment and same results.

2016-04-18 14:23:55 [app] [I] Finished registering 1 hooks for Audited::Adapters::ActiveRecord::Audit#after_create

Debug logging is enabled though not very verbose compared to 'info'. All the messages look like 'info' despite settings[:logging][:level] being debug. Only way I got debugging to print was modifying config/environments/production.rb. This is Foreman 1.11 in production. Debugging issue likely a separate issue for separate issue tracker.

In my tests on production I am changing a host's hostgroup and get no log messages I'd expect from this plugin and nothing in /tmp/hook.log.

domcleal commented 8 years ago

Could you give c0f9966 a try please? I think it was simply not loaded on 1.11+ due to a check on the Rails version.

treydock commented 8 years ago

@domcleal The issue persists. I built the gem from source and installed and seems still a problem. Before that commit I'd still see the hooks loaded, just the actual hook script is never called. My guess is the classes having to do with Audited are either incorrect or somehow the callback isn't registering.

2016-04-25 09:23:36 [app] [D] Found hook to Audited::Adapters::ActiveRecord::Audit#after_create, filename test.sh
2016-04-25 09:23:36 [app] [D] Found hook to Audited::Audit#after_create, filename test.sh
2016-04-25 09:23:36 [app] [I] Finished registering 1 hooks for Audited::Adapters::ActiveRecord::Audit#after_create
2016-04-25 09:23:36 [app] [I] Finished registering 1 hooks for Audited::Audit#after_create

I modified a host's hostgroup and got nothing in the /tmp/hook.log.

I've tried the documented Audited::Adapters::ActiveRecord::Audit#after_create path as well as Audited::Audit#after_create.

domcleal commented 8 years ago

Debug logging is enabled though not very verbose compared to 'info'. All the messages look like 'info' despite settings[:logging][:level] being debug. Only way I got debugging to print was modifying config/environments/production.rb. This is Foreman 1.11 in production. Debugging issue likely a separate issue for separate issue tracker.

You're right, I reproduced this and filed it as http://projects.theforeman.org/issues/14820.

domcleal commented 7 years ago

This appears to work better in Foreman 1.15 (and foreman_hooks 0.3.13) now, probably due to the audit gem changes in version 4.3.0 which changed the class used.

Register hooks at config/hooks/audited/audit/ and they are now called correctly.