Page 1 of 1

check_mssql $USER$ macro problem

Posted: Sun May 04, 2014 5:59 am
by sureshkraj2012
Hello Team,

I have stored MSSQL credentials in the resource.cfg file and tried to call those macros in the check_mssql plugin but it does not seems to be working.

resource.cfg entries
---------------------------

$USER30$=Domain\USSQL
$USER31$=Cr$d3nt1a10#&&

Command:
/usr/local/nagios/libexec/check_mssql -H server1.domain.com --username '$USER30$' --password '$USER31' --database master --query "SELECT+COUNT%28%2A%29+FROM+sys.sysperfinfo" --result "Expected result" --decode --warning 50 --critical 200

it does working when passing clear text password without domain name.

Command:
/usr/local/nagios/libexec/check_mssql -H server1.domain.com --username 'USSQL' --password 'Cr$d3nt1a10#&&' --database master --query "SELECT+COUNT%28%2A%29+FROM+sys.sysperfinfo" --result "Expected result" --decode --warning 50 --critical 200
CRITICAL: CRITICAL: Query expected "Expected result" but got "2389".

Any help on this? I would really need to perform this check with $USER$ macros!

Re: check_mssql $USER$ macro problem

Posted: Mon May 05, 2014 10:59 am
by sreinhardt
It seems to be working great, other than you are telling it to expect a result of "Expected result" with --result "Expected result". You should change the text in quotes to a number or string that you are actually expecting. It seems to be returning 2389 for example.

Re: check_mssql $USER$ macro problem

Posted: Mon May 05, 2014 11:00 am
by tmcdonald
Actually you are missing the second $ sign in $USER31$
sureshkraj2012 wrote: /usr/local/nagios/libexec/check_mssql -H server1.domain.com --username '$USER30$' --password '$USER31' --database master --query "SELECT+COUNT%28%2A%29+FROM+sys.sysperfinfo" --result "Expected result" --decode --warning 50 --critical 200

Re: check_mssql $USER$ macro problem

Posted: Mon May 12, 2014 12:50 am
by sureshkraj2012
No. That's not a problem. (Missed $ only in the post).
The below part might be the issue since its validating username and password.

I think I should comment it and try

// Validate the username
if (isset($db_user)) {
if (!preg_match("/^[a-zA-Z0-9-]{2,32}$/", $db_user)) {
print "UNKNOWN: Invalid characters in the username.\n";
exit(3);
}
} else {
print "UNKNOWN: You must specify a username for this DB connection.\n";
exit(3);
}

// Validate the password
if (empty($db_pass)) {
print "UNKNOWN: You must specify a password for this DB connection.\n";
exit(3);
}

Re: check_mssql $USER$ macro problem

Posted: Mon May 12, 2014 11:50 am
by sreinhardt
You can certainly try commenting those out, however I can almost guarantee that it will break the plugin and cause undefined behavior within the perl script if you attempt to use any other symbols, they are generally escaped\rejected for good reason. I would also note, that you are not getting either of the unknown errors in your output, so I am slightly confused as to why you feel this is the proper portion to remove.

Re: check_mssql $USER$ macro problem

Posted: Mon May 12, 2014 4:13 pm
by Box293
sureshkraj2012 wrote:Command:
/usr/local/nagios/libexec/check_mssql -H server1.domain.com --username '$USER30$' --password '$USER31' --database master --query "SELECT+COUNT%28%2A%29+FROM+sys.sysperfinfo" --result "Expected result" --decode --warning 50 --critical 200
I think that when you use single quotes around macros they are treated as plain text (i.e. the characters $USER30$ are sent instead of their values).

Try using double quotes instead:

Code: Select all

--username "$USER30$" --password "$USER31"