[nagiosplug] check_disk_smb: Add performance data
"Nagios Plugin Development" <[email protected]> Sat, 23 Jun 2012 08:40:09 +0000
| Newsgroups | gmane.network.nagios.plugins.cvs |
|---|---|
| Message-ID | <[email protected]> |
Module: nagiosplug Branch: master Commit: d61a3056c598bf030e699a094671727f841eca8c Author: Holger Weiss <[email protected]> Date: Sat Jun 23 10:22:08 2012 +0200 URL: http://nagiosplug.git.sf.net/git/gitweb.cgi?p=nagiosplug/nagiosplug;a=commit;h=d61a305 check_disk_smb: Add performance data (Debian #654259 - Charles-Henri Larose) --- NEWS | 1 + THANKS.in | 1 + plugins-scripts/check_disk_smb.pl | 44 ++++++++++++++++++++++++++---------- 3 files changed, 34 insertions(+), 12 deletions(-) diff --git a/NEWS b/NEWS index b138084..29ca455 100644 --- a/NEWS +++ b/NEWS @@ -13,6 +13,7 @@ This file documents the major additions and syntax changes between releases. check_sensors now detects faulty sensors unless --ignore-fault is specified (Jan Wagner) utils.sh now provides a check_range function (Alex Griffin) Improved the performance of check_users (Marc Remy) + Add perfdata to check_disk_smb (Debian #654259 - Charles-Henri Larose) Updated Nagios::Plugin perl module FIXES diff --git a/THANKS.in b/THANKS.in index 943acdb..b9368a4 100644 --- a/THANKS.in +++ b/THANKS.in @@ -274,3 +274,4 @@ Alex Griffin Marc Remy Matej Vela Jason Ellison +Charles-Henri Larose diff --git a/plugins-scripts/check_disk_smb.pl b/plugins-scripts/check_disk_smb.pl index 6783543..43841c3 100755 --- a/plugins-scripts/check_disk_smb.pl +++ b/plugins-scripts/check_disk_smb.pl @@ -166,6 +166,7 @@ my $address = $1 if (defined($opt_a) && $opt_a =~ /(.*)/); my $state = "OK"; my $answer = undef; my $res = undef; +my $perfdata = ""; my @lines = undef; # Just in case of problems, let's not hang Nagios @@ -204,11 +205,23 @@ $_ = $lines[$#lines]; #If line does not match required regexp, return an UNKNOWN error if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) { - my ($avail) = ($3*$2)/1024; - my ($avail_bytes) = $avail; + my ($avail_bytes) = $3 * $2; + my ($total_bytes) = $1 * $2; + my ($occupied_bytes) = $1 * $2 - $avail_bytes; + my ($avail) = $avail_bytes/1024; my ($capper) = int(($3/$1)*100); my ($mountpt) = "\\\\$host\\$share"; + # TODO : why is the kB the standard unit for args ? + my ($warn_bytes) = $total_bytes - $warn * 1024; + if ($warn_type eq "P") { + $warn_bytes = $warn * $1 * $2 / 100; + } + my ($crit_bytes) = $total_bytes - $crit * 1024; + if ($crit_type eq "P") { + $crit_bytes = $crit * $1 * $2 / 100; + } + if (int($avail / 1024) > 0) { $avail = int($avail / 1024); @@ -225,32 +238,37 @@ if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) { #print ":$warn:$warn_type:\n"; #print ":$crit:$crit_type:\n"; #print ":$avail:$avail_bytes:$capper:$mountpt:\n"; + $perfdata = "'" . $share . "'=" . $occupied_bytes . 'B;' + . $warn_bytes . ';' + . $crit_bytes . ';' + . '0;' + . $total_bytes; - if ((($warn_type eq "P") && (100 - $capper) < $warn) || (($warn_type eq "K") && ($avail_bytes > $warn))) { - $answer = "Disk ok - $avail ($capper%) free on $mountpt\n"; - } elsif ((($crit_type eq "P") && (100 - $capper) < $crit) || (($crit_type eq "K") && ($avail_bytes > $crit))) { + if ($occupied_bytes > $crit_bytes) { + $state = "CRITICAL"; + $answer = "CRITICAL: Only $avail ($capper%) free on $mountpt"; + } elsif ( $occupied_bytes > $warn_bytes ) { $state = "WARNING"; - $answer = "WARNING: Only $avail ($capper%) free on $mountpt\n"; + $answer = "WARNING: Only $avail ($capper%) free on $mountpt"; } else { - $state = "CRITICAL"; - $answer = "CRITICAL: Only $avail ($capper%) free on $mountpt\n"; + $answer = "Disk ok - $avail ($capper%) free on $mountpt"; } } else { - $answer = "Result from smbclient not suitable\n"; + $answer = "Result from smbclient not suitable"; $state = "UNKNOWN"; foreach (@lines) { if (/(Access denied|NT_STATUS_LOGON_FAILURE|NT_STATUS_ACCESS_DENIED)/) { - $answer = "Access Denied\n"; + $answer = "Access Denied"; $state = "CRITICAL"; last; } if (/(Unknown host \w*|Connection.*failed)/) { - $answer = "$1\n"; + $answer = "$1"; $state = "CRITICAL"; last; } if (/(You specified an invalid share name|NT_STATUS_BAD_NETWORK_NAME)/) { - $answer = "Invalid share name \\\\$host\\$share\n"; + $answer = "Invalid share name \\\\$host\\$share"; $state = "CRITICAL"; last; } @@ -259,6 +277,8 @@ if (/\s*(\d*) blocks of size (\d*)\. (\d*) blocks available/) { print $answer; +print " | " . $perfdata if ($perfdata); +print "\n"; print "$state\n" if ($verbose); exit $ERRORS{$state}; ------------------------------------------------------------------------------ Live Security Virtual Conference Exclusive live event will cover all the ways today's security and threat landscape has changed and how IT managers can respond. Discussions will include endpoint security, mobile security and the latest in malware threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/