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 critical alert if any file system
on the database server exceeds 90 percent utilization.
#!/bin/sh
df -kP | grep -vE 'ˆFilesystem|tmpfs|cdrom' | awk '{ print $5 " " $1 }' | while read output;
do
echo $output
usep=$(echo $output | awk '{ print $1}' | cut -d'%' -f1 )
echo usep is $usep
if [ $usep -ge 90 ]; then
returnValue=-2
echo "Running out of space on ($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.
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