Hi,
I'd like to monitor the latest file on an ftp server and also its size.
I could not find any plugin that do such thing
Thank you for your help
Check FTP file date and size
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact:
Re: Check FTP file date and size
It is going to depend on what you want to do, there are some available FTP plugins are here:
https://exchange.nagios.org/directory/P ... tocols/FTP
https://exchange.nagios.org/directory/P ... tocols/FTP
Re: Check FTP file date and size
The Folder Watch Wizard within Nagios XI can probably do this via SSH if that is an option for your setup:
https://support.nagios.com/kb/article.php?id=76
Otherwise, here's a simple script I found written in Perl that claims to "check the age of a specific File, threshold is provided in minutes" though it does require you to pass in a specific file name and would have to be modified slightly to grab the "latest" file every time.
You may need to change the shebang on this script to point to your actual Perl binary. If you're not familiar with using third party plugins in Nagios XI, this documentation should be helpful:
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
https://support.nagios.com/kb/article.php?id=76
Otherwise, here's a simple script I found written in Perl that claims to "check the age of a specific File, threshold is provided in minutes" though it does require you to pass in a specific file name and would have to be modified slightly to grab the "latest" file every time.
Code: Select all
#!/usr/local/groundwork/perl/bin/perl
# Nagios Check Plugin
# Title: Check FTP Advanced
#
# Description: This FTP Check is designed to check the age of a specific File, threshold is provided in minutes.
# Author: Chrysanth Sulzberger | NextiraOne (Schweiz) GmbH
# Version: 1.0
#
# Usage:
# You can use this plugin to simply check if it's possible to connect successfully to a FTP Server, to be more specific you can additionaly check if a specific file exists. If a file e.g. image export of a we
bcam changes periodically you can set a treshold in minutes.
use Date::Parse;
use Net::FTP;
use Getopt::Std;
use vars qw($opt_H $opt_u $opt_p $opt_d $opt_f $opt_w $opt_c);
getopts("H:u:p:d:f:w:c:");
# Initialise Vars
my $host = $opt_H ||
die "usage: check_ftp.pl -H host [<-u user> <-p pass> <-d dir> <-f file> <-w age in min.> -c age in min.]\n";
my $username = $opt_u || 'anonymous';
my $pass = $opt_p || "$ENV{'LOGNAME'}\@$ENV{'HOSTNAME'}" ;
my $dir = $opt_d || '.';
my $file = $opt_f || '';
my $status = 0;
my $problem;
my $output = "connected successfully as $username";
my $min = 60;
my $warning = $opt_w || 0;
my $critical = $opt_c || 0;
my $time ="00:00";
my $year = ((localtime)[5] +1900);
my @line;
my $ftp;
# Open FTP Connection
$ftp = Net::FTP->new($host)
or &crit("connect");
# Login with provided Username / Password
$ftp->login($username,$pass)
or &crit("login");
# Change Directory to provided Directory
$ftp->cwd($dir)
or &crit("dir");
if ( $file ne '' ) {
# Load Line listing in an array
@line=$ftp->dir($file)
or &crit("list");
# Close Connection
$ftp->quit;
# Cut away the unwanted parts of the string
$line=substr($line[0],42);
$line=~ s/^\s+//;
$line=~ s/\s+/ /g;
# Split the string
@date = split(/ /, $line);
# Convert the last part of the sting
if ($date[2] =~ m/:/) {
$time=$date[2];
$date[2]=$year;
}
# Convert the date into Unix Time
$t1 = str2time("$date[0] $date[1] $date[2] $time");
# Actual time
$now=time();
# Caculate the time difference in minutes
$mins = ($now - $t1) / $min;
# Round the Result
$mins = sprintf ("%.0f", $mins);
}
#
sub crit()
{
$problem = $_[0];
$status = 2;
if ( $problem eq 'connect' ) {
$output = " can't connect to $host";
} elsif ( $problem eq 'login' ) {
$output = "can't log as $username";
} elsif ( $problem eq 'dir' ) {
$output = "can't open $dir";
} elsif ( $problem eq 'list' ) {
$output = "$file does not exist";
}
}
if (( $critical != 0 ) && ( $critical < $mins )) {
$status = 2;
$output = "$file changed $mins minutes ago";
} elsif (( $warning!= 0 ) && ( $warning < $mins )) {
$status = 1;
$output = "$file changed $mins minutes ago";
} elsif (( $critical != 0 ) || ( $warning !=0 ) && ( $file ne '' )) {
$status = 0;
$output = "$file changed $mins minutes ago";
} elsif ( $file ne '' ) {
$status = 0;
$output = "$file exists";
}
if($status == 0 ) {
$info="OK:";
} elsif ($status == 1 ) {
$info="WARNING:";
} elsif ( $status == 2 ) {
$info="CRITICAL:";
}
print "$info $output\n";
exit $status;
https://assets.nagios.com/downloads/nag ... ios-XI.pdf
Former Nagios employee
https://www.mcapra.com/
https://www.mcapra.com/
-
- DevOps Engineer
- Posts: 19396
- Joined: Tue Nov 15, 2011 3:11 pm
- Location: Nagios Enterprises
- Contact: