~ubuntu-branches/debian/lenny/smokeping/lenny

« back to all changes in this revision

Viewing changes to lib/probes/DNS.pm

  • Committer: Bazaar Package Importer
  • Author(s): Niko Tyni
  • Date: 2006-10-26 21:45:56 UTC
  • mfrom: (1.2.2 upstream) (2.1.5 edgy)
  • Revision ID: james.westby@ubuntu.com-20061026214556-5jnpiesx4vdijmu6
* debian/patches/15_clean_makefile.dpatch:
  + remove unneeded and potentially unsecure include paths.
* debian/patches: selected patches from the upstream SVN repository
  + 40_password.dpatch: skip reading the password file when running as a CGI.
  + 50_ldap.dpatch: Make the 'scope' option in the LDAP probe actually work.
  + 60_fping.dpatch:
    * Support the '-S' (set source address, see #198486) fping option.
    * Don't try to execute fping when running as a CGI.
  + 70_syslog.dpatch: Don't die silently if syslogd is unavailable.
    (Closes: #395056)
* Remove all the autogenerated documentation at clean time, to properly
  undo the effects of the 'build' target.
* Install example configuration files for documentation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
package probes::DNS;
2
 
 
3
 
=head1 NAME
4
 
 
5
 
probes::DNS - Name Service Probe for SmokePing
6
 
 
7
 
=head1 SYNOPSIS
8
 
 
9
 
 *** Probes ***
10
 
 + DNS
11
 
 binary = /usr/bin/dig
12
 
 
13
 
 *** Targets *** 
14
 
 probe = DNS
15
 
 forks = 10
16
 
 
17
 
 + First
18
 
 menu = First
19
 
 title = First Target
20
 
 # .... 
21
 
 
22
 
 ++ PROBE_CONF
23
 
 lookup=www.mozilla.org
24
 
 
25
 
=head1 DESCRIPTION
26
 
 
27
 
Integrates dig as a probe into smokeping. The variable B<binary> must
28
 
point to your copy of the dig program. If it is not installed on
29
 
your system yet, you should install bind-utils >= 9.0.0.
30
 
 
31
 
The Probe asks the given host n-times for it's name. Where n is
32
 
the amount specified in the config File.
33
 
 
34
 
Supported probe-specific variables:
35
 
 
36
 
=over
37
 
 
38
 
=item binary
39
 
 
40
 
The location of your dig binary.
41
 
 
42
 
=item forks
43
 
 
44
 
The number of concurrent processes to be run. See probes::basefork(3pm)
45
 
for details.
46
 
 
47
 
=back
48
 
 
49
 
Supported target-level probe variables:
50
 
 
51
 
=over
52
 
 
53
 
=item lookup
54
 
 
55
 
Name of the host to look up in the dns.
56
 
 
57
 
=back
58
 
 
59
 
 
60
 
=head1 AUTHOR
61
 
 
62
 
Igor Petrovski E<lt>pigor@myrealbox.comE<gt>,
63
 
Carl Elkins E<lt>carl@celkins.org.ukE<gt>,
64
 
Andre Stolze E<lt>stolze@uni-muenster.deE<gt>,
65
 
Niko Tyni E<lt>ntyni@iki.fiE<gt>,
66
 
Chris Poetzel<lt>cpoetzel@anl.gov<gt>
67
 
 
68
 
 
69
 
=cut
70
 
 
71
 
use strict;
72
 
use base qw(probes::basefork);
73
 
use IPC::Open3;
74
 
use Symbol;
75
 
use Carp;
76
 
 
77
 
my $dig_re=qr/query time:\s+([0-9.]+)\smsec.*/i;
78
 
 
79
 
sub new($$$)
80
 
{
81
 
    my $proto = shift;
82
 
    my $class = ref($proto) || $proto;
83
 
    my $self = $class->SUPER::new(@_);
84
 
 
85
 
    # no need for this if we run as a cgi
86
 
    unless ( $ENV{SERVER_SOFTWARE} ) {
87
 
        
88
 
        croak "ERROR: DNS 'binary' not defined in FPing probe definition"
89
 
            unless defined $self->{properties}{binary};
90
 
 
91
 
        croak "ERROR: DNS 'binary' does not point to an executable"
92
 
            unless -f $self->{properties}{binary} and -x $self->{properties}{binary};
93
 
        my $call = "$self->{properties}{binary} localhost";
94
 
        my $return = `$call 2>&1`;
95
 
        if ($return =~ m/$dig_re/s){
96
 
            $self->{pingfactor} = 1000;
97
 
            print "### parsing dig output...OK\n";
98
 
        } else {
99
 
            croak "ERROR: output of '$call' does not match $dig_re\n";
100
 
        }
101
 
    };
102
 
 
103
 
    return $self;
104
 
}
105
 
 
106
 
sub ProbeDesc($){
107
 
    my $self = shift;
108
 
    return "DNS requests";
109
 
}
110
 
 
111
 
sub pingone ($){
112
 
    my $self = shift;
113
 
    my $target = shift;
114
 
 
115
 
    my $inh = gensym;
116
 
    my $outh = gensym;
117
 
    my $errh = gensym;
118
 
 
119
 
    my $host = $target->{addr};
120
 
    my $lookuphost = $target->{vars}{lookup};
121
 
    $lookuphost = $target->{addr} unless defined $lookuphost;
122
 
 
123
 
    #my $host = $target->{addr};
124
 
    my $query = "$self->{properties}{binary} \@$host $lookuphost";
125
 
    my @times;
126
 
 
127
 
    $self->do_debug("query=$query\n");
128
 
    for (my $run = 0; $run < $self->pings($target); $run++) {
129
 
        my $pid = open3($inh,$outh,$errh, $query);
130
 
        while (<$outh>) {
131
 
            if (/$dig_re/i) {
132
 
                push @times, $1;
133
 
                last;
134
 
            }
135
 
        }
136
 
        waitpid $pid,0;
137
 
        close $errh;
138
 
        close $inh;
139
 
        close $outh;
140
 
    }
141
 
    @times = map {sprintf "%.10e", $_ / $self->{pingfactor}} sort {$a <=> $b} grep {$_ ne "-"} @times;
142
 
 
143
 
#    $self->do_debug("time=@times\n");
144
 
    return @times;
145
 
}
146
 
 
147
 
1;