Page 1 of 1

Problem to execute custom script from NagiosXI

Posted: Mon Jun 07, 2021 10:25 am
by dberlenda
Hello ,
I have a problem executing a custom script to check the sybase database .
If I start the script from OS the connection to the database using the isql command work fine :

QUERY_CRIT="select db_name,data_used_pct from (select db_name(d.dbid) as db_name, ceiling(sum(case when u.segmap != 4 then u.size/1048576.*@@maxpagesize end )) as data_size, ceiling(sum(case when u.segmap != 4 then size - curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end)/1048576.*@@maxpagesize) as data_used, ceiling(100*(1-1.0*sum(case when u.segmap != 4 then curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end) / sum(case when u.segmap != 4 then u.size end))) as data_used_pct from master..sysdatabases d, master..sysusages u where u.dbid = d.dbid and d.status != 256 and u.segmap != 4 group by d.dbid) a where a.data_used_pct > ${5} "

QUERY_WARN="select db_name,data_used_pct from (select db_name(d.dbid) as db_name, ceiling(sum(case when u.segmap != 4 then u.size/1048576.*@@maxpagesize end )) as data_size, ceiling(sum(case when u.segmap != 4 then size - curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end)/1048576.*@@maxpagesize) as data_used, ceiling(100*(1-1.0*sum(case when u.segmap != 4 then curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end) / sum(case when u.segmap != 4 then u.size end))) as data_used_pct from master..sysdatabases d, master..sysusages u where u.dbid = d.dbid and d.status != 256 and u.segmap != 4 group by d.dbid) a where a.data_used_pct > ${6} "

result_critical=`/usr/bin/isql -v -b ${2} ${3} ${4} <<EOF
${QUERY_CRIT}
EOF`

result_warning=`/usr/bin/isql -v -b ${2} ${3} ${4} <<EOF
${QUERY_WARN}
EOF`

echo $result_critical > /usr/local/nagios/libexec/SAP/result_query_crit.log
echo $result_warning > /usr/local/nagios/libexec/SAP/result_query_warning.log
----------------------------------------------------------------------------------------

If i execute from OS the script the var. result_critical and result_warning contain the output value of the query :
[nagios@tegd-nag-ia1 SAP]$ cat result_query_warning.log
+---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> select db_name,data_used_pct from (ap != 4 then size - curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end)/1048576.*@@maxpagesize) as data_used, ceiling(100*(1-1.0*sum(case when u.segmap != 4 then curunreservedpgs(u.dbid, u.lgmap != 4 group by d.dbid) a where a.data_used_pct > 90 +-------------------------------+---------------------------------------+ | db_name | data_used_pct | +-------------------------------+---------------------------------------+ +-------------------------------+---------------------------------------+ SQLRowCount returns 0 SQL>
[nagios@tegd-nag-ia1 SAP]$ cat result_query_crit.log
+---------------------------------------+ | Connected! | | | | sql-statement | | help [tablename] | | quit | | | +---------------------------------------+ SQL> select db_name,data_used_pct from (ap != 4 then size - curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end)/1048576.*@@maxpagesize) as data_used, ceiling(100*(1-1.0*sum(case when u.segmap != 4 then curunreservedpgs(u.dbid, u.lgmap != 4 group by d.dbid) a where a.data_used_pct > 95 +-------------------------------+---------------------------------------+ | db_name | data_used_pct | +-------------------------------+---------------------------------------+ +-------------------------------+---------------------------------------+ SQLRowCount returns 0 SQL>

But if i start the script from nagios XI the output war are empty :
-rw-r--r-- 1 nagios nagios 1 Jun 7 17:16 result_query_warning.log
-rw-r--r-- 1 nagios nagios 1 Jun 7 17:16 result_query_crit.log

[nagios@tegd-nag-ia1 SAP]$ cat result_query_warning.log

[nagios@tegd-nag-ia1 SAP]$ cat result_query_crit.log

[nagios@tegd-nag-ia1 SAP]$

It seems that if I execute the script from nagiosXI the isql command is not executed .
I tried without success to change the isql command using the DB_CONN , username and password .
for example I changed the lines :
result_critical=`/usr/bin/isql -v -b ${2} ${3} ${4} <<EOF
${QUERY_CRIT}
EOF`

to

result_critical=`/usr/bin/isql -v -b DB_CONN username password <<EOF
${QUERY_CRIT}
EOF`

DB_CONN is the nane defined in the file /etc/odbc.ini


Could you help me ?

Thanks in advance
Davide

Re: Problem to execute custom script from NagiosXI

Posted: Mon Jun 07, 2021 4:56 pm
by vtrac
Hi,
How are you doing?

Let's try your script as the followings:

Code: Select all

QUERY_CRIT="select db_name,data_used_pct from (select db_name(d.dbid) as db_name, ceiling(sum(case when u.segmap != 4 then u.size/1048576.*@@maxpagesize end )) as data_size, ceiling(sum(case when u.segmap != 4 then size - curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end)/1048576.*@@maxpagesize) as data_used, ceiling(100*(1-1.0*sum(case when u.segmap != 4 then curunreservedpgs(u.dbid, u.lstart, u.unreservedpgs) end) / sum(case when u.segmap != 4 then u.size end))) as data_used_pct from master..sysdatabases d, master..sysusages u where u.dbid = d.dbid and d.status != 256 and u.segmap != 4 group by d.dbid) a where a.data_used_pct"

echo `/usr/bin/isql -v -b DB_CONN username password < ${QUERY_CRIT}` > ${5}
or
echo $(/usr/bin/isql -v -b DB_CONN username password < ${QUERY_CRIT}) > ${5}
or
OUT1=$(/usr/bin/isql -v -b DB_CONN username password < ${QUERY_CRIT})
echo $OUT1 > ${5}
I'm not sure what "${5}" is but I think you get the idea here!! ... :-)


Best Regards,
Vinh

Re: Problem to execute custom script from NagiosXI

Posted: Tue Jun 08, 2021 7:24 am
by dberlenda
Hello Vrtac ,
thanks for your reply but is not the solution of my problem.
My big problem is that if I start the script on Operating System with user nagios the script works fine but if I start the script from nagios XI the script does not work.
For information I try to creare a script to monitor the status of remote databases sybase installated on remote servers .

Best Regards
Davide

Re: Problem to execute custom script from NagiosXI

Posted: Tue Jun 08, 2021 11:15 am
by vtrac
Hi,
How are you doing?

Since this might be executed by "apache" agent.
Please make sure user "apache" has write permission on the file and folder of SAP.

Please run this:

Code: Select all

chown apache.nagios -R /usr/local/nagios/libexec/SAP/

chmod 664 /usr/local/nagios/libexec/SAP/result_query_crit.log

chmod 664 /usr/local/nagios/libexec/SAP/result_query_warning.log
Best Regards,
Vinh

Re: Problem to execute custom script from NagiosXI

Posted: Tue Jun 08, 2021 11:38 am
by dberlenda
Hello vrtac ,
I solved my problem changed the Sybase client from unixODBC to SAP JDK client .
I installed the SAP JDK client and now with this client and changed the isql command line my custom script works fine .
If someone needs to monitor the sybase database i add some informations :
With SAP JDK client and after the creation of the client parameter file /opt/sap/interfaces my script works fine ( after the changed of isql connection string ) and also the script : check_sybase_ase ( https://exchange.nagios.org/directory/P ... se/details ) works without problems .

The SAP JDK installation does not create the file /opt/sap/interfaces , I created the file manually as follow :

NAME_REMOTE_DB
master tcp ether <IP_address> <Port>
query tcp ether <IP_address> <Port>

Best Regards
Davide

Re: Problem to execute custom script from NagiosXI

Posted: Tue Jun 08, 2021 1:43 pm
by vtrac
Hi Davide,
How are you doing?
I'm very glad that the issue has been resolved.

I have just took note of your suggestion. Thank you very much for the info.

Locking thread!!


Best Regards,
Vinh