Initial version of SMS alerting

Hi all

Here’s a simple action module to send SMS alerts to the user’s
PagerPhone. As written it uses RedOxygen’s SMS service, but since it’s
using SMS::Send any driver for that will work, and new drivers are
pretty easy to write.

This is a bit of an early version; it doesn’t take arguments to control
who gets notified yet. It should really be able to accept an argument
like “TicketAdminCcs,QueueAdminCcs” or
“TicketAdminCcs,Group:Level2Support” . Or the name of a Perl module
callback to filter the user list according to local rules like (say) who
is on shift.

It also hardcodes the SMS driver, username, password and account ID.
Pretty easy to change that so that the hash parms passed to
SMS::Send->new are obtained from RT_SiteConfig.pm, just haven’t done it
yet, and I wanted to post this as a starting point for anyone needing to
do something similar. Once I’ve cleaned it up I’ll pop it up on CPAN.

Usage via rt-crontool is a crontab entry like:

*/1 * * * * * rtuser rt-crontool --transaction last --search
RT::Search::FromSQL --search-arg “(Status=‘new’ OR Status=‘open’) AND
(Due > ‘Jan 1, 1970’) AND ((Due < ‘25 minutes’ AND Due >= ‘24 minutes’)
OR (Due < ‘12 minutes’ AND Due >= ‘11 minutes’) OR (Due < ‘5 minutes’
AND Due >= ‘3 minutes’))” --action RT::Action::SMSNotify --template ‘SLA
Alert SMS’

where “rtuser” is your local rt-crontool user.

RT::Action::SMSNotify, the text of which follows, is placed in
rtlocallib under RT/Action/SMSNotify.pm :

#!/usr/bin/perl

package RT::Action::SMSNotify;
use strict;
use warnings;

use Data::Dumper;
use SMS::Send;
use SMS::Send::RedOxygen;

use base qw(RT::Action);

sub Prepare {
my $self = shift;

    my (@memberlist);

    # get UserMembersObj of queue admincc members
    push(@memberlist, sort grep defined && length, map

$_->PagerPhone, @{
$self->TicketObj->QueueObj->AdminCc->UserMembersObj->ItemsArrayRef });

    # If the ticket has any adminCCs, add them too
    push(@memberlist, sort grep defined && length, map

$_->PagerPhone, @{
$self->TicketObj->AdminCc->UserMembersObj->ItemsArrayRef });

    RT::Logger->debug("Preparing to send SMSes to: " .

Dumper(@memberlist) );

    $self->{'PagerNumbers'} = \@memberlist;

    return scalar(@memberlist);

}

sub Commit {

    my $self = shift;

    my @memberlist = @{$self->{'PagerNumbers'}};

    my $sender = SMS::Send->new( 'RedOxygen',
            _accountid  => 'xxxxx',
            _email      => 'xxxxxx',
            _password   => 'xxxxxxx'
    );
    foreach my $ph (@memberlist) {

            # TODO: Sub in principal of current $ph
            my ($result, $message) = $self->TemplateObj->Parse(
                    Argument       => $self->Argument,
                    TicketObj      => $self->TicketObj,
                    TransactionObj => $self->TransactionObj
            );
            if ( !$result ) {
                    $RT::Logger->error("Failed to populate template:

$result, $message");
next;
}

            my $MIMEObj = $self->TemplateObj->MIMEObj;
            my $msgstring = $MIMEObj->bodyhandle->as_string;

            eval {
                    $RT::Logger->debug("Notifying $ph about ticket

SLA");
$sender->send_sms(
text => $msgstring,
to => $ph
);
$RT::Logger->info(“Notified $ph about ticket SLA”);
};
if ($@) {
$RT::Logger->error(“Failed to notify $ph about
ticket SLA: $@”);
}
}

    return 1;

}

1;

Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services

Hi all

Here’s a simple action module to send SMS alerts to the user’s
PagerPhone.

I’ve found the time to package this as RT::Extension::SMSNotify and
document it. It’s released under the Perl license on CPAN:

http://search.cpan.org/~ringerc/RT-Extension-SMSNotify/lib/RT/Extension/SMSNotify.pm

The module requires SMS::Send from CPAN and at least one SMS::Send
driver like SMS::Send::RedOxygen.

Sources for RT::Extension::SMSNotify here:

This version is a lot more flexible. You can plug in a custom function
in your RT_SiteConfig.pm to look up the phone number for a user, so you
can do LDAP or database queries, make phone number returns conditional
based on the user’s time zone, etc. Selection of recipients is done via
action arguments instead of being hardcoded to queue and ticket admincc,
too.

Any comments/fixes/improvements would be valued.

Craig Ringer http://www.2ndQuadrant.com/
PostgreSQL Development, 24x7 Support, Training & Services