Basically it's rather a simple thing to get running. Your command line will look like this:
perl ms_sql.pl hostname dbinstance dbname1,dbname2,dbname3
Do not put the $ in front of the dbinstance value, the script does that automatically. You can list any number of individual databases seperated by comma's at the end, including the _Total if you want that value.
When you make your Data Input method you'll have to create three input fields, and however many output fields you're expecting. Which is exactly why I'm not creating templates ahead of time.
Feel free to make changes to this code to get whatever values you want. I just did this to provide examples of how to retrieve the values using the check_nt program.
Enjoy
Here's the code:
Code: Select all
#!/usr/bin/perl
# Replace '/usr/local/nagios/libexec/check_nt' with the localtion where your check_nt binary is located
$CheckNTPath='/usr/lib/nagios/plugins';
@array1 = split(/\,/, $ARGV[2]);
$tempdb = `$CheckNTPath/check_nt -H $ARGV[0] -p 1248 -v COUNTER -l '\\MSSQL\$$ARGV[1]:Transactions\\Free Space in tempdb (KB)'`;
chomp $tempdb;
$TActions = `$CheckNTPath/check_nt -H $ARGV[0] -p 1248 -v COUNTER -l '\\MSSQL\$$ARGV[1]:Transactions\\Transactions'`;
chomp $TActions;
$Users = `$CheckNTPath/check_nt -H $ARGV[0] -p 1248 -v COUNTER -l '\\MSSQL\$$ARGV[1]:General Statistics\\User Connections'`;
chomp $Users;
foreach $dbname (@array1)
{
$dbSize = `$CheckNTPath/check_nt -H $ARGV[0] -p 1248 -v COUNTER -l '\\MSSQL\$$ARGV[1]:Databases($dbname)\\Data File(s) Size (KB)'`;
chomp $dbSize;
$cache = `$CheckNTPath/check_nt -H $ARGV[0] -p 1248 -v COUNTER -l '\\MSSQL\$$ARGV[1]:Catalog Metadata($dbname)\\Cache Hit Ratio'`;
chomp $cache;
$Output1 .= @array1[$x] . "_size:" . $dbSize . " ";
$Output2 .= @array1[$x] . "_cache:" . $cache . " ";
push(@PrintVal,$Output1);
push(@PrintVal,$Output2);
$x = $x + 1;
}
print "Users:" . $Users . " " .
"Transactions:" . $TActions . " " .
"TempDb:" . $tempdb . " " .
$Output1 .
$Output2 .
"\n";
exit 0;