From dd74f0f6581e85cdc11810ffd9e4b60f8f1df998 Mon Sep 17 00:00:00 2001 From: Jean-Samuel Reynaud Date: Mon, 18 Feb 2008 17:32:32 +0100 Subject: [PATCH] Initial version --- plugins/other/bind_ | 115 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 115 insertions(+) create mode 100755 plugins/other/bind_ diff --git a/plugins/other/bind_ b/plugins/other/bind_ new file mode 100755 index 00000000..fd19e0fe --- /dev/null +++ b/plugins/other/bind_ @@ -0,0 +1,115 @@ +#!/usr/bin/perl +# +# Copyright Jean-Samuel Reynaud +# Licenced under GPL v2 +# +# We use this script to produce graph with munin for dns requests +# This script must have his name start with bind_ +# bind_ : Global bind statistic +# bind_test.com : Bind statistic for test.com zone +# +# "env.bind_stat_file" is the path to the bind statistic file +# (/var/cache/bind/named.stats by default). +# +# "env.bind_rndc" is the path to the rndc tool +# (/usr/sbin/rndc by default). +# +# Thanks for Benjamin Pineau for perl cleaning and correction in non root +# running +# Thanks to Immanuel Klinkenberg for adding config parameter by using munin config +# +# Magic markers +#%# family=auto +#%# capabilities=autoconf + +use strict; +use warnings; + +# change those to reflect your bind configuration +# stat file +my $stat_file = # DB directory + defined $ENV{'bind_stat_file'} ? $ENV{'bind_stat_file'} : '/var/cache/bind/named.stats'; +# rndc path +my $rndc = # rndc path + defined $ENV{'bind_rndc'} ? $ENV{'bind_rndc'} : '/usr/sbin/rndc'; + +my $lst = { "success" => 1, + "referral" => 1, + "nxrrset" => 1, + "nxdomain" => 1, + "recursion" => 1, + "failure" => 1}; + +my $domain = $0; +$domain =~ s/^.*bind_([\w\d\._\-]*)$/$1/; + + +# Parse the statistic file +sub parseFile { + my $dom = shift @_; + open(IN,"<$stat_file") or die "Can't open $stat_file : $!"; + + while () { + chomp; + my ($type,$count,$zone) = split(/ /,$_); + $zone = defined($zone) ? $zone : ""; + if ($zone eq $dom) { + if (defined $lst->{$type}) { + # only keep the latest occurence for each value + $lst->{$type} = $count; + } + + } + } + + close(IN); + printf "%s.value %u\n", $_, $lst->{$_} foreach (keys %$lst); +} + + + +# Config mode +if ( defined($ARGV[0]) && $ARGV[0] eq "config" ) { + printf "graph_title Dns requests %s\n",($domain eq "" ? " all domains":$domain); + printf "graph_vlabel requests/s\n"; + printf "graph_category network\n"; + printf "graph_info This graph display dns requests for %s\n",($domain eq "" ? " all domains":$domain); + printf "success.label Success\n"; + printf "success.type COUNTER\n"; + + printf "referral.label Referral\n"; + printf "referral.type COUNTER\n"; + + printf "nxrrset.label Nx RR set\n"; + printf "nxrrset.type COUNTER\n"; + + printf "nxdomain.label NX domain\n"; + printf "nxdomain.type COUNTER\n"; + + printf "recursion.label Recursion\n"; + printf "recursion.type COUNTER\n"; + + printf "failure.label Failure\n"; + printf "failure.type COUNTER\n"; + + exit 0; +} + +if ( defined($ARGV[0]) && $ARGV[0] eq "autoconf" ) { + if (! -f $stat_file) { + printf "Unable to file bind stat file on %s",$stat_file; + exit 1; + } + if (! -f $rndc) { + printf "Unable to file rndc tool (configured : %s)",$rndc; + exit 1; + } + exit 0; +} + +# Remove old stat file +unlink ($stat_file); +# Ask to bind to build new one +`$rndc stats`; +# Parse the stat file and return result +parseFile($domain);