Article Listing 1 Listing 2 Listing 3 Listing 4
Listing 5 Listing 6 Listing 7 Listing 8 Listing 9
Listing 10 apr2004.tar

Listing 8 eliminate redundant alerts

#!/bin/ksh
# Listing 8:
# Description:
#
# This utility, typically called from send_alerts script, eliminates
# redundant alerts by sending duplicates to the sent directory without 
# processing them through the configuration process.

. $(dirname $0)/setenv_monitor

get_alert_attribute()
{
    head -4 $1 | grep "$2=" | cut -d= -f2
}

TEMP_STRINGS_FILE=/tmp/filter_alerts.$$
> $TEMP_STRINGS_FILE

#====================================================== 
# Process all alerts files in the new alerts directory.
#====================================================== 
for alert_file in $(find $NEW_ALERTS_DIR -type f | sort -r)
do

    #===================================================
    # Build a string based on host, priority, and class.
    #===================================================

    alert_host=$(get_alert_attribute $alert_file host)
    alert_priority=$(get_alert_attribute $alert_file priority)
    alert_class=$(get_alert_attribute $alert_file class)

    attribute_string=$alert_host.$alert_priority.$alert_class

    #=======================================================
    # Only keep the most recent alert file for a given host,
    # priority, and class combination.
    #=======================================================
    if [ $(fgrep $attribute_string $TEMP_STRINGS_FILE | wc -l) -gt 0 ]
    then
        mv $alert_file $SENT_ALERTS_DIR
        echo "outdated: $(basename $alert_file)"
    else
        echo $attribute_string >> $TEMP_STRINGS_FILE
    fi
done

rm $TEMP_STRINGS_FILE
# End Listing 8: