ytti / oxidized

Oxidized is a network device configuration backup tool. It's a RANCID replacement!
Apache License 2.0
2.74k stars 915 forks source link

Hook/Plugin System #60

Closed sts closed 9 years ago

sts commented 9 years ago

We want to be notified for configuration changes at our devices. I cannot use GIT hooks for that purpose, since they don't trigger on a bare repository as its initialised by Oxidized.

There is https://github.com/git-commit-notifier/git-commit-notifier which will create good looking change e-mails, which I would like to use for that purpose. We could probably just initiate it after creating the rugged commit oxidized/output/git.rb.

What are your thoughts?

ytti commented 9 years ago

We probably should support several configurable hooks. And configuration changes is definitely one of them.

sts commented 9 years ago

So we would need a plugin system, something like this

class Oxidized::Hook
   @hooks = []
   def register(type, block)
   end
   def execute(type)
   end
end

Oxidized::Hook.register :post_commit do
   `git-commit-notifier`
end

Oxidized::Hook.execute :post_commit

register would record a new user defined hook, and execute would run all available hooks from the hookable code points. Can you create a list of code points you think would be worth hooking in?

Also I think we should alos expose this via the configuration file somehow.

ytti commented 9 years ago

Absolutely. We need people to be able to set arbitrary URL or ruby class to be called on hook triggered, someone asked about this in IRC recently.

13:20 <+kll> ytti: does oxidized have callbacks on configuration changes? (quick peak at github tells me no)

This is definitely something many will find useful.

MrRJ45 commented 9 years ago

This would be very nice to have. The ability to execute an external binary/script would be nice, with the ability to pass it arguments, such as the device name, ip, etc.

SaaldjorMike commented 9 years ago

:+1: for a hook system. I could really use a pre-commit hook to do some cleanup in configuration before committing any changes. Also a post-commit hook to push to a remote repository would also be of interest to me.

laetrid commented 9 years ago

Hello! Any advance in configuration changes notification? Now I use http://git-scm.com/docs/git-send-email for this purpose, but it isn`t really convenient.

ytti commented 9 years ago

@sts can you test this?

https://github.com/ytti/oxidized/tree/feature-hook

aakso commented 9 years ago

@sts and @ytti here is the example configuration for using the Exec hook:

hooks:
  do_smth:
    type: exec
    events: [post_store, node_fail]
    cmd: 'env >> /tmp/oxiexec.txt'
    timeout: 120
    async: true
aakso commented 9 years ago

You can also implement hooks in Ruby by subclassing Oxidized::Hook and implementing run_hook(ctx) method.

jthunt commented 9 years ago

Since I haven't replaced my production rancid with Oxidized yet (still waiting on the custom ports), I installed the feature-hook branch on my test box. It is working well with a shell script I created to run git-commit-notifier against the git repo on post_store.

ytti commented 9 years ago

Released in 0.8.0