No output returned from plugin but working from CLI
Posted: Wed Sep 12, 2018 3:54 am
I have written an plugin in shell which will call sqlplus and get results from a query about db job status. This works file when run through CLI on nagios server but shows (No output returned from plugin) on Dashboard.
service:
define service {
service_description Check DAS purge
use generic-service
hostgroup_name xyz
check_command check_purge_status!<PREFIX>!daspurge!!!
max_check_attempts 5
check_interval 720
retry_interval 60
check_period xi_timeperiod_24x7
notification_interval 1440
notification_period xi_timeperiod_24x7
register 1
}
commands
define command {
command_name check_purge_status
command_line $USER1$/check_purge_status $ARG1$ $ARG2$
}
plugin check_purge_status in /usr/local/nagios/libexec
-----------------------------
#!/bin/bash
# Return Codes for Nagios
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
ORA_HOME=/sita/shared/latest-oracle-client/app/config/product/12.1.0/client_1
SQL_QUERY_CONF=/usr/local/nagios/libexec/nagios_sql_query.conf
MAPPING=/usr/local/nagios/libexec/prefixmapping.conf
OUTFILE=/tmp/purgestatus
today=`date '+%d-%^b-%y'`
prefix=$1
action=$2
url=`cat $MAPPING | grep $prefix | cut -f2 -d"|"`
if [ $action = 'daspurge' ]
then
user=${prefix}DASCORE
pass=${prefix}DASCORE
fi
query=`cat $SQL_QUERY_CONF | grep $action | cut -f2 -d"|" | sed -e "s/<DATE>/$today/g"`
#echo $query
conn_str=${user}/${pass}@${url}
#echo $conn_str
${ORA_HOME}/bin/sqlplus -S $conn_str << EOF >> $OUTFILE
set heading off;
$query
exit;
EOF
sed -i '/^$/d' $OUTFILE
final_status=`cat $OUTFILE`
echo 1$final_status
if [ "$final_status" = "SUCCEEDED" ]
then
rm $OUTFILE
echo $final_status
exit $OK
else
rm $OUTFILE
echo $final_status
exit $CRITICAL
fi
----------------------------
service:
define service {
service_description Check DAS purge
use generic-service
hostgroup_name xyz
check_command check_purge_status!<PREFIX>!daspurge!!!
max_check_attempts 5
check_interval 720
retry_interval 60
check_period xi_timeperiod_24x7
notification_interval 1440
notification_period xi_timeperiod_24x7
register 1
}
commands
define command {
command_name check_purge_status
command_line $USER1$/check_purge_status $ARG1$ $ARG2$
}
plugin check_purge_status in /usr/local/nagios/libexec
-----------------------------
#!/bin/bash
# Return Codes for Nagios
OK=0
WARNING=1
CRITICAL=2
UNKNOWN=3
ORA_HOME=/sita/shared/latest-oracle-client/app/config/product/12.1.0/client_1
SQL_QUERY_CONF=/usr/local/nagios/libexec/nagios_sql_query.conf
MAPPING=/usr/local/nagios/libexec/prefixmapping.conf
OUTFILE=/tmp/purgestatus
today=`date '+%d-%^b-%y'`
prefix=$1
action=$2
url=`cat $MAPPING | grep $prefix | cut -f2 -d"|"`
if [ $action = 'daspurge' ]
then
user=${prefix}DASCORE
pass=${prefix}DASCORE
fi
query=`cat $SQL_QUERY_CONF | grep $action | cut -f2 -d"|" | sed -e "s/<DATE>/$today/g"`
#echo $query
conn_str=${user}/${pass}@${url}
#echo $conn_str
${ORA_HOME}/bin/sqlplus -S $conn_str << EOF >> $OUTFILE
set heading off;
$query
exit;
EOF
sed -i '/^$/d' $OUTFILE
final_status=`cat $OUTFILE`
echo 1$final_status
if [ "$final_status" = "SUCCEEDED" ]
then
rm $OUTFILE
echo $final_status
exit $OK
else
rm $OUTFILE
echo $final_status
exit $CRITICAL
fi
----------------------------