Projet

Général

Profil

Paste
Télécharger au format
Statistiques
| Branche: | Révision:

root / plugins / network / dns / bind95_ @ 0a1524f2

Historique | Voir | Annoter | Télécharger (3,74 ko)

1
#!/usr/bin/perl
2
#
3
# Copyright Jean-Samuel Reynaud <js.reynaud@free.fr>
4
# Licenced under GPL v2
5
#
6
# We use this script to produce graph with munin for dns requests
7
# This script must have his name start with bind95_
8
# bind95_ : Global bind statistic
9
# bind95_test.com : Bind statistic for test.com zone (no view)
10
# bind95_test.com@internal : Bind statistic for test.com zone (view internal)
11
# This version work with bind 9.5
12
#
13
# Thanks for Benjamin Pineau for perl cleaning and corrections
14
#
15
# You should have to add the following lines to you plugin configuration
16
# (/etc/munin/plugin-conf.d/munin-node):
17
#[bind95_*]
18
#user root
19
#stat_file /var/cache/bind/named.stats
20
#rndc /usr/sbin/rndc
21
#
22
#
23
# Magic markers
24
#%# family=auto
25
#%# capabilities=autoconf
26

    
27
use strict;
28
use warnings;
29
use Digest::MD5 qw(md5_hex);
30

    
31
# change those to reflect your bind configuration (use plugin configuration)
32
# stat file
33
my $stat_file = $ENV{'stat_file'} || "/var/cache/bind/named.stats";
34
# rndc path
35
my $rndc = $ENV{'rndc'} || "/usr/sbin/rndc";
36

    
37

    
38
my $domain = $0;
39
if ($domain =~ m/^.*bind95_[\w\d\._\-]+@[\w\d\._\-]+?$/) {
40
    $domain =~ s/^.*bind95_([\w\d\._\-]*)@([\w\d\._\-]+)?$/$1 (view: $2)/;
41
} elsif ($domain =~ m/^.*bind95_[\w\d\._\-]+$/) {
42
    $domain =~ s/^.*bind95_([\w\d\._\-]+)$/$1/;
43
} else {
44
    $domain = "View: _bind";
45
}
46

    
47
my @counters = (
48
'IPv4 requests received',
49
'requests with EDNS(0) received',
50
'TCP requests received',
51
'auth queries rejected',
52
'recursive queries rejected',
53
'transfer requests rejected',
54
'update requests rejected',
55
'responses sent',
56
'truncated responses sent',
57
'responses with EDNS(0) sent',
58
'queries resulted in successful answer',
59
'queries resulted in authoritative answer',
60
'queries resulted in non authoritative answer',
61
'queries resulted in referral answer',
62
'queries resulted in nxrrset',
63
'queries resulted in SERVFAIL',
64
'queries resulted in NXDOMAIN',
65
'queries caused recursion',
66
'duplicate queries received',
67
'queries dropped',
68
'other query failures',
69
'requested transfers completed',
70
'transfer requests succeeded',
71
'IPv4 notifies sent',
72
'IPv4 notifies received',
73
'notifies rejected',
74
'IPv4 SOA queries sent',
75
'IPv4 IXFR requested'
76
);
77

    
78

    
79
# Parse the statistic file
80
sub parseFile {
81
    my $dom = shift @_;
82
    open(IN,"<$stat_file") or die "Can't open $stat_file : $!";
83
    my $current_zone = "";
84
    while (<IN>) {
85
        chomp;
86
        my $l = $_;
87

    
88
        if ($l =~ /\[/ ) {
89
            $l =~ s/\[//g;
90
            $l =~ s/\]//g;
91
            $current_zone = $l;
92
        } else {
93
            $l =~ s/^ *//g;
94
            if ($l =~ /^[0-9]/ && $current_zone eq $domain) {
95
                my ($val,$desc) = split(' ',$l,2);
96
                if (grep { $desc eq $_ } @counters) {
97
                    printf "%s.value %u\n",md5_hex($desc),$val;
98
                }
99
            }
100
        }
101
    }
102
    close(IN);
103
}
104

    
105

    
106

    
107
# Config mode
108
if ( defined($ARGV[0]) && $ARGV[0] eq "config" ) {
109
    printf "graph_title Dns requests %s\n",($domain eq "View: _bind" ? " all domains":$domain);
110
    printf "graph_vlabel requests/s\n";
111
    printf "graph_category network\n";
112
    printf "graph_info This graph display dns requests for %s\n",($domain eq "View: _bind" ? "all domains":$domain);
113

    
114
    foreach(@counters) {
115
        my $s = $_;
116
        printf "%s.label %s\n",md5_hex($s),$s;
117
        printf "%s.type DERIVE\n",md5_hex($s);
118
        printf "%s.min 0\n",md5_hex($s);
119
    }
120
    exit 0;
121
}
122

    
123
if ( defined($ARGV[0]) && $ARGV[0] eq "autoconf" ) {
124
    if (! -f $stat_file) {
125
        printf "Unable to file bind stat file on %s",$stat_file;
126
        exit 1;
127
    }
128
    if (! -f $rndc) {
129
        printf "Unable to file rndc tool (configured : %s)",$rndc;
130
        exit 1;
131
    }
132
    exit 0;
133
}
134

    
135
# Remove old stat file
136
unlink ($stat_file);
137
# Ask to bind to build new one
138
`$rndc stats`;
139
# Parse the stat file and return result
140
parseFile($domain);