Nagwin status show (null)

11 posts / 0 new
Last post
mach1688
Offline
Last seen: 8 years 8 months ago
Joined: 11.10.2012 - 00:17
Nagwin status show (null)

Hi,

I have Perl script access DB and execute SP. The return code comply with the Nagios Plugin requirement.
The echo %ERRORLEVEL% shows different result after run the script in command line. However I am unable to see Nagwin show different status when the monitoring application is up/down. It always shows critical with null status. I am using NagWin 1.2 version. I also try Nagwin 1.3 - same result. Nagwin 1.3 produce more critical service and the host is always down.

Please advise how should I resolve the issue. Appreciate the help.

Here's my perl script

use DBI;
use Getopt::Long;

my ($hardcoded, $sql_user, $sql_pass);
# If you have a universal 'support' login for MS SQL server, set $hardcoded to 1
# and then set the SQL username and password.
$hardcoded = 0;
$sql_user = "";
$sql_pass = "";

our $OK = 0;
our $WARNING = 1;
our $CRITICAL = 2;
our $UNKNOWN = 3;

our %status_text = (
  $OK => "OK",
  $WARNING => "WARNING",
  $CRITICAL => "CRITICAL",
  $UNKNOWN => "UNKNOWN"
);

my ($opt_h, $opt_proc, $opt_host, $opt_db, $opt_user, $opt_pw, $opt_c, $opt_w, $opt_ver);
Getopt::Long::Configure('bundling');
GetOptions(
     "h"   => \$opt_h, "help"  => \$opt_h,
     "p=s"   => \$opt_proc,  "procedure=s"  => \$opt_proc,
     "H=s"   => \$opt_host,  "hostname=s"  => \$opt_host,
     "d=s"   => \$opt_db,    "database=s"  => \$opt_db,
     "u=s"   => \$opt_user,  "user=s"  => \$opt_user,
     "P=s"   => \$opt_pw,    "password=s"  => \$opt_pw,        
     "c=s"   => \$opt_c,     "critical=s"  => \$opt_c,
     "w=s"   => \$opt_w,     "warning=s"  => \$opt_w,
     "v"     => \$opt_ver,    "version"  => \$opt_ver,
);

if ($opt_h) {
    print_help();
    exit;
}

if ($opt_ver) {
  print_version();
  exit;
}

if ($hardcoded) {
  $opt_user = $sql_user;
  $opt_pw = $sql_pass;
  }

if ($opt_host eq "" or $opt_proc eq "" or $opt_user eq "" or $opt_pw eq "" or $opt_c eq "" or $opt_w eq "") {
print "ERROR: Mandatory arguments -H, -u, -P, -p, -c and -w are required.\n";
print "Please see '$0 --help' for addtional informaton\n";
exit;
}

my $conn;

$conn{"username"} = $opt_user;
$conn{"server"} = $opt_host;
$conn{"password"} = $opt_pw;
$conn{"dsn"} = "dbi:ODBC:Driver={SQL Server};SERVER=" . $conn{"server"};
$conn{"dbh"} = DBI-> connect( $conn{"dsn"}, $conn{"username"}, $conn{"password"})
  or die "Error: Unable to connect to MS-SQL database!\n", $DBI::errstr,"\n";

# go to the database first
my $sql = qq{ use $opt_db };
my $sth = $conn{"dbh"}->prepare( $sql );
$sth->execute();

# do query
$sql = qq{ exec $opt_proc};
$sth = $conn{"dbh"}->prepare( $sql );
$sth->execute();

my( $result );
$sth->bind_columns( undef, \$results );

while( $sth->fetch() ) {
  process_results($results);
}

$sth->finish();
$conn{"dbh"}->disconnect();

sub process_results {
  my ($results) = shift;
  my ($response);
  if($results >= $opt_c) {
   $response = "SQL Query returned $results for stored procedure '$opt_proc'. The critical threshold is $opt_c.\n";
   ExitProgram($CRITICAL, $response); 
  }
  elsif($results >= $opt_w) {
   $response = "SQL Query returned $results for stored procedure '$opt_proc'. The warning threshold is $opt_w.\n";
   ExitProgram($WARNING, $response);   
  }
  else {
   $response = "Returned value $results within acceptable limits for stored procedure '$opt_proc'.\n";
   ExitProgram($OK, $response);
  }
}

sub ExitProgram
{
  my ($exitcode, $message) = @_;

  print "MSSQL_SProc $status_text{$exitcode} - $message";
  exit ($exitcode);
}

itefix
Offline
Last seen: 39 min 26 sec ago
Joined: 01.05.2008 - 21:33
Exit code seems normal. I

Exit code seems normal. I assume that SQL Server support exists in the ODBC::Dbi module. Which Perl do you use ? How do you call this plugin from Nagwin ?

 

mach1688
Offline
Last seen: 8 years 8 months ago
Joined: 11.10.2012 - 00:17
Hi. Perl 5, version 14.. The

Hi.

Perl 5, version 14.. The exit code is correct - either OK=0 if application is up or Critical=2 if application is down.

Here's how I configure this service in localhost.cfg

# Test Plugins 1 : check MSSQL SP execution result
define command {
       command_name    mssqlsvr-sp-run
       command_line    /usr/bin/perl $USER1$/check_mssql_sproc.pl --hostname $ARG1$ --procedure $ARG3$ --database $ARG2$  --user $USER3$ --password $USER4$ --warning 2 --critical 5
}

 

# Service: MSSQL Server SP checking
define service{
        use                             local-service,srv-pnp         ; Name of service template to use
        host_name                       localhost
        service_description             MSSQL Server SP checking
    check_command         mssqlsvr-sp-run!PC-890009\SQL2005!db_MD_511_IVR!Nagios_SPTest
        }      

 

BTW: try in Nagwin 1.3, the status is "return code of 127 is out of bounds - plugin may be missing"

the host is always "down". I think check_winping didn't work properly in my case.

 

Thanks

 

 

itefix
Offline
Last seen: 39 min 26 sec ago
Joined: 01.05.2008 - 21:33
Perl 5.14 ? Nagwin 1.3 free

Perl 5.14 ? Nagwin 1.3 free doesn't contain Perl. Our commercial Nagwin distributions have Perl 5.10. Do you have a home made setup ? As I mentioned before, output logic in your plugin seems ok. The problem must be somewhere else. I am afraid we can't provide any help here. We try to support what we offer from this website.

mach1688
Offline
Last seen: 8 years 8 months ago
Joined: 11.10.2012 - 00:17
Hi, thanks for your

Hi,

thanks for your information. I think the problem is in the Plugins configuratin. I add logic in the Plugins to dump information in a log file. when I run the script in command line, log file show update. But there's no sign showing Nagios is executing the script. How do we confirm Nagios is running the service with the provided command? appreciate the help!

itefix
Offline
Last seen: 39 min 26 sec ago
Joined: 01.05.2008 - 21:33
How does your nagios command

How does your nagios command definition look like ?

mach1688
Offline
Last seen: 8 years 8 months ago
Joined: 11.10.2012 - 00:17
Hi, Thanks for further help.

Hi,

Thanks for further help. Here's my command confgiuration. I also modify resource.cfg to add $USER3$ and $USER4$ for my SQL server user name/password.

# Test Plugins 1 : check MSSQL SP execution result for Nagwin 1.2
define command {
       command_name    mssqlsvr-sp-run
       command_line    /usr/bin/perl $USER1$/check_mssql_sproc.pl --hostname $ARG1$ --procedure $ARG3$ --database $ARG2$  --user $USER3$ --password $USER4$ --warning 1 --critical 2
}

# Test Plugins 1 : check MSSQL SP execution result for Nagwin 1.2
define command {
       command_name    mssqlsvr-sp-run
       command_line   $USER2$/perl $USER1$/check_mssql_sproc.pl --hostname $ARG1$ --procedure $ARG3$ --database $ARG2$  --user $USER3$ --password $USER4$ --warning 1 --critical 2
}

# Service: MSSQL Server SP checking
define service{
        use                             local-service,srv-pnp         ; Name of service template to use
        host_name                       localhost
        service_description             MSSQL Server SP checking
    check_command         mssqlsvr-sp-run!PC-890009\SQL2005!db_MD_511_IVR!Nagios_SPTest
        }     

 

BTW: you menioned Perl didn't come with Nagwin 1.3 free version. Is that why the status of host is always down (check_winping) and a couple of services which are Perl script like check_winprocess give back- (return code of 127 is out of bounds - plugins may be missing). Please advise how to resolve this issue - make perl script Plugins run in Nagwin 1.3.

really appreciate your help!

Regards,

ICM

 

mach1688
Offline
Last seen: 8 years 8 months ago
Joined: 11.10.2012 - 00:17
Hi, I download the new free

Hi,

I download the new free Perl script plugins with standalone executable - check_winprocess and check_winping.

Now Nagwin 1.3 no longer show local host status is down and two services using check_winprocess are working properly.

I convert my perl script as standalone exe file and test in Nagwin. Now, I got error which is (Return code of 255 is out of bounds)

Any advice how to resolve it?

BTW: the .exe work fine under command line.

 

 

mach1688
Offline
Last seen: 8 years 8 months ago
Joined: 11.10.2012 - 00:17
Hi, I turn on all the debug

Hi,

I turn on all the debug informaiton and found the error is in the service configuration

    check_command         mssqlsvr-sp-run!PC-890009\SQL2005!db_MD_511_IVR!Nagios_SPTest

The error log shows

DBI connect('Driver={SQL Server};SERVER=PC-890009SQL2005','sa',...) failed: [Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not exist or access denied. (SQL-08001) [state was 08001 now 01000]
[Microsoft][ODBC SQL Server Driver][DBNETLIB]ConnectionOpen (Connect()). (SQL-01000) at check_mssql_sproc.pl line 93
Error: Unable to connect to MS-SQL database!

It looks backslash won't be allowed as the argument.

How do we resolve this?

Thanks

Regards,

ICM

 

itefix
Offline
Last seen: 39 min 26 sec ago
Joined: 01.05.2008 - 21:33
Try double backslashes.

Try double backslashes.

mach1688
Offline
Last seen: 8 years 8 months ago
Joined: 11.10.2012 - 00:17
Hi tk, That's the first thing

Hi tk,

That's the first thing I tried. It's not working. I also tried 'PC-890009/\SQL2005'. same result.

I modify the Perl script to take two parameters for host name and contact with "\\". Now the plugin is working with Nagios.

Thanks for all the help!

 

Regards,

ICM