Code

Replacement (structured name mainly) for check_citrix: check of ICA browse service
[nagiosplug.git] / contrib / check_ftpget.pl
1 #!/usr/bin/perl -w
2 ## Written 12/5/00 Jeremy Hanmer 
3 # $Id$
5 use strict;
6 use Net::FTP;
7 use Getopt::Std;
9 use vars qw($opt_H $opt_u $opt_p $opt_f);
10 getopts("H:u:p:f:");
12 my $host = $opt_H || 
13     die "usage: check_ftp.pl -h host [<-u user> <-p pass> <-f file>]\n";
15 my $username = $opt_u || 'anonymous';
16 my $pass = $opt_p || "$ENV{'LOGNAME'}\@$ENV{'HOSTNAME'}" ;
18 my $file = $opt_f;
20 my $status = 0;
21 my $problem;
22 my $output = "ftp ok";
24 my $ftp = Net::FTP->new("$host") ||
25     &crit("connect");
27 $ftp->login("$username", "$pass") ||
28     &crit("login");
30 $ftp->get($file) ||
31     &crit("get") if $file;
33 sub crit() 
34 {
35     $problem = $_[0];
36     $status = 2;
37     if ( $problem eq 'connect' ) {
38         $output = "can't connect";
39     } elsif ( $problem eq 'login' ) {
40         $output = "can't log in";
41     } elsif ( $problem eq 'get' ) {
42         $output = "cant get $file";
43     }
44 }
46 print "$output\n";
47 exit $status;