summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/facter/dns_zone_serial.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/lib/facter/dns_zone_serial.rb b/lib/facter/dns_zone_serial.rb
new file mode 100644
index 0000000..6aca94e
--- /dev/null
+++ b/lib/facter/dns_zone_serial.rb
@@ -0,0 +1,20 @@
+require 'resolv'
+
+Facter.add(:dns_zone_serial) do
+ confine do
+ Facter.Util.Resolution.which('named-checkconf')
+ end
+
+ setcode do
+ dns = Resolv::DNS.new(nameserver: ['localhost'])
+ zones = `named-checkconf -l`
+ .split("\n")
+ .map { |line| line.split(' ') }
+ .filter { |zone| zone.last == 'master' }
+ zone_map = {}
+ zones.map do |zone|
+ zone_map["#{zone[0]}."] = dns.getresource(zone[0], Resolv::DNS::Resource::IN::SOA).serial
+ end
+ zone_map
+ end
+end