procmail
[Top] [All Lists]

Re: track error messages to limit notification

1998-12-02 01:26:45
David Tamkin wrote,
Jerry Shenk wrote,

| I'd like a way to have procmail process alert messages but it it gets the
| same alert every 15 minutes, only notify me on the first alert....maybe even
| the first one every day or something like that but not once every 15
| minutes.  Any ideas?

Bennett Todd has recommended swatch, about which I am thoroughly ignorant,
so it may be better than what I'm about to suggest.

One terribly q&d way is to use a cookie file.  Set up a cron job that does
this:

 0 0 * * * echo ALERT\=notyet > $HOME/path/to/.alertyet

Then in your procmail rcfile,

 :0
 * conditions to identify alert messages
 {
  INCLUDERC=$HOME/path/to/.alertyet # reads current value of $ALERT

  :0 # if you've already received one since the last cron job, lose this one
  * ALERT ?? already
  /dev/null

  :0ci # if not, rewrite the cookie file and accept this message
  | echo ALERT\=already > $INCLUDERC

  :0:
  alerts
 }

You can vary the timing of the cron job to let an alert through more often.


If you don't have cron access, or choose not to use it, you can still use the
method that David describes above. Instead of creating the cookie file as
above, create it using the day of month number from a header (From_,
Received, or Date). If it is different from what is already in your file, a
new day has dawned, so save the alert and rewrite the cookie file. Note that
the cookie file must exist, and should be seeded (sesame?) with a value,
before it is first used.

As the problem was originally stated, this all works fine. If alerts can come
in at any time (and especially if you expect more than one in a short period
of time) you must protect the section within the curlybraces with a global
lock. Combining these, we get (untested, but similar to production code):

(one time only)> echo LASTALERTED=32 > $HOME/path/to/.lastalert

 :0
 * conditions to identify alert messages
 {
  :0                      # grab day of month from From_ header time stamp
  * ^^From.* \/[0-9]+ [0-9]+:
  * MATCH ?? \\/[0-9]+
  {
    DAYofMONTH=$MATCH
  }
  :0 E                    # error, save alert if first time
  {
    DAYofMONTH=0
    LOG="How did that happen? No parsed day of month in From_ header!
"
  }

  LOCKFILE=dont.tread.on.me$LOCKEXT  # serialize access
  INCLUDERC=$HOME/path/to/.lastalert # reads current value of $LASTALERTED

  :0 # if this one is from the same day as a previous one, lose this one
  * $ LASTALERTED ?? ^^$DAYofMONTH^^
  /dev/null

  :0ci # if not, rewrite the cookie file and accept this message
  | echo LASTALERTED=$DAYofMONTH > $INCLUDERC

  :0
  alerts

  LOCKFILE
 }


--
Rik Kabel          Old enough to be an adult              
rik(_at_)netcom(_dot_)com

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