Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verbose option fix #17

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 40 additions & 29 deletions check_disks.pl/check_disks.pl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

=head1 PLUGIN

check_disk.pl : check disks on Unix servers
check_disks.pl : check disks on Unix servers

=head1 ENVIRONNEMENT

Expand All @@ -19,7 +19,7 @@ =head1 CONTEXT

=head1 SYNOPSIS

./check_disk.pl [-H <host>] [-w <num>] [-c <num>] [-u <user>] [-p <path>]
./check_disks.pl [-H <host>] [-w <num>] [-c <num>] [-u <user>] [-p <path>]
[-i <dev>] [-f <fs>] [-h] [-C <file>]
-h | --help : Display this help
-w | --warning : % free space to send warning alert (default 10)
Expand All @@ -44,7 +44,7 @@ =head1 SYNOPSIS

-w and -c options allow you to ajust default threshold of all checked fs.
Theses values can be overwritten with -C option by specifying a configuration
file. perldoc ckech_disk.pl for more details.
file. perldoc check_disks.pl for more details.
If you want to use the NRPE connexion and check remote hosts, you must create
a connection without password between your nagios server and the checked host
(key exchange).
Expand All @@ -57,28 +57,28 @@ =head2 No config file for FS :
All FS will have the same threshold :

not verbose mode :
./check_disk.pl -w 20 -c 10
./check_disks.pl -w 20 -c 10
DISKS OK

verbose mode :
./check_disk.pl -w 20 -c 10 -v
DISK OK [/dev/shm 125.1M (100% free)] [/usr 1.1G (56% free)] [/ 357.2M (84%
./check_disks.pl -w 20 -c 10 -v
DISKS OK [/dev/shm 125.1M (100% free)] [/usr 1.1G (56% free)] [/ 357.2M (84%
free)] [/var 1.5G (73% free)] [/tmp 989.7M (96% free)] [/home 1.8G (90% free)]

ignore some FS :
./check_disk.pl -i /dev/shm,/tmp,/home -v
DISK OK [/usr 1.1G (56% free)] [/ 357.2M (84% free)] [/var 1.5G (73% free)]
./check_disks.pl -i /dev/shm,/tmp,/home -v
DISKS OK [/usr 1.1G (56% free)] [/ 357.2M (84% free)] [/var 1.5G (73% free)]

Specify different threshold :
./check_disk.pl -w 20 -c 10 -f /usr:30:25 -i /dev/shm,/tmp,/home -v
./check_disks.pl -w 20 -c 10 -f /usr:30:25 -i /dev/shm,/tmp,/home -v

Specify another unit (K kilo, M Mega, G Giga, T Tera) :
./check_disk.pl -w 20 -c 10 -f /usr:400M:300M -i /dev/shm,/tmp,/home
./check_disks.pl -w 20 -c 10 -f /usr:400M:300M -i /dev/shm,/tmp,/home


=head2 With a FS config file :

Syntaxe (check_disk.cfg):
Syntaxe (check_disks.cfg):

#FS WARN CRIT
/ 400M 300M
Expand All @@ -88,12 +88,16 @@ =head2 With a FS config file :
FS threshold are read in this configuration file. the -f option will
not be used.

./check_disk.pl -C check_disk.cfg -i /dev/shm,/tmp,/home
DISK WARNING [/ 357.2M (84% free)]
./check_disks.pl -C check_disks.cfg -i /dev/shm,/tmp,/home
DISKS WARNING [/ 357.2M (84% free)]

=head1 HISTORY

$Log: check_disk.pl,v $
$Log: check_disks.pl,v $

Revision 1.11 2014/12/17 11:07:00 duboip
o Fixed bug with verbose option (all mount points were always retured with options off)
o Removed extra spaces in output.

Revision 1.10 2013/03/01 14:28:00 [email protected]
o Added support for inodes
Expand Down Expand Up @@ -373,25 +377,29 @@ =head1 HISTORY

# Tests Warn et Crit de tous les fs et creation de l'output
foreach my $f (keys %checkdisks) {
if ($opt_v) { $output .= "\n"; }
my $notok = 0;
if($checkdisks{$f}->{pfree} < $checkdisks{$f}->{critical}) {
$critical_disks .= " " . $f ;
$critical_disks = join (' ', $critical_disks, $f) ;
$cmp_crit++;
}
$notok = 1;
}
elsif ($checkdisks{$f}->{pfree} < $checkdisks{$f}->{warning}) {
$warning_disks .= " " . $f ;
$warning_disks = join (' ', $warning_disks, $f) ;
$cmp_warn++;
$notok = 1;
} else {
$ok_disks .= " " . $f ;
$ok_disks = join (' ', $ok_disks, $f) ;
}
$output .= "[$f " . byte2human($checkdisks{$f}->{free}) .
" (" . $checkdisks{$f}->{pfree} . '% free) ;' .
"warning=" . $checkdisks{$f}->{warning} . "% " .
"critical=" . $checkdisks{$f}->{critical} . "% " .
'] ' ;
if ($notok || $opt_v) {
$output .= "[ $f " . byte2human($checkdisks{$f}->{free}) .
" (" . $checkdisks{$f}->{pfree} . '% free) ;' .
"warning=" . $checkdisks{$f}->{warning} . "% " .
"critical=" . $checkdisks{$f}->{critical} . "% " .
'] ' ;
$output .= "<br>" if ($opt_html);
#$output .= "\n";

$output .= "\n" if ($opt_v);
}

# Donnees de Perfs
my $perfwarn=$alldisks{$f}->{somme}*((100-$checkdisks{$f}->{warning})/100);
$perfwarn = sprintf("%0.f",$perfwarn);
Expand All @@ -404,7 +412,6 @@ =head1 HISTORY
"0;".
"$checkdisks{$f}->{somme} ";
}

if($cmp_crit > 0) {
$retour='CRITICAL';
} elsif ($cmp_warn > 0) {
Expand All @@ -428,14 +435,18 @@ =head1 HISTORY
my $host = $cfg->get_host_by_address($opt_H) || $opt_H;

open(FP, ">>$opt_srvperf/$host.perfdata") ;
print FP time(),"|$host|disk|DISK $retour $output|$perf_data\n" ;
print FP time(),"|$host|disk|DISKS $retour $output|$perf_data\n" ;
close(FP) ;
}
}

# Sortie du plugin : sans donnees de perfs qui sont stockes
# dans d'autres fichiers
print "DISK $retour $critical_disks $warning_disks ... $output | $perf_data\n";
print "DISKS $retour";
print "$critical_disks" if ( $critical_disks );
print "$warning_disks" if ( $warning_disks );
print "\n$output" if ( $output && ( $retour ne 'OK' || $opt_v ) );
print "| $perf_data\n";
exit $EXIT_CODES{$retour};

##########################################################################
Expand Down