[rt-devel] Digest program.

Chewy zingfharn at fastmail.fm
Fri Jun 28 12:15:42 EDT 2002

It's scrappy as hell, but if anyone wants to test it, here's a script that
pulls out changes on the list since 4am on the day it's run. Stick it in a
cron job to kick off at the end of the work day, and it reduces emails going
Basically, it just emails every watcher on the list. I've realised that I've
not set mine up brilliantly. Too many adminCCs, and there are a lot of
little features I could do to make it better.
But, it works. Any enhancements you'd like, let me know.


use POSIX;

# Script to get all changes for the day, and mail them to the relevant
# A digest-maker if you will.
# Chewy, 28 Jun 2002, v0.1

# Globals. Change these for your platform.
$dir = "/home/rt2";
$mail = "/usr/sbin/sendmail";
$local_machine = "host.domain.net";

# These shouldn't need changing
$bin = "$dir/bin/rt";
$adbin = "$dir/bin/rtadmin";

# first, get a list off all tickets that have been changed since 4am this

# the time is
@now = localtime();
# fix it to 4.30am.
$now = POSIX::strftime("%Y/%m/%d:%T", 0, 30, 4, $now[3], $now[4], $now[5]);

# Run this command.
$command  = "$bin --limit-last-updated=$now- --summary

# Assign the output to a list.
open(OUTPUT, "$command|");
@tickets = <OUTPUT>;

# Drop the headers.


# For each ticket in the queue, append id and subject to the list.
# This could be done, so that it stores only subject, then have a config at
the top
# to decide what fields are sent to the watchers. But I'm lazy, and this
will work.
foreach $ticket (@tickets) {

  # clean the tickets up.
  $ticket =~ s/^\s+//;
  # split the line.
  ($id, $queue, $subject) = split(/\s\s+/, $ticket);
  # append the data.
  $queues{$queue} .= "$id/$subject||";

# for each queue, pull the watchers with the rtamin command, then mail id
and subject to them, one per line.
# Inform that these tickets have changed. That's about it.

foreach $queue (keys(%queues)) {
  $command = "$adbin --queue $queue --list-watchers";
  @tickets = split(/\|\|/, $queues{$queue});

  open(OUTPUT, "$command|");
  foreach $watcher (<OUTPUT>) {
    # strip whitespace and things.
    $watcher =~ s/^\s+//;
    # Send it to all of them. Would be nice to have a filter here, but I'm
too lazy.

    # Just pull the email address.
    ($crap, $wemail) = split(/\s+/, $watcher);

    # Format the email (pretty messy).
    open(MAIL, "|$mail -t $wemail");
    print MAIL "From: CRM System <$queue\@$local_machine>\n";
    print MAIL "To: $wemail\n";
    print MAIL "Subject: Daily CRM Digest\n";
    print MAIL "Reply-to: $wemail\n\n";
    print MAIL "Here are some tickets that have changed today on the $queue
    foreach $ticket (@tickets) {
      print "$ticket\n";
      ($id, $subj) = split(/\//, $ticket);
      print "$id, $subj\n";
      print MAIL

Ecce Potestas Casei

More information about the Rt-devel mailing list