procmail
[Top] [All Lists]

Re: track error messages to limit notification

1998-11-29 18:07:13
In addition to some comments, I have a correction to the script I
posted yesterday.

On Sat, 28 Nov 1998 15:39:59 +0200 (EET), I wrote:
The bulk of the work would still be done by the script, but you would
feed it a command line parameter containing some sort of cookie, e.g.
the From_ line of the current message, and you'd want a lock on the
script so only one copy can be running at the same time:

(Perhaps the script itself should do all the locking it needs. Then
it's safe to test it from the command line, and you could say
something along these lines:

    :0
    * ^Subject:[        ]*alert:
    {
        :0:
        * ^\/From .*
        * ? COOKIEFILE="alert2" script-which-does-the-real-work "$MATCH" ;
        | handle-first-in-a-series >>alerts

        # script returned false -- it's a duplicate report
        :0E:
        alerts
    }

I'll point out again that this means you need to change the script so
it does all the required locking itself. With this syntax I propose
here, it would also need to override COOKIEFILE with its built-in
value only if the variable is not already set in the environment. 
[I only include it here to point out this possibility, it's not
necessary for just one type of alerts.]

If you want to store duplicates, and store and forward the first
alert, the above becomes

    :0
    * ^Subject:[        ]*alert:
    {
        :0c  # forward to pager if first in a series
        * ^\/From .*
        * ? COOKIEFILE="alert2" script-which-does-the-real-work "$MATCH" ;
        ! self(_at_)on-the-road(_dot_)net

        # no matter what the script returned, we also save the message
        :0:
        alerts
    }

The assignment of COOKIEFILE is of course not necessary if you only
want to use one cookie file for all alerts, in which case the trailing
semicolon [arbitrary SHELLMETA character, read the docs ;^] is also
unnecessary.

This has been a long parenthesis.)

    #!/bin/sh
<...>
    test `cat "$COOKIEFILE"` = "$COOKIE" && rm -f "$COOKIEFILE"

You need an additional set of double quotes around this one. From_
lines (which is what I used for cookies, since they're easy to grab
and can reasonably be expected to come in exact duplicates rarely [but
this might not be the case for you -- if the alert thing you're using
might spew out five alerts in the same second, you need to improve on
this!]) frequently contain two spaces in a row, which will be
"normalized" into one space by the backquotes.

      test "`cat "$COOKIEFILE"`" = "$COOKIE" && rm -f "$COOKIEFILE"
           ^                   ^
Yes, this looks crazy, but it really is necessary. Even if there are
only single spaces, the quotes are necessary simply to make test(1)
see a single argument string here.

This is untested, as usual ...

Still is ;^)

perhaps switch to Perl. With Perl, it's easy enough to simply test
whether a file is older than n seconds. (This is slightly hairy in
shell scripts, unless you have an enhanced version of test(1) or like
to use find(1) for simple tasks like this -- I perceive it as too
heavy.) You could perhaps write one line to an alert log for each

(As Stan Ryckman pointed out off the list, an additional problem with
find(1) is that its finest granularity is n _days_ -- GNU find gets
that down to minutes with -mmin, but it's still not seconds.)

For a completely different approach, you could collect all alerts in a
file and set up a cron job say once an hour which would summarize the
alerts in the last hour if there were any.

/* era */

-- 
.obBotBait: It shouldn't even matter whether    <http://www.iki.fi/~era/>
I am a resident of the state of Washington. <http://members.xoom.com/procmail/>

<Prev in Thread] Current Thread [Next in Thread>