| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | # ---------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 3 | # © Copyright 2003-2011 by Alex Peeters [alex.peeters@citap.be] | ||||||||||||||||||||||||||||||||||||||||||
| 4 | # ---------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 5 | # 2011/mm/dd, v3.002.003, check_template-ftp.pl | ||||||||||||||||||||||||||||||||||||||||||
| 6 | # ---------------------------------------------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use warnings; # Must be used in test mode only. This reduces a little process speed | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | #use diagnostics; # Must be used in test mode only. This reduces a lot of process speed | ||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 0 | ▶ | BEGIN { if ( $ENV{ASNMTAP_PERL5LIB} ) { eval 'use lib ( "$ENV{ASNMTAP_PERL5LIB}" )'; } } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=9.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 7 | ▶ | use ASNMTAP::Asnmtap::Plugins::Nagios v3.002.003; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 7 | ▶ | use ASNMTAP::Asnmtap::Plugins::Nagios qw(:NAGIOS); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | 7 | my $objectNagios = ASNMTAP::Asnmtap::Plugins::Nagios->new ( | |||||||||||||||||||||||||||||||||||||||||
| 24 | _programName => 'check_template-ftp.pl', | ||||||||||||||||||||||||||||||||||||||||||
| 25 | _programDescription => 'FTP Nagios Template', | ||||||||||||||||||||||||||||||||||||||||||
| 26 | _programVersion => '3.002.003', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | _programGetOptions => ['host|H=s', 'username|u|loginname=s', 'password|p|passwd=s', 'environment|e=s', 'trendline|T:i'], | ||||||||||||||||||||||||||||||||||||||||||
| 28 | _timeout => 30, | ||||||||||||||||||||||||||||||||||||||||||
| 29 | _debug => 0); | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | my $host = $objectNagios->getOptionsArgv ('host'); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 1 | my $username = $objectNagios->getOptionsArgv ('username'); | |||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | my $password = $objectNagios->getOptionsArgv ('password'); | |||||||||||||||||||||||||||||||||||||||||
| 34 | 1 | my $environment = $objectNagios->getOptionsArgv ('environment'); | |||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 1 | my $debug = $objectNagios->getOptionsValue ('debug'); | |||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | 1 | my $timeout = $objectNagios->timeout (); | |||||||||||||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||||||||||||||
| 40 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 41 | # Start plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 42 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 1 | my $returnValue = 1; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 7 | ▶ | use Net::FTP; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 1 | ▶ | my $ftp = Net::FTP->new(Host => $host, Timeout => $timeout, Debug => $debug) or $returnValue = errorTrapFTP ("Cannot connect to $host", "$@", $debug); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 48 | 1 | ▶ | $ftp->login($username, $password) or $returnValue = errorTrapFTP ('Cannot login', $ftp->message, $debug) if ($returnValue); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$returnValue && ($ftp->login($username, $password) || ($returnValue = errorTrapFTP('Cannot login', $ftp->message, $debug)))
$ftp->login($username, $password) or $returnValue = errorTrapFTP("Cannot login", $ftp->message, $debug)
MC/DC0%0/3
$returnValue && ($ftp->login($username, $password) || ($returnValue = errorTrapFTP('Cannot login', $ftp->message, $debug)))
$returnValue
$ftp->login($username, $password)
$returnValue = errorTrapFTP("Cannot login", $ftp->message, $debug)
Truth table0%0/4
A && B or C
A= $returnValueB= $ftp->login($username, $password)C= $returnValue = errorTrapFTP("Cannot login", $ftp->message, $debug)
| |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 1 | ▶ | if ( $returnValue ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | print "You are logged on\n" if ($debug); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 54 | # Start plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 55 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||||||||||||||||
| 57 | # $ftp->cwd ("/test") or $returnValue = errorTrapFTP ("Cannot change to directory", $ftp->message, $debug ) if ($returnValue); | ||||||||||||||||||||||||||||||||||||||||||
| 58 | # $ftp->ascii or $returnValue = errorTrapFTP ("Transfer file in ascii mode", $ftp->message, $debug ) if ($returnValue); | ||||||||||||||||||||||||||||||||||||||||||
| 59 | # $ftp->binary or $returnValue = errorTrapFTP ("Transfer file in binary mode", $ftp->message, $debug ) if ($returnValue); | ||||||||||||||||||||||||||||||||||||||||||
| 60 | # $ftp->get ("that.file") or $returnValue = errorTrapFTP ("Get failed", $ftp->message, $debug ) if ($returnValue); | ||||||||||||||||||||||||||||||||||||||||||
| 61 | # $ftp->ls or $returnValue = errorTrapFTP ("List ", $ftp->message, $debug ) if ($returnValue); | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 64 | # End plugin - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 65 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 1 | ▶ | $ftp->quit or $returnValue = errorTrapFTP ('Quit', $ftp->quit, $debug) if ($returnValue); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition16%1/6
$returnValue && ($ftp->quit || ($returnValue = errorTrapFTP('Quit', $ftp->quit, $debug)))
$ftp->quit or $returnValue = errorTrapFTP("Quit", $ftp->quit, $debug)
MC/DC0%0/3
$returnValue && ($ftp->quit || ($returnValue = errorTrapFTP('Quit', $ftp->quit, $debug)))
$returnValue
$ftp->quit
$returnValue = errorTrapFTP("Quit", $ftp->quit, $debug)
Truth table0%0/4
A && B or C
A= $returnValueB= $ftp->quitC= $returnValue = errorTrapFTP("Quit", $ftp->quit, $debug)
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 1 | ▶ | $objectNagios->pluginValues ( { stateValue => $ERRORS{OK}, alert => 'OKIDO' }, $TYPE{APPEND} ) if ( $returnValue ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | $objectNagios->exit (7); | |||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||||||||||||||
| 74 | 1 | ▶ | sub errorTrapFTP { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
errorTrapFTP: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||||||||||||||||
| 75 | 1 | my ($error_message, $ftp_message, $debug) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 76 | 1 | ▶ | print "$error_message\n" if ($debug); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 1 | chomp ($ftp_message); | |||||||||||||||||||||||||||||||||||||||||
| 78 | 1 | $objectNagios->pluginValues ( { stateValue => $ERRORS{CRITICAL}, error => $error_message .': '. $ftp_message, result => '' }, $TYPE{APPEND} ); | |||||||||||||||||||||||||||||||||||||||||
| 79 | 1 | return 0; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | __END__ | ||||||||||||||||||||||||||||||||||||||||||