Problem to execute custom script from NagiosXI
Posted: Mon Jun 07, 2021 10:25 am
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
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