[go: up one dir, main page]

Menu

[2c1ff0]: / dns / dns.pl  Maximize  Restore  History

Download this file

123 lines (103 with data), 3.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/perl -w
###############################################################################
# Webmin Sysstats Module
# Copyright (C) 2008 by Eric Gerbier
# Bug reports to: gerbier@users.sourceforge.net
# $Id$
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
###############################################################################
use strict;
use warnings;
no warnings 'redefine';
use RRDs;
use English qw(-no_match_vars);
use FindBin;
# to be used alone or from sysstat.pl without warning
# because require verify the path
if ( !exists $ENV{WEBMINSTAT_TEMP} ) {
use lib "$FindBin::Bin/../..";
## no critic (RequireBarewordIncludes)
require 'sysstats-aquisition-lib.pl';
## use critic;
}
my $module_name;
###############################################################################
# log file format :
# 16-May-2008 08:34:49.381 client 137.129.154.11#32807: query: pop.cnrm.meteo.fr.meteo.fr IN AAAA +
sub parse_dnslog($) {
my $log = shift @_;
my %res;
my $r_tab = read_new_lines( $log, $module_name );
foreach my $line ( @{$r_tab} ) {
if ( $line =~ m/client .* query: .* IN (\w+)/ ) {
my $prot = $1;
if ( exists $res{$prot} ) {
$res{$prot}++;
}
else {
$res{$prot} = 1;
}
}
}
return %res;
}
###############################################################################
my %config;
read_file_cached( 'config', \%config );
$module_name = $config{'name'};
debug( "run $module_name version " . $config{'version'} );
my %codes = action_load( \%config );
my $log = $config{'dnslog'};
if ( !$log ) {
warning('dns log not configured');
goto FIN;
}
elsif ( !-r $log ) {
warning("dns log $log not found");
goto FIN;
}
my %result = parse_dnslog($log);
my $pre = $config{'pre'};
my $vol_num = 1;
while ( exists $config{ $pre . $vol_num } ) {
my @tab = split /,/, $config{ $pre . $vol_num };
my $real_vol_num = $tab[0];
my $vol = $tab[1];
my $runstop = $tab[3];
#debug( "volume = $vol");
my $total;
if ( is_param_runstop($runstop) ) {
if ( exists $result{$vol} ) {
$total = $result{$vol};
}
else {
# not found
$total = 0;
}
debug("$module_name $vol ($real_vol_num) : total=$total");
action_param( $vol, $total, \%codes );
}
else {
debug("aquisition for $vol stopped");
$total = 'U';
}
my $rrdbase = $real_vol_num . '.rrd';
RRDs::update( $rrdbase, "N:$total" );
my $ERR = RRDs::error();
warning("ERROR while updating $rrdbase database : $ERR") if $ERR;
$vol_num++;
}
# a label to quit
#I can not use return when executing this script standalone,
# so I had to use goto
FIN: