my nagios check_ftp plugin

I use a modified version of a simple perl plugin check_ftp.pl from nagios exchange.
Here is my version:

#!/usr/bin/perl -w 
#
# Version 0.0.3
# # modified by Thierry Randrianiriana
# # used /dev/null
# # added missing exit
# # typos
# Version 0.0.2
# # fixed some bugs when using strict
# Version 0.0.1
# # initial version

use Net::FTP;
use Getopt::Long qw(:config no_ignore_case);

my $hostname = 'localhost';
my $username = 'anonymous';
my $password = 'username@domain.com';
my $port = '21';
my $directory = '/';
my $file = '';
my $verbose = '0';
my $passive = '0';
my $timeout = "30";
my $version = "0.0.2";

sub help ();

my $options_okay = GetOptions (
  'hostname|H=s'	=> \$hostname,
  'username|u=s'	=> \$username,
  'password|p=s'	=> \$password,
  'port|P=s'		=> \$port,
  'directory=s'		=> \$directory,
  'file=s'		=> \$file,
  'verbose=i'		=> \$verbose,
  'version'		=> \$version,
  'help|h'		=> sub {help}
);

# creating connection
my $ftp = Net::FTP->new("$hostname", Debug => $verbose, Port => $port, Timeout => $timeout, Passive => $passive );
my $err = $@;

if (! defined $ftp) {
    print "ERROR: ", $err;
    exit 2;
}

if (!$ftp->login("$username","$password")) { 
  print "ERROR: server says: ", $ftp->message;
  exit 2;
}

if ($file eq "") {
  if (!$ftp->ls("$directory")) { 
    print "WARNING: server says: " , $ftp->message;
    exit 1;
  } else  {
    print $ftp->message;
    exit 0;
  }
} else {
  if (!$ftp->ls("$file")) { 
    print "WARNING: server says: " , $ftp->message;
    exit 1;
  } else {
    if (!$ftp->get("$file","/dev/null")) {
      print "WARNING: server says: " , $ftp->message;
      exit 1;
    } else {
      my @message = $ftp->message;
      chomp @message;
      print "OK: ", "$message[0] $message[1]\n";
      exit 0;
    }
  }
}
$ftp->quit;

sub help () {
        print "Copyright (c) 2005 Joost Veldkamp, nagios at darth dot xs4all dot nl
This plugin checks a ftp server, logins supported. The check downloads a file and returns
OK when the download succeeded.

-H, --hostname=HOST
   Name or IP address of host to check
-u, --username=username
   FTP username
-p --password=password
   FTP Password
-P --port=INTEGER
   TCP port of the FTP server (default 21)
-d --directory=PATH
   Directory on the remote FTP server
-f --file=FILENAME
   Filename of the file on the remote FTP server
-v --verbose=INT
   Print verbose stuff when performing the check, default 0, other for debugging.
-h --help
   Print this message.
-v --version
   Print version number.
";
exit 0;
}

Laisser un commentaire

Entrez vos coordonnées ci-dessous ou cliquez sur une icône pour vous connecter:

Logo WordPress.com

Vous commentez à l'aide de votre compte WordPress.com. Déconnexion / Changer )

Image Twitter

Vous commentez à l'aide de votre compte Twitter. Déconnexion / Changer )

Photo Facebook

Vous commentez à l'aide de votre compte Facebook. Déconnexion / Changer )

Photo Google+

Vous commentez à l'aide de votre compte Google+. Déconnexion / Changer )

Connexion à %s