/[mon-modules]/anon_ftp.monitor
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /anon_ftp.monitor

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Mon Sep 2 13:57:13 2002 UTC (16 years, 6 months ago) by dpavlin
Branch: MAIN
CVS Tags: HEAD
Changes since 1.1: +14 -2 lines
added option -o

1 #!/usr/bin/perl
2 #
3 # Use try to connect to a FTP server using Net::FTP, login as
4 # anonymous and issue PWD.
5 #
6 # Since anonymous ftp servers can be quite busy I suggest that you
7 # enter more than one anonymous ftp server and use option -o. That will
8 # return success if ANY OF SERVERS are available -- that way you can
9 # test if you can connect to ANY ftp server outside.
10 #
11 # For use with "mon".
12 #
13 # Arguments are "[-p port] [-t timeout] [-o] host [host...]"
14 #
15 # 2002-09-02 Dobrica Pavlinusic <dpavlin@rot13.org>
16 #
17
18 use Getopt::Std;
19 use Net::FTP;
20
21 getopts ("p:t:o");
22 $PORT = $opt_p || 21;
23 $TIMEOUT = $opt_t || 30;
24
25 my %bad;
26
27 foreach my $host (@ARGV) {
28
29 my $result = check_anon_ftp($host);
30 if ($result) {
31 $bad{$host} = $result;
32 } else {
33 $good{$host} = "ok";
34 }
35 }
36
37 if (keys %bad == 0) {
38 exit 0;
39 }
40
41 print join (" ", sort keys %bad), "\n";
42
43 foreach my $h (keys %bad) {
44 print "HOST $h: " . $bad{$h}, "\n";
45 }
46
47 if ($opt_o && keys %good > 0) {
48 # one host is o.k., don't report warning
49 exit 0;
50 }
51
52 exit 1;
53
54 sub check_anon_ftp {
55 my ($host) = @_;
56 $ftp = Net::FTP->new($host, Debug => 0, Timeout => $TIMEOUT, Port => $PORT) || return "can't connect to $host:$PORT for $TIMEOUT seconds.";
57 $ftp->login("anonymous",'mon@kernel.org') || return "$host: can't login as anonymous";
58 my $dir = $ftp->pwd || return "$host: can't do PWD";
59 $ftp->quit;
60 return 0;
61 }
62

  ViewVC Help
Powered by ViewVC 1.1.26