2010-11-21 13:58:53 +01:00
|
|
|
#!/usr/bin/perl -w
|
2010-08-25 18:43:54 +02:00
|
|
|
#
|
|
|
|
# This script will check MSSQL Database size via check_nrpe and NSclient. returns performance data in Nagios format
|
|
|
|
# Author Pall Sigurdsson <palli@opensource.is>
|
|
|
|
#
|
|
|
|
|
2010-11-21 13:58:53 +01:00
|
|
|
use strict;
|
|
|
|
use Nagios::Plugin;
|
2010-08-25 18:43:54 +02:00
|
|
|
|
|
|
|
|
2010-11-21 13:58:53 +01:00
|
|
|
my $np = Nagios::Plugin->new(
|
|
|
|
usage => "Usage: %s <hostname>" );
|
2010-08-25 18:43:54 +02:00
|
|
|
|
2010-11-21 13:58:53 +01:00
|
|
|
$np->add_arg(
|
|
|
|
spec => 'debug|d=i',
|
|
|
|
help => '-d, --debug=INTEGER',
|
|
|
|
);
|
2010-08-25 18:43:54 +02:00
|
|
|
|
2010-11-21 13:58:53 +01:00
|
|
|
$np->getopts;
|
|
|
|
|
|
|
|
my $NRPECMD = "/usr/lib/nagios/plugins/check_nrpe";
|
|
|
|
|
|
|
|
if (@ARGV < 1) {
|
|
|
|
usage();
|
|
|
|
exit 3;
|
|
|
|
}
|
|
|
|
|
|
|
|
my $HOSTNAME=$ARGV[0];
|
|
|
|
|
|
|
|
|
|
|
|
my $databases = nrpeexec("-H $HOSTNAME -t 60 -c listCounterInstances -a 'SQLServer:Databases'");
|
|
|
|
my @array1 = split(/\,/, $databases);
|
|
|
|
|
|
|
|
|
|
|
|
my $num_databases = 0;
|
|
|
|
foreach my $database (@array1)
|
2010-08-25 18:43:54 +02:00
|
|
|
{
|
|
|
|
# Strip whitespace
|
|
|
|
$database =~ s/^\s*(.*?)\s*$/$1/;
|
|
|
|
|
|
|
|
# Call check_nrpe
|
2010-11-21 13:58:53 +01:00
|
|
|
my $dbSize = nrpeexec("-H $HOSTNAME -t 60 -c CheckCounter -a 'Counter:$database=\\SQLServer:Databases($database)\\Data File(s) Size (KB)'");
|
2010-08-25 18:43:54 +02:00
|
|
|
|
|
|
|
# Strip everything but the performance data
|
|
|
|
$dbSize =~ s/^.*\|(.*?)$/$1/;
|
|
|
|
chomp($dbSize);
|
2010-11-21 13:58:53 +01:00
|
|
|
$np->add_perfdata($dbSize);
|
2010-08-25 18:43:54 +02:00
|
|
|
$num_databases = $num_databases + 1;
|
2010-11-21 13:58:53 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
$np->nagios_exit( OK, "$num_databases databases found in $HOSTNAME");
|
2010-08-25 18:43:54 +02:00
|
|
|
|
|
|
|
|
2010-11-21 13:58:53 +01:00
|
|
|
|
|
|
|
sub usage {
|
|
|
|
print <<" EOUSAGE";
|
|
|
|
Usage $0 <hostname>
|
|
|
|
EOUSAGE
|
2010-08-25 18:43:54 +02:00
|
|
|
}
|
|
|
|
|
2010-11-21 13:58:53 +01:00
|
|
|
|
|
|
|
|
|
|
|
# Execute NRPE with some error handling
|
|
|
|
sub nrpeexec {
|
|
|
|
my @args = @_;
|
|
|
|
|
|
|
|
my $output = '';
|
|
|
|
if (open NRPE, "$NRPECMD " . join(' ',@args) . ' 2>&1 |') {
|
|
|
|
$output .= $_ while(<NRPE>);
|
|
|
|
close NRPE;
|
|
|
|
}
|
|
|
|
my $ret = $? >> 8;
|
|
|
|
# No such file or directory
|
|
|
|
if ($ret == 127) {
|
|
|
|
$np->nagios_die("Cannot execute $NRPECMD command missing");
|
|
|
|
# Some other error
|
|
|
|
} elsif ($ret != 0) {
|
|
|
|
$np->nagios_die("Cannot execute $NRPECMD: $!");
|
|
|
|
}
|
|
|
|
return $output;
|
|
|
|
}
|