allow exporting process to run arbitrary hooks
This commit allows local Netdot instances to run their own code at various hook points in the exporting process.
This commit only adds hook points for exporting BIND configs. However, adding hook points for other classes should be straightforward and simple due to leveraging the 'hook' subroutine.
Pertinent data is passed to the hook programs via a JSON encoded data structure on the command line.
Hi Carlos,
I saw on the -users mailing a question (circa 2012) about a hook to restart BIND after the zone file was generated:
Subject: [Netdot-users] Hook to restart bind after export
To which Vincent.Magnin responded with a patch to directly modify the Netdot sources. This branch works around that by implementing a "hooks" system where each export class can have hook points and the site administrator can create scripts inside corresponding hook directories to be run whenever the exported configs are created.
For instance, this branch creates three hook points in the BIND exporter:
before-all-zones-written after-zone-written after-all-zones-written
For our Netdot install, we run git pull for "before-all-zones-written". Then on "after-zone-written" we perform:
named-checkzone $ZONE scp $ZONE ssh rndc reload $ZONE
Finally, the "after-all-zones-written" we run a git add; git commit; git push.
It works pretty slick. Here is the output on the export page:
INFO - VCS update successful via: git pull INFO - Zone d.umn.edu written to file: /usr/local/netdot/export/bind/db.d.umn.edu INFO - Zone check successful via: /usr/sbin/named-checkzone -k fail d.umn.edu /usr/local/netdot/export/bind/db.d.umn.edu INFO - Copying zone successful via: scp -o User=root /usr/local/netdot/export/bind/db.d.umn.edu ns-master-test.d.umn.edu:/etc/bind/db/local INFO - Reloading zone successful via: ssh -o User=root ns-master-test.d.umn.edu rndc reload d.umn.edu INFO - Copied zone d.umn.edu to /var/lib/netdot/deploy/vcs/dns-test INFO - VCS commit successful. INFO - VCS push successful.
And when it blows up:
INFO - VCS update successful via: git pull INFO - Zone d.umn.edu written to file: /usr/local/netdot/export/bind/db.d.umn.edu ERROR - Zone has failures. Not deploying. [from: hook BIND:after-zone-written /usr/local/netdot/etc/exporter/hooks/BIND/after-zone-written/netdot-deploy-bind-zone-update] ERROR - /usr/local/netdot/export/bind/db.d.umn.edu:35723: underscore_.d.umn.edu: bad owner name (check-names) [from: hook BIND:after-zone-written /usr/local/netdot/etc/exporter/hooks/BIND/after-zone-written/netdot-deploy-bind-zone-update] ERROR - zone d.umn.edu/IN: loading from master file /usr/local/netdot/export/bind/db.d.umn.edu failed: bad owner name (check-names) [from: hook BIND:after-zone-written /usr/local/netdot/etc/exporter/hooks/BIND/after-zone-written/netdot-deploy-bind-zone-update] ERROR - zone d.umn.edu/IN: not loaded due to errors. [from: hook BIND:after-zone-written /usr/local/netdot/etc/exporter/hooks/BIND/after-zone-written/netdot-deploy-bind-zone-update] WARN - /usr/local/netdot/etc/exporter/hooks/BIND/after-zone-written/netdot-deploy-bind-zone-update had an exit status of: 1
I believe others would benefit from this branch and I'd appreciate it if you'd look it over for inclusion.
Thanks!
-m