The following examples show how to create user-defined
alert type scripts on Linux to handle different alerting scenarios.
Generate an alert if file system utilization is high
The
following shell script generates a warning alert if any file system
on the database server exceeds 90 percent utilization, and a critical
alert if any file system on the database server exceeds 95 percent
utilization.
#!/bin/sh
# Percent usage thresholds that will flag a problem -- change as needed
myCriticalLimit=95
myWarningLimit=90
cumulativeSeverity=0
checkThresholdBreach()
{
fsUsage=$1
limit=$2
severity=$3
percentValue=`echo ${fsUsage} | cut -d% -f1`
if [ ${percentValue} -ge ${limit} ]; then
if [ ${cumulativeSeverity} -gt ${severity} ]; then
cumulativeSeverity=${severity}
fi
echo "Threshold ${limit}% reached for ${fsUsage}. Severity: ${severity}"
fi
}
checkFileSystemUsage()
{
capacityOutput=`df -kP | grep -vE '^Filesystem|tmpfs|cdrom|/proc' | awk '{ print $5 "," $1 }' `
for output in ${capacityOutput}
do
checkThresholdBreach ${output} ${myCriticalLimit} -2
checkThresholdBreach ${output} ${myWarningLimit} -1
done
}
checkFileSystemUsage
echo cumulativeSeverity = ${cumulativeSeverity}
exit $cumulativeSeverity
Generate an alert if amount of free space in memory
is low
The following shell script generates a warning alert
if the amount of free memory space is less than 10 megabytes and a
critical alert if the free memory space is less than 5 megabytes.
freemem=$(cat /proc/meminfo | grep SwapFree | cut -d ":" -f 2 | awk '{print $1}')
echo freemem is $freemem
if [ $freemem -ge 2000000 ]; then
returnValue=0
else
returnValue=-1
fi
exit $returnValue
Generate an alert for database backup
In this
example, the SQL-only script generates a critical alert if the last
backup operation for a production database occurred at a certain date
and time.
SELECT CASE last_backup
WHEN
(SELECT TIMESTAMP(CURRENT DATE - 7 DAYS, CURRENT TIME) FROM sysibm.sysdummy1)
THEN
-2
ELSE
0
END AS returnvalue
FROM sysibmadm.snapdb
Generate an alert for diagnostic records
In
this example, the SQL-only script generates a warning alert if the
level of 'W' (Warning) is recorded in the DB2 general diagnostic
logs, and a critical alert if the recorded level is 'E'
(Error), 'C' (Critical), or 'S' (Severe).
SELECT CASE level
WHEN 'W' THEN -1
WHEN 'E' THEN -2
WHEN 'C' THEN -2
WHEN 'S' THEN -2
ELSE 0
END AS RETURNVALUE
FROM TABLE (PD_GET_DIAG_HIST('MAIN','E', '', CAST (NULL AS TIMESTAMP), CAST (NULL AS TIMESTAMP))) AS T