Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

allow exporting process to run arbitrary hooks #49

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

mzagrabe
Copy link
Contributor

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.

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.
@mzagrabe
Copy link
Contributor Author

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

External programs can make good use of various metadata - such as the Netdot
name - thus we pass it along.
It will beneficial to be able to order the hook programs. Such as:

hooks/BIND/after-zone-written/0001-copy-zone-to-production
hooks/BIND/after-zone-written/0002-reload-zone
hooks/BIND/after-zone-written/0003-flush-cache-on-recursive-servers
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant