Hi,
We are using an SQL query check here which returns a value from 0-99 from a table. I want to create the -w to 10 and -c to 20 within the query.
The perl code is as follows:
!/usr/bin/perl
use strict;
use warnings;
use Getopt::Std;
my $sqsh='/usr/bin/sqsh'; # Full path to SQSH command
my $cmd=''; # OS command to pass to CLI
my %opts=(); # HASH to store CLI options
my @output=''; # Output from OS CLI
my $numflag=1; # Assume the data being returned is numeric,
# Change this to 0 if it isn't
my $outmsg='Check';
my $new_data='';
my $err=0;
my @errmsg=qw(OK WARNING CRITICAL);
getopts('D:d:w:c:a:H:S:P:U:C:bh',\%opts);
foreach (keys %opts) {
next if m/[cwbhdCa]/;
$cmd .= " -$_ $opts{$_}";
}
$cmd .= " -b -h -C \"$opts{C}\"";
if ( $opts{d} ) {print "cmd: $cmd\n";}
@output=`$sqsh $cmd`;
$new_data=$output-1];
chomp $new_data;
$new_data =~ s/^ \t]*//g;
if ( $opts{d} ) { print "Output: $new_data\n";}
# Check if the output returned is numeric
if ( ($new_data !~ /^\d+$/) ) {
$numflag=0;
}
if ( defined($opts{w}) && ($new_data gt $opts{w}) ) { $err=1; }
if ( defined($opts{c}) && ($new_data gt $opts{c}) ) { $err=2; }
if ( defined($opts{a}) ) { $outmsg = $opts{a}; }
print "$outmsg $errmsg$err]: $new_data";
if ( $numflag ) { print "|$outmsg=$new_data";}
if ( defined($opts{c}) && ($new_data gt $opts{c}) ) { exit 2; }
if ( defined($opts{w}) && ($new_data gt $opts{w}) ) { exit 1; }
exit 0
The problem I am having is that if we run the check with -H hostname -D dbname - U username -P password -w10 -c20 -C “SQL_QUERY” then the returned value only see’s the first digit - for example 10 comes back as 1 and 20 comes back as 2 ?
any help would be appreciated.