Db2 issue

This support forum board is for support questions relating to Nagios XI, our flagship commercial network monitoring solution.
Locked
raamardhani7
Posts: 459
Joined: Tue Jun 02, 2015 12:36 am

Db2 issue

Post by raamardhani7 »

Hi Team,

We are working on the custom scripts to get the required information from the remote server using NRPE.

Here is the script that is written for the same.

Code: Select all

#!/bin/sh
###############################################################################
#         Title: DB2 Database Transaction Log Utilization
#        Author: Chris Park
#          Date: Mar. 11th, 2016
# Example usage: ./check_Db2_transaction_log_util.sh [Database Name] [Database Profile Location]
#
# This script checks the database Transaction Log Utilization.
# Retrieves a critical alarm when the total log used percentage is bigger than the given size in critical,
# or retrieves a warning alarm when the total log used percentage is bigger than the provided,
# comparing with the allocated utilization.
#
###############################################################################

SERVER=`hostname`
DBNAME="$1"
PROFILE="$2"

. $PROFILE

# Nagios return codes
STATE_OK=0
STATE_WARNING=1
STATE_CRITICAL=2
STATE_UNKNOWN=3

PROGNAME=$(basename $0)

print_usage() {
        echo ""
        echo "$PROGNAME"
        echo ""
        echo "Usage: $PROGNAME $ARG1$ $ARG2$"
        echo ""
        echo "# $ARG1$: Database Name"
        echo "# $ARG2$: Database Profile Location"
        echo ""
        echo ""
}

# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
TMP_OUTPUT="/tmp/db2_trans_log_util_out"

db2 connect to $DBNAME| db2 'select substr(DB_NAME,1,10) DB_NAME,LOG_UTILIZATION_PERCENT total_log_used_kb, total_log_available_kb from SYSIBMADM.LOG_UTILIZATION'|grep $DBNAME > $TMP_OUTPUT

TMP_DB_USED_KB=`cat "$TMP_OUTPUT" | awk '{print $2}'`
TMP_DB_AVAILABLE_KB=`cat "$TMP_OUTPUT" | awk '{print $3}'`

if [[ "$TMP_DB_USED_KB" == "0.00" ]]
   then
      DB_USED_PERCENT=0
#elif [[ "$TMP_DB_USED_KB" == "" ]]
elif [[ -z "$TMP_DB_USED_KB" ]]
   then
      DB_USED_PERCENT=0
   else
      DB_USED_PERCENT=`echo "$TMP_DB_USED_KB * 100" |bc|sed 's/[.].*//'`
fi

#if [[ -z "$TMP_DB_AVAILABLE_KB" -eq "" ]]
if [[ -z "$TMP_DB_AVAILABLE_KB" ]]
   then
      DB_AVAILABLE_MB=0
   else
      DB_AVAILABLE_MB=`expr "$TMP_DB_AVAILABLE_KB" / 1024`
fi

if [ -f $TMP_OUTPUT ]
   then
       rm -f $TMP_OUTPUT
fi

#3979811
SYMBOL="%"
#CRITICAL State
CDB_USED_PERCENT=90

# WARNING State
WDB_USED_PERCENT=85

if [[ $DB_USED_PERCENT -gt $CDB_USED_PERCENT ]]; then
     TEMP_STATUS="CRITICAL"
     RETURN_STATUS=$STATE_CRITICAL
elif [[ $DB_USED_PERCENT -gt $WDB_USED_PERCENT ]]; then
     TEMP_STATUS="WARNING"
     RETURN_STATUS=$STATE_WARNING
else
     TEMP_STATUS="OK"
     RETURN_STATUS=$STATE_OK
fi
FINAL_STATUS="$TEMP_STATUS|Total_log_Used:$DB_USED_PERCENT${SYMBOL}, Toal_log_Available:${DB_AVAILABLE_MB}MB, Db_Name:$DBNAME"
echo $FINAL_STATUS
exit $RETURN_STATUS
We ran the script in remote server and the output is:

Code: Select all

$ ./check_Db2_transaction_log_util.sh MCCD13X /db2/home/mccdev/sqllib/db2profile
OK|Total_log_Used:1%, Toal_log_Available:3886MB, Db_Name:MCCD13X
When we are running the same from Nagios server, we are not getting the desired results on the first instance. If the same command is run for 4 or 5 times, it is showing us the right information.

Code: Select all

[root@lussvpnagiosxi00 ~]# /usr/local/nagios/libexec/check_nrpe -H dalcpldd10 -t 30 -c check_Db2_transaction_log_util.sh -a 'MCCD13X /db2/home/mccdev/sqllib/db2profile' -n
OK - Total log Used is 0 % and Toal log available is 0(MB) of MCCD13X on the server dalcpldd10
You have new mail in /var/spool/mail/root
[root@lussvpnagiosxi00 ~]# /usr/local/nagios/libexec/check_nrpe -H dalcpldd10 -t 30 -c check_Db2_transaction_log_util.sh -a 'MCCD13X /db2/home/mccdev/sqllib/db2profile' -n
OK - Total log Used is 0 % and Toal log available is 0(MB) of MCCD13X on the server dalcpldd10
[root@lussvpnagiosxi00 ~]# /usr/local/nagios/libexec/check_nrpe -H dalcpldd10 -t 30 -c check_Db2_transaction_log_util.sh -a 'MCCD13X /db2/home/mccdev/sqllib/db2profile' -n
OK - Total log Used is 0 % and Toal log available is 0(MB) of MCCD13X on the server dalcpldd10

Code: Select all

[root@lussvpnagiosxi00 ~]# /usr/local/nagios/libexec/check_nrpe -H dalcpldd10 -t 30 -c check_Db2_transaction_log_util.sh -a 'MCCD13X /db2/home/mccdev/sqllib/db2profile' -n
OK - Total log Used is 1 % and Toal log available is 3886(MB) of MCCD13X on the server dalcpldd10
Check command configured in nrpe:

Code: Select all

command[check_Db2_transaction_log_util.sh]=/usr/local/nagios/libexec/check_Db2_transaction_log_util.sh $ARG1$
Could you please help us here. thanks.
raamardhani7
Posts: 459
Joined: Tue Jun 02, 2015 12:36 am

Re: Db2 issue

Post by raamardhani7 »

Therefore, when we ran the db2 command on the command prompt, it works. However, when you run through the shell script, it does not work properly. It's very random.
raamardhani7
Posts: 459
Joined: Tue Jun 02, 2015 12:36 am

Re: Db2 issue

Post by raamardhani7 »

I also specified absolute path in the script as below. However, it's still very random output...
#!/usr/bin/bash

export PATH=$PATH:/usr/bin:/etc:/usr/sbin:/usr/ucb:/usr/bin/X11:/sbin:/usr/java5/jre/bin:/usr/java5/bin:/db2/home/mccdev/sqllib/bin:/db2/home/mccdev/sqllib/adm:/db2/home/mccdev/sqllib/misc
raamardhani7
Posts: 459
Joined: Tue Jun 02, 2015 12:36 am

Re: Db2 issue

Post by raamardhani7 »

Please close ticket. I resolved this matter.
Locked