retire da-backup checks
[mirror/dsa-nagios.git] / dsa-nagios-checks / checks / dsa-check-file_size
1 #!/usr/bin/perl 
2 # $Id: filesize.pl 230 2006-09-30 20:11:05Z touche $
3 #  julien.touche@touche.fr.st
4 #
5 # Added use strict, warning, treshold for min size
6 #
7 # from http://www.nagiosexchange.org/NRPE_Plugins.66.0.html?&tx_netnagext_pi1[p_view]=81
8 #################################################
9 # Small quick and dirty perl example from Larry #
10 #################################################
11 # downloaded from http://exchange.nagios.org/directory/Plugins/System-Metrics/File-System/filesize-2Epl/details
12 # by zobel 2012-01-02
13
14 use strict;
15
16 if($#ARGV+1!=3 || ! -f $ARGV[0]){
17     print "Usage: \"Filename\" \"Critical filesize\" \"Warning filesize\"\n";
18     print " exemples: $0 <file> 1024 512\n";
19     print " exemples: $0 <file> 16:1024 128:512\n";
20     exit 0;
21 }
22 my $exit=0;
23 my ($file,$maxwarn,$maxcrit,$minwarn,$mincrit);
24 $file = $ARGV[0];
25 $maxcrit = $ARGV[1];
26 if ($maxcrit =~ m/([0-9].+):([0-9].+)/) {
27     $mincrit = $1;
28     $maxcrit = $2;
29 }
30 $maxwarn = $ARGV[2];
31 if ($maxwarn =~ m/([0-9].+):([0-9].+)/) {
32     $minwarn = $1;
33     $maxwarn = $2;
34 }
35
36 my $size= (-s $file);
37
38 if ($size>$maxcrit) {
39     print "Critical: Filesize of '$file' too large $size > $maxcrit.\n";$exit=2;
40 } elsif (defined($mincrit) && $size < $mincrit) {
41     print "Critical: Filesize of '$file' too small $size < $mincrit.\n";$exit=2;
42 } elsif ($size>$maxwarn) {
43     print "Warning: Filesize of '$file' $size > $maxwarn.\n";$exit=1;
44 } elsif (defined($minwarn) && $size < $minwarn) {
45     print "Warning: Filesize of '$file' $size < $minwarn.\n";$exit=1;
46 } else {
47     print "OK: Filesize of '$file' $size.\n"; $exit = 0;
48 }
49 exit $exit;