I'm basically querying a remote Windows SQL Server from my Nagios server. It works well when executed from linux CLI (./check_sql.pl), but it returns empty output while executing from Web UI. What is really bugging me is that the output fails to be printed only if it is AFTER the "connect" method. Here's the code:
Code: Select all
#!/usr/bin/perl -w
use DBI;
use Getopt::Long;
my %ERRORS=('OK'=>0,'WARNING'=>1,'CRITICAL'=>2,'UNKNOWN'=>3,'DEPENDENT'=>4);
my $data_source = "dbi:ODBC:dbxwc_app6";
my $dbh = DBI->connect($data_source, 'username', 'password') or die "Can't connect to $data_source: $DBI::errstr";
my $sql = "select client,acount,lastexecution from nagiosContaPOP";
my $sth = $dbh->prepare( $sql ) or die "Can't prepare statement: $DBI::errstr";
$sth->execute();
# Bind the results to the local variables
$sth->bind_columns(undef, \$cliente, \$acc, \$date);
# Retrieve values from the result set
while( $sth->fetch() ) {
print("[Client:$client | Account:$acc | Since:$date] ");
}
$sth->finish();
$dbh->disconnect();
print "Testing...";
exit 0;
- it will print at the test check
If there is any "exit" anywhere BEFORE the DBI->connect:
- the Web UI will return valid status code (ok, warn, crit)
If there is any "print" anywhere AFTER the DBI->connect:
- the test check will return empty output
If there is any "exit" anywhere AFTER the DBI->connect:
- the Web UI will return "(Return code of 255 is out of bounds)"
(^ this is exaclty what happens when you provide no exit status nor text output)
Both print and status code will always print at linux CLI, no matter where they are placed.