Command variable resolution problem

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Bitflogger
Posts: 226
Joined: Mon Oct 16, 2017 9:24 am

Command variable resolution problem

Post by Bitflogger »

Hello, I'm at v5.5.2 64-bit VM CentOS 7

I try to pass a command a complex $ARG1$, "DBI:Oracle:host=$_SERVICEHOST$\;port=$_SERVICEPORT$\;service_name=$_SERVICESID$"

The program gets: DBI:Oracle:host=$\;port=$\;service_name=$

The variable names are defined.

How can this be fixed?

Earl
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Command variable resolution problem

Post by lmiltchev »

The program gets: DBI:Oracle:host=$\;port=$\;service_name=$
Where do you see this? Is this the output that you get when testing your check under the CCM by clicking on Run Check Command?

It is possible that the variables do resolve but not under the CCM (when testing). Is the actual service check failing?

Also, can you give us an example of how these variables are defined, and an example of the entire check? Hide/redact sensitive info.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Bitflogger
Posts: 226
Joined: Mon Oct 16, 2017 9:24 am

Re: Command variable resolution problem

Post by Bitflogger »

Hello,

It has a problem in the test run and the production run.

Attached are some screen prints. The service name is e_db_admindb.

xiscreen shows the top item displaying a error message from the check_sql program
xiscreen.png
nagios4_config shows the configuration in the file.
nagios4_config.png
command_config shows the command in the file.
command_config.png
check_sql_error_message_code shows the code in the check_sql program that produces the message.
Please note the two commented out lines above that, showing my work testing this to see the actual dsn variable value which is in the first post.
Its not letting me add that, so:

#print("dsn = $dsn\n");
#exit(0);
$np->nagios_exit('UNKNOWN', 'DSN contains invalid characters.')
if ($dsn =~ /\`|\~|\!|\$|\%|\^|\&|\*|\||\'|\"|\<|\>|\?|\,|\(|\)/);

Earl
You do not have the required permissions to view the files attached to this post.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Command variable resolution problem

Post by lmiltchev »

Have you tried placing this:

Code: Select all

"DBI:Oracle:host=$_SERVICEHOST$\%3Bport=$_SERVICEPORT$\%Bservice_name=$_SERVICESID$"
in your command:

Code: Select all

command_line  $USER5$/check_sql -d "DBI:Oracle:host=$_SERVICEHOST$\%3Bport=$_SERVICEPORT$\%Bservice_name=$_SERVICESID$" -P ...
instead of placing it in $ARG1$ in your service definition?

This *should* fix the issue or at least get you a step closer.
Be sure to check out our Knowledgebase for helpful articles and solutions!
Bitflogger
Posts: 226
Joined: Mon Oct 16, 2017 9:24 am

Re: Command variable resolution problem

Post by Bitflogger »

Hello,

I took out the check for the % symbol in check_sql code.

Now I get the "can't find" error:
sql_fail_2.png
This works as a command line script:

[ead@winston ~]$ cat check_sql.sh
#!/bin/sh
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/12.1/client64/lib
export ORACLE_HOME=/usr/lib/oracle/12.1/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin
/opt/local/nagios-extra/check_sql -d "DBI:Oracle:host=dbh1-scan.doit.wisc.edu;port=1900;service_name=admindb" -P ** -U ** -w 5 -c 10 -q "select 'x' from dual" -e 'x'

[ead@winston ~]$ ./check_sql.sh
CHECK_SQL OK - SQL responded in 0.092238 seconds | time=0.092238s;5;10

As per documentation https://support.nagios.com/kb/article.php?id=489
(although I did not understand the path change part), I added:

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/12.1/client64/lib
export ORACLE_HOME=/usr/lib/oracle/12.1/client64
export TNS_ADMIN=$ORACLE_HOME/network/admin

to the file /etc/sysconfig/nagios

And ran sudo service nagios restart.

Earl
You do not have the required permissions to view the files attached to this post.
Bitflogger
Posts: 226
Joined: Mon Oct 16, 2017 9:24 am

Re: Command variable resolution problem

Post by Bitflogger »

I should add that I did the /etc/sysconfig/nagios change much earlier, so the problem still exists.
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Command variable resolution problem

Post by lmiltchev »

Have you modified your command and service definition respectively as suggested? Can you show us the new, modified check_sql_generic command and e_db_admindb service configs?

Also, run the following command from the command line and show the output:

Code: Select all

env | grep -i 'oracle\|pwd'
Be sure to check out our Knowledgebase for helpful articles and solutions!
Bitflogger
Posts: 226
Joined: Mon Oct 16, 2017 9:24 am

Re: Command variable resolution problem

Post by Bitflogger »

Here they are:

define service {
host_name dbh1-scan.doit.wisc.edu
service_description e_db_admindb
use generic-ss-service
check_command check_sql_generic2!"DBI:Oracle:host=$_SERVICEHOST$\%3Bport=$_SERVICEPORT$\%3Bservice_name=$_SERVICESID$"!**!**!$_SERVICEWARNING_SECS$!$_SERVICECRITICAL_SECS$!!!
check_interval 5
process_perf_data 1
notification_interval 5760
notification_options w,c,r,
contact_groups 940bc8d7e43d371534fb1846708a19d4c0eae97300,exadata-apps,ovo-ss-db
_ci (ci:940bc8d7e43d371534fb1846708a19d4c0eae97300)
_critical_secs 20
_host dbh1-scan.doit.wisc.edu
_port 1900
_sid admindb
_support_info Critical denotes an issue with Exadata admindb database on dbh1-scan.
_warning_secs 10
register 1
}

define command {
command_name check_sql_generic2
command_line $USER5$/check_sql -d "DBI:ORACLE:host=$_SERVICEHOST$\%3Bport=$_SERVICEPORT$\%3Bservice_name=$_SERVICESID$" -P $ARG2$ -U $ARG3$ -w $ARG4$ -c $ARG5$ -q "select 'x' from dual" -e 'x'
}

[ead@winston etc]$ sudo su - nagios -c "env | grep -i 'oracle\|pwd'"
PWD=/home/nagios
[ead@winston etc]$

Earl
User avatar
lmiltchev
Bugs find me
Posts: 13589
Joined: Mon May 23, 2011 12:15 pm

Re: Command variable resolution problem

Post by lmiltchev »

You showed us earlier that your script was called check_sql.sh, but in your command, you are using check_sql...
command_line $USER5$/check_sql -d "DBI:ORACLE:host=$_SERVICEHOST$\%3Bport=$_SERVICEPORT$\%3Bservice_name=$_SERVICESID$" -P $ARG2$ -U $ARG3$ -w $ARG4$ -c $ARG5$ -q "select 'x' from dual" -e 'x'
Modify your command by changing check_sql to check_sql.sh to see if this is going to fix your issue. Thank you!
Be sure to check out our Knowledgebase for helpful articles and solutions!
Bitflogger
Posts: 226
Joined: Mon Oct 16, 2017 9:24 am

Re: Command variable resolution problem

Post by Bitflogger »

Hello,

I see some advantage to having the ID and Password buried in a script file off of Nagios XI. So making the XI command very simple, and having one script file for each DB test works.

Please lock the call.

Earl
Locked