Digest program

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
around.
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.
Chewy

#!/usr/bin/perl

use POSIX;

Script to get all changes for the day, and mail them to the relevant

people.

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

morning.

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
%id5%queue15%subject100”;

Assign the output to a list.

open(OUTPUT, “$command|”);
@tickets = ;
close(OUTPUT);

Drop the headers.

shift(@tickets);

%queues;

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+//;
chomp($ticket);

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 () {
# strip whitespace and things.
$watcher =~ s/^\s+//;
chomp($watcher);
# 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

list.\n";
foreach $ticket (@tickets) {
print “$ticket\n”;
($id, $subj) = split(///, $ticket);
print “$id, $subj\n”;
print MAIL
“http://$local_machine/Ticket/Display.html?id=$id\t$subj\n”;
}
close(MAIL);
}
close(OUTPUT);

}
Ecce Potestas Casei