#!/usr/bin/perl
use warnings ;
use strict ;
use Sys:: Hostname ;
use DBI ;
my $dataSource = shift ;
#my $sqlHost = shift;
#my $database = shift;
my $sqlUsername = shift ;
my $sqlPassword = shift ;
#print "$dataSource, $database, $sqlUsername, $sqlPassword, -- start --\n"; # debug
# start
my $dbh = DBI -> connect ( " DBI:ODBC: $dataSource ", $sqlUsername , $sqlPassword )
or die " Unable to connect to database using DBI:ODBC: $dataSource " . DBI -> errstr . " \n ";
my $sqlExecSP = qq( EXEC sp_SDS \@nagios = 'true' ) ;
my $sth = $dbh -> prepare ( $sqlExecSP );
#print "\n -- $sqlExecSP -- \n"; # debug
$sth -> execute
or die " Unable to execute statement: " . $sth -> errstr . " \n ";
my ( $databaseWeight , $databaseName , $databaseUsed , $databaseFree , $databaseTotal , $databaseUsedPct , $databaseFreePct , $databaseDataTotal , $databaseDataUsed , $databaseDataUsedPct , $databaseLogTotal , $databaseLogUsed , $databaseLogUsedPct , $Totals_databaseDataTotal , $Totals_databaseDataUsed , $Totals_databaseLogTotal , $Totals_databaseLogUsed );
# BIND TABLE COLUMNS TO VARIABLES
$sth -> bind_columns ( \ $databaseWeight , \ $databaseName , \ $databaseUsed , \ $databaseFree , \ $databaseTotal , \ $databaseUsedPct , \ $databaseFreePct , \ $databaseDataTotal , \ $databaseDataUsed , \ $databaseDataUsedPct , \ $databaseLogTotal , \ $databaseLogUsed , \ $databaseLogUsedPct );
print " DB ALL ";
print " | ";
$Totals_databaseDataTotal = 0 ;
$Totals_databaseDataUsed = 0 ;
$Totals_databaseLogTotal = 0 ;
$Totals_databaseLogUsed = 0 ;
# LOOP THROUGH RESULTS
while ( $sth -> fetch ()) {
print " ' $databaseName DATABASE TOTAL'= " . ( $databaseTotal = $databaseTotal * 1024 * 1024 );
print " Bytes; ";
print " ' $databaseName DATABASE USED'= " . ( $databaseUsed = $databaseUsed * 1024 * 1024 );
print " Bytes; ";
print " ' $databaseName DATABASE USED (%)'= $databaseUsedPct %; ";
print " ' $databaseName DATA TOTAL'= " . ( $databaseDataTotal = $databaseDataTotal * 1024 * 1024 );
print " Bytes; ";
print " ' $databaseName DATA USED'= " . ( $databaseDataUsed = $databaseDataUsed * 1024 * 1024 );
print " Bytes; ";
print " ' $databaseName DATA USED (%)'= $databaseDataUsedPct %; ";
print " ' $databaseName LOG TOTAL'= " . ( $databaseLogTotal = $databaseLogTotal * 1024 * 1024 );
print " Bytes; ";
print " ' $databaseName LOG USED'= " . ( $databaseLogUsed = $databaseLogUsed * 1024 * 1024 );
print " Bytes; ";
print " ' $databaseName LOG USED (%)'= $databaseLogUsedPct %; ";
$Totals_databaseDataTotal = $Totals_databaseDataTotal + $databaseDataTotal ;
$Totals_databaseDataUsed = $Totals_databaseDataUsed + $databaseDataUsed ;
$Totals_databaseLogTotal = $Totals_databaseLogTotal + $databaseLogTotal ;
$Totals_databaseLogUsed = $Totals_databaseLogUsed + $databaseLogUsed ;
}
print " 'TOTAL DB SIZE on DISK'= $Totals_databaseDataTotal ";
print " Bytes; ";
print " 'TOTAL DB USED'= $Totals_databaseDataUsed ";
print " Bytes; ";
print " 'TOTAL LOG SIZE on DISK'= $Totals_databaseLogTotal ";
print " Bytes; ";
print " 'TOTAL LOG USED'= $Totals_databaseLogUsed ";
print " Bytes; ";
#print "\n -- $sth -- \n"; # debug
$sth -> finish ();
$dbh -> disconnect ();