diff options
| author | Subhendu Ghosh <sghosh@users.sourceforge.net> | 2002-04-07 05:13:57 +0000 |
|---|---|---|
| committer | Subhendu Ghosh <sghosh@users.sourceforge.net> | 2002-04-07 05:13:57 +0000 |
| commit | d71f56c42e6fe08a81eef2667a868bddbf2b751e (patch) | |
| tree | fd6320cf819389ab9b6296f2e603f5c8540df99c /contrib | |
| parent | 733523442b7cc577b750d66d211eb00f1decc799 (diff) | |
| download | monitoring-plugins-d71f56c42e6fe08a81eef2667a868bddbf2b751e.tar.gz | |
plugins from Patrick Greenwell
git-svn-id: https://nagiosplug.svn.sourceforge.net/svnroot/nagiosplug/nagiosplug/trunk@14 f882894a-f735-0410-b71e-b25c423dba1c
Diffstat (limited to 'contrib')
| -rw-r--r-- | contrib/check_backup.pl | 114 | ||||
| -rw-r--r-- | contrib/check_dl_size.pl | 148 |
2 files changed, 262 insertions, 0 deletions
diff --git a/contrib/check_backup.pl b/contrib/check_backup.pl new file mode 100644 index 00000000..703d2424 --- /dev/null +++ b/contrib/check_backup.pl | |||
| @@ -0,0 +1,114 @@ | |||
| 1 | #! /usr/bin/perl -wT | ||
| 2 | |||
| 3 | # (c)2001 Patrick Greenwell, Stealthgeeks, LLC. (patrick@stealthgeeks.net) | ||
| 4 | # Licensed under the GNU GPL | ||
| 5 | # http://www.gnu.org/licenses/gpl.html | ||
| 6 | |||
| 7 | # check_backup: Checks a directory to see if at least one file was | ||
| 8 | # created within a specified period of time that is of equal to or greater | ||
| 9 | # than a given size. | ||
| 10 | |||
| 11 | # Version 1.0 | ||
| 12 | # Last Updated: 9/12/01 | ||
| 13 | |||
| 14 | |||
| 15 | BEGIN { | ||
| 16 | if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { | ||
| 17 | $runtimedir = $1; | ||
| 18 | $PROGNAME = $2; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | require 5.004; | ||
| 23 | use strict; | ||
| 24 | use Getopt::Long; | ||
| 25 | use vars qw($opt_H $opt_d $opt_s $opt_t $verbose $PROGNAME); | ||
| 26 | use lib $main::runtimedir; | ||
| 27 | use utils qw($TIMEOUT %ERRORS &print_revision &usage &support &is_error); | ||
| 28 | |||
| 29 | sub help (); | ||
| 30 | sub print_help (); | ||
| 31 | sub print_usage (); | ||
| 32 | sub version (); | ||
| 33 | sub display_res($$); | ||
| 34 | my ($filesize, $answer) = (); | ||
| 35 | my $state = $ERRORS{'UNKNOWN'}; | ||
| 36 | |||
| 37 | # Directory to check. | ||
| 38 | my $dir = "/backup/"; | ||
| 39 | |||
| 40 | # Time period(in seconds) | ||
| 41 | my $within = "3600"; | ||
| 42 | |||
| 43 | # Minimum size of file (in bytes) | ||
| 44 | my $minsize = "40000000"; | ||
| 45 | |||
| 46 | delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; | ||
| 47 | |||
| 48 | Getopt::Long::Configure('bundling', 'no_ignore_case'); | ||
| 49 | GetOptions | ||
| 50 | ("V|version" => \&version, | ||
| 51 | "h|help" => \&help, | ||
| 52 | "v|verbose" => \$verbose, | ||
| 53 | "d|directory=s" => \$opt_d, | ||
| 54 | "s|minsize=s" => \$opt_s, | ||
| 55 | "t|timeout=s" => \$opt_t, | ||
| 56 | ); | ||
| 57 | |||
| 58 | ($opt_s) || ($opt_s = shift) || usage("Minimum File size not specified\n"); | ||
| 59 | usage("File size must be numeric value") unless ($opt_s =~ m/^[0-9]+$/); | ||
| 60 | |||
| 61 | (($opt_t) && ($TIMEOUT = $opt_t)) || ($TIMEOUT = 120); | ||
| 62 | usage("TIMEOUT must be numeric value") unless ($TIMEOUT =~ m/^[0-9]+$/); | ||
| 63 | |||
| 64 | # Don't hang if there are timeout issues | ||
| 65 | $SIG{'ALRM'} = sub { | ||
| 66 | print ("ERROR: No response from ftp server (alarm)\n"); | ||
| 67 | exit $ERRORS{'UNKNOWN'}; | ||
| 68 | }; | ||
| 69 | alarm($TIMEOUT); | ||
| 70 | |||
| 71 | # Do stuff | ||
| 72 | |||
| 73 | my $time = time; | ||
| 74 | |||
| 75 | opendir(THISDIR, "$dir") or die "Can't open directory! $!"; | ||
| 76 | my @allfiles = grep !/^\./, readdir THISDIR; | ||
| 77 | closedir THISDIR; | ||
| 78 | while (my $file = $dir . pop @allfiles){ | ||
| 79 | my ($size, $mtime) = (stat($file))[7,9]; | ||
| 80 | if (((my $a = ($time - $mtime)) <= $within) and ($size >= $opt_s)){ | ||
| 81 | display_res("OK: File $file is <= $within and >=$opt_s bytes.\n","OK"); | ||
| 82 | } | ||
| 83 | } | ||
| 84 | |||
| 85 | # If we got here nothing matched.... | ||
| 86 | display_res("CRITICAL: No files in $dir are <= $within and >= $minsize.", "CRITICAL"); | ||
| 87 | |||
| 88 | exit; | ||
| 89 | |||
| 90 | sub print_usage () { | ||
| 91 | print "Usage: $PROGNAME -s <minimum file size in bytes> -t <timeout> \n"; | ||
| 92 | } | ||
| 93 | |||
| 94 | sub print_help () { | ||
| 95 | print_revision($PROGNAME,'$ Revision: 1.0 $ '); | ||
| 96 | print_usage(); | ||
| 97 | support(); | ||
| 98 | } | ||
| 99 | |||
| 100 | sub version () { | ||
| 101 | print_revision($PROGNAME,'$ Revision: 1.0 $ '); | ||
| 102 | exit $ERRORS{'OK'}; | ||
| 103 | } | ||
| 104 | |||
| 105 | sub help () { | ||
| 106 | print_help(); | ||
| 107 | exit $ERRORS{'OK'}; | ||
| 108 | } | ||
| 109 | |||
| 110 | sub display_res ($$) { | ||
| 111 | my ($answer, $state) = @_; | ||
| 112 | print $answer; | ||
| 113 | exit $ERRORS{$state}; | ||
| 114 | } | ||
diff --git a/contrib/check_dl_size.pl b/contrib/check_dl_size.pl new file mode 100644 index 00000000..e6cbda8b --- /dev/null +++ b/contrib/check_dl_size.pl | |||
| @@ -0,0 +1,148 @@ | |||
| 1 | #! /usr/bin/perl -wT | ||
| 2 | |||
| 3 | # (c)2001 Patrick Greenwell, Stealthgeeks, LLC. (patrick@stealthgeeks.net) | ||
| 4 | # Licensed under the GNU GPL | ||
| 5 | # http://www.gnu.org/licenses/gpl.html | ||
| 6 | # | ||
| 7 | # check_dl_size: Attempts to download a specified file via FTP and verify | ||
| 8 | # it is a specified size. | ||
| 9 | # Requires Net::FTP | ||
| 10 | |||
| 11 | # Version 1.0 | ||
| 12 | # Last Updated: 8/31/01 | ||
| 13 | |||
| 14 | |||
| 15 | BEGIN { | ||
| 16 | if ($0 =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { | ||
| 17 | $runtimedir = $1; | ||
| 18 | $PROGNAME = $2; | ||
| 19 | } | ||
| 20 | } | ||
| 21 | |||
| 22 | require 5.004; | ||
| 23 | use strict; | ||
| 24 | use Getopt::Long; | ||
| 25 | use vars qw($opt_H $opt_f $opt_s $opt_t $verbose $PROGNAME); | ||
| 26 | use lib $main::runtimedir; | ||
| 27 | use utils qw($TIMEOUT %ERRORS &print_revision &usage &support &is_error); | ||
| 28 | use Net::FTP; | ||
| 29 | |||
| 30 | sub help (); | ||
| 31 | sub print_help (); | ||
| 32 | sub print_usage (); | ||
| 33 | sub version (); | ||
| 34 | sub display_res($$); | ||
| 35 | my ($ftpfile, $ftpdir, $filesize, $answer) = (); | ||
| 36 | my $state = $ERRORS{'UNKNOWN'}; | ||
| 37 | |||
| 38 | # Directory to place file. If your machine is not secure DO NOT USE /tmp. | ||
| 39 | my $dir = "/usr/local/netsaint/etc/tmp"; | ||
| 40 | |||
| 41 | # Username for login | ||
| 42 | my $user = "anonymous"; | ||
| 43 | |||
| 44 | # Password (PLEASE TAKE APPROPRIATE PRECAUTIONS TO SECURE THIS) | ||
| 45 | my $pass = "guest\@example.com"; | ||
| 46 | |||
| 47 | |||
| 48 | delete @ENV{'PATH', 'IFS', 'CDPATH', 'ENV', 'BASH_ENV'}; | ||
| 49 | |||
| 50 | Getopt::Long::Configure('bundling', 'no_ignore_case'); | ||
| 51 | GetOptions | ||
| 52 | ("V|version" => \&version, | ||
| 53 | "h|help" => \&help, | ||
| 54 | "v|verbose" => \$verbose, | ||
| 55 | "H|hostname=s" => \$opt_H, | ||
| 56 | "f|filename=s" => \$opt_f, | ||
| 57 | "s|filesize=s" => \$opt_s, | ||
| 58 | "t|timeout=s" => \$opt_t, | ||
| 59 | ); | ||
| 60 | |||
| 61 | ($opt_H) || ($opt_H = shift) || usage("Host address or name not specified\n"); | ||
| 62 | my $host = $1 | ||
| 63 | if ($opt_H =~ m/^(([0-9]{1,3}\.){3}[0-9]{1,3}|(([a-z0-9]+(\-+[a-z0-9]+)*|\.))+[a-z])$/i); | ||
| 64 | usage("Please provide a valid IP address or host name\n") unless ($host); | ||
| 65 | |||
| 66 | ($opt_f) || ($opt_f = shift) || usage("File name not specified\n"); | ||
| 67 | |||
| 68 | if ($opt_f =~ m/^(.*?)[\/\\]([^\/\\]+)$/) { | ||
| 69 | $ftpdir = $1; | ||
| 70 | $ftpfile = $2; | ||
| 71 | } | ||
| 72 | |||
| 73 | ($opt_s) || ($opt_s = shift) || usage("File size not specified\n"); | ||
| 74 | usage("File size must be numeric value") unless ($opt_s =~ m/^[0-9]+$/); | ||
| 75 | |||
| 76 | (($opt_t) && ($TIMEOUT = $opt_t)) || ($TIMEOUT = 120); | ||
| 77 | usage("TIMEOUT must be numeric value") unless ($TIMEOUT =~ m/^[0-9]+$/); | ||
| 78 | |||
| 79 | # Don't hang if there are timeout issues | ||
| 80 | $SIG{'ALRM'} = sub { | ||
| 81 | print ("ERROR: No response from ftp server (alarm)\n"); | ||
| 82 | exit $ERRORS{'UNKNOWN'}; | ||
| 83 | }; | ||
| 84 | alarm($TIMEOUT); | ||
| 85 | |||
| 86 | # Make certain temporary directory exists | ||
| 87 | |||
| 88 | if ( ! -e "$dir" ) { | ||
| 89 | display_res("Temporary directory $dir does not exist.\n", "CRITICAL"); | ||
| 90 | |||
| 91 | } | ||
| 92 | |||
| 93 | # Remove existing file if any | ||
| 94 | |||
| 95 | if ( -e "$dir/$ftpfile") { | ||
| 96 | unlink "$dir/$ftpfile" or | ||
| 97 | display_res("Can't remove existing file $dir/$ftpfile.\n", "CRITICAL"); | ||
| 98 | } | ||
| 99 | |||
| 100 | # Snarf file | ||
| 101 | |||
| 102 | my $ftp = Net::FTP->new("$host", Passive => 1, Timeout => $TIMEOUT) or | ||
| 103 | display_res("Can't connect to $host.\n", "CRITICAL"); | ||
| 104 | $ftp->login("$user","$pass") or | ||
| 105 | display_res("Login to $host failed", "CRITICAL"); | ||
| 106 | $ftp->cwd("$ftpdir") or | ||
| 107 | display_res("Can't change to directory $ftpdir.\n", "CRITICAL"); | ||
| 108 | $ftp->get($ftpfile, "$dir/$ftpfile") or | ||
| 109 | display_res("Can't retrieve file $ftpfile.\n", "CRITICAL"); | ||
| 110 | $ftp->quit; | ||
| 111 | |||
| 112 | # If file exists and is correct size we are happy. | ||
| 113 | |||
| 114 | if (( -e "$dir/$ftpfile" ) && (($filesize = -s "/tmp/$ftpfile") eq $opt_s)) { | ||
| 115 | display_res("File $ftpfile size OK: $filesize bytes.\n", "OK"); | ||
| 116 | } else { | ||
| 117 | # Otherwise we are not happy. | ||
| 118 | display_res("File $ftpfile size incorrect: $filesize bytes", "CRITICAL"); | ||
| 119 | } | ||
| 120 | |||
| 121 | exit; | ||
| 122 | |||
| 123 | sub print_usage () { | ||
| 124 | print "Usage: $PROGNAME -H <host> -f <filename> -s <file size in bytes> -t <timeout> \n"; | ||
| 125 | } | ||
| 126 | |||
| 127 | sub print_help () { | ||
| 128 | print_revision($PROGNAME,'$ Revision: 1.0 $ '); | ||
| 129 | print "Copyright (c) 2001 Patrick Greenwell, Stealthgeeks, LLC.\n\n"; | ||
| 130 | print_usage(); | ||
| 131 | support(); | ||
| 132 | } | ||
| 133 | |||
| 134 | sub version () { | ||
| 135 | print_revision($PROGNAME,'$ Revision: 1.0 $ '); | ||
| 136 | exit $ERRORS{'OK'}; | ||
| 137 | } | ||
| 138 | |||
| 139 | sub help () { | ||
| 140 | print_help(); | ||
| 141 | exit $ERRORS{'OK'}; | ||
| 142 | } | ||
| 143 | |||
| 144 | sub display_res ($$) { | ||
| 145 | my ($answer, $state) = @_; | ||
| 146 | print $answer; | ||
| 147 | exit $ERRORS{$state}; | ||
| 148 | } | ||
