Projet

Général

Profil

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

root / plugins / network / dansguardian @ dd4afac8

Historique | Voir | Annoter | Télécharger (1,66 ko)

1
#!/usr/bin/perl -w
2
#
3
# Parameters:
4
#
5
# 	logfile      - Location of the query log
6
# 	statefile    - Where to put temporary statefile.
7
#
8
# Stolen directly from the bind log analzyer
9
# contributed by Nicolai Langfeldt
10
#
11
# Modified by Sean Whitney
12
# $Id: dansguardian,v 1.1 2011/10/04 13:53:17 root Exp root $
13
#
14
#%# family=contrib
15

    
16
use strict;
17

    
18
my $QUERYLOG = $ENV{logfile} || '/var/log/dansguardian/access.log';
19
my $STATEFILE = $ENV{statefile}
20
  || '/var/lib/munin/plugin-state/dansguardian.state';
21
my %IN;
22

    
23
sub get_state {
24
    open( Q, "< $STATEFILE" ) or die;
25
    while (<Q>) {
26
        chomp;
27
        my ( $q, $n ) = split( /\s+/, $_, 2 );
28
        $IN{$q} = $n unless defined( $IN{$q} );
29
    }
30
    close(Q);
31
}
32

    
33
sub do_stats {
34
    my $k;
35

    
36
    open( Q, "< $QUERYLOG" ) or die "$!";
37
    while (<Q>) {
38
        chomp;
39
        my ( $date, $time, $sep, $ip, $url, $action, $rest ) = split(' ');
40
        $action =~ s/[^a-zA-Z0-9]//g;
41
        $IN{$action}++;
42
    }
43
    close(Q);
44

    
45
    get_state;
46

    
47
    open( Q, "> $STATEFILE" ) or die;
48
    foreach $k ( keys %IN ) {
49
        print "query_$k.value ", $IN{$k}, "\n";
50
        print Q "$k ", $IN{$k}, "\n";
51
    }
52
    close(Q);
53

    
54
}
55

    
56
sub do_config {
57
    my $k;
58

    
59
    print "graph_title Danguardian hits by type\n";
60
    print "graph_vlabel Hits / \${graph_period}\n";
61
    print "graph_category network\n";
62
    print "graph_info This graph shows the rate of traffic through a dansguardian filter\n";
63

    
64
    get_state;
65
    foreach $k ( keys %IN ) {
66
        print "query_$k.label $k\n";
67
	print "query_$k.type DERIVE\n";
68
	print "query_$k.min 0\n";
69
    }
70
}
71

    
72
if ( defined( $ARGV[0] ) and ( $ARGV[0] eq 'config' ) ) {
73
    do_config;
74
    exit(0);
75
}
76

    
77
do_stats;
78

    
79
# vim:syntax=perl