Sample scripts for user-defined alert types

The following examples show how to create user-defined alert type scripts to handle different alerting scenarios.

Generate an alert if file system utilization is high

The following shell script generates a critical alert if any file system on the database server exceeds 90 percent utilization.
df -H | grep -vE '^Filesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
  echo $output
  usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1  )
  partition=$(echo $output | awk '{ print $2 }' )
if [ $usep -ge 90 ]; then
  returnValue = 2
    echo "Running out of space \"$partition ($usep%)\" on $(hostname) as on $(date)" 
else returnValue = 0
fi
done
exit $returnValue

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.
if [cat /proc/meminfo | grep SwapFree  | cut –d ‘:' –f2 -ge 200000]
exit 0
else if [cat /proc/meminfo | grep SwapFree  | cut –d ‘:' –f2 -lt 100000]
exit 1
else if [cat /proc/meminfo | grep SwapFree  | cut –d ‘:' –f2 -lt 50000]
exit 2

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 ‘2012-01-06-22.47.42.000000' 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 
ELSE WHEN ‘E' OR ‘C' OR ‘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

Feedback