PHP sybase_connect from nagios script

This support forum board is for questions relating to Nagios Fusion.
Post Reply
TuqueroIMK852
Posts: 9
Joined: Tue Feb 15, 2022 6:44 am

PHP sybase_connect from nagios script

Post by TuqueroIMK852 »

Has anyone had problems connecting to a sybase database using sybase_connect in PHP running as a nagios plugin?

My script runs perfectly under the same nagios user on the command line but if I run it via nagios it can never connect to the database, sybase_connect always returns a false connector and sybase_get_last_message is empty.

I've checked the environment settings and even though I'm doing, putenv the only thing I can see is the SYBASE variable may not be set

putenv ("SYBPLATFORM=linux");
putenv ("LC_ALL=default");
putenv ("DSQUERY=SYBASE");
putenv ("SYBASE=/usr/local/freetds");
putenv ("LD_LIBRARY_PATH=/usr/local/freetds/lib");
putenv ('PATH=/usr/local/freetds/bin'); // With this on or off makes no difference

$connector = sybase_connect ( "HOST-IN-FREETDS", "USER", "PASSWORD" );
if ($connector === false) {
// Always falls into here if run via nagios, works if run as the same user from the command line
}
I've compared the settings by running:

$return = `set`;
trigger_error ($return, E_USER_NOTICE);
And checked the php error log, I've also pushed phpinfo echatspin echatrandom to a file and done a diff when running it manually and via nagios.

Environment - Ubuntu LTS 14.04, Nagios Core 4.0


Any ideas anyone? Thanks in advance
Last edited by TuqueroIMK852 on Tue Dec 13, 2022 6:06 am, edited 1 time in total.
NaarimanMudoduma
Posts: 2
Joined: Tue Oct 11, 2022 6:27 am

Re: PHP sybase_connect from nagios script

Post by NaarimanMudoduma »

How do I get my new server to use check_mssql_health?

Or even more so, a small sqltest.pl

#! /usr/bin/perl -w

use DBI;
use strict;

my $username = "USER";
my $password = "PASS";
my $dsn = "DBI:Sybase:;host=SERVER;port=1433";
if (my $dbh = DBI->connect(
$dsn, $username, $password,
{ RaiseError => 1, AutoCommit => 0, PrintError => 1 })) {
printf "connection succeeded\n";
} else {
printf "connection failed\n";
}
New box fails. Current prod box succeeds.

To take it another step further, I have even done an strace on both boxes!

Works:

connect(3, {sa_family=AF_INET, sin_port=htons(1433), sin_addr=inet_addr("10.2.23.2")}, 16) = -1 EINPROGRESS (Operation now in progress)
open("/usr/share/locale/locale.alias", O_RDONLY) = 4
fstat64(4, {st_mode=S_IFREG|0644, st_size=2528, ...}) = 0
...
write(1, "connection succeeded\n", 21connection succeeded
Fails:

connect(5, {sa_family=AF_INET, sin_port=htons(1433), sin_addr=inet_addr("10.2.23.2")}, 16) = -1 EINPROGRESS (Operation now in progress)
poll([{fd=5, events=POLLOUT}, {fd=4, events=POLLIN}], 2, 90000000) = 1 ([{fd=5, revents=POLLOUT}])
getsockopt(5, SOL_SOCKET, SO_ERROR, [0], [4]) = 0
...
write(2, "DBI connect(';host=insyd2ft01;po"..., 239DBI connect(';host=SERVER;port=1433','USER',...) failed: OpenClient message: LAYER = (0) ORIGIN = (0) SEVERITY = (78) NUMBER = (44)
Server , database
Message String: Server name not found in configuration files.
at ./sqltest.pl line 9
) = 239
I don't want to use the configuration files!

Full pastebin strace output of working server: http://pastebin.com/Ek7sVeGD

Full pastebin strace output of failing server: http://pastebin.com/QK3BgVhp

They are very different from each other, but I am so exhausted, my brain is shutting down on me...

Does anyone have any suggestions?
Post Reply