From: Anders Kaseorg Date: Wed, 5 May 2010 22:39:17 +0000 (-0400) Subject: Add RT-to-Zephyr notification scrip. X-Git-Url: https://sipb.mit.edu/gitweb.cgi/snippets/.git/commitdiff_plain/1b73c3f915e1b0a7802e242cc0e85dfe1949c281?hp=36b8f5a7528476345b176c10164170c13743037c Add RT-to-Zephyr notification scrip. Signed-off-by: Anders Kaseorg --- diff --git a/rt/zephyr-scrip.pl b/rt/zephyr-scrip.pl new file mode 100644 index 0000000..5a23cdf --- /dev/null +++ b/rt/zephyr-scrip.pl @@ -0,0 +1,53 @@ +my $class = 'scripts-test'; +my $instance_prefix = 'rt.'; +my @zwrite = ('/usr/athena/bin/zwrite', '-d', '-O', 'auto', '-c', $class); + +# RT-to-Zephyr notification scrip +# http://snippets.scripts.mit.edu/gitweb.cgi/.git/tree/HEAD:/rt/zephyr-scrip.pl +# +# Copyright © 2010 Anders Kaseorg +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# Usage: configure $class and $instance_prefix above, and create a +# scrip as follows. +# +# Description: Send Zephyr +# Condition: User Defined +# Action: User Defined +# Template: Global template: Blank +# Stage: TrasnactionCreate +# Custom condition: +# 1; +# Custom action preparation code: +# 1; +# Custom action cleanup code: +# [insert this code] + +sub send_notice { + my ($instance, $body, $extra) = @_; + open my $out, '|-', @zwrite, '-i', $instance, defined $extra ? ('-s', $extra) : (); + print $out $body; + close $out; +}; + +local $SIG{__DIE__} = sub { + my ($err) = @_; + $err =~ s/@/@@/g; + send_notice "${instance_prefix}error", "Internal error in Zephyr scrip:\n$err"; +}; + +(my $id = $self->TicketObj->id) =~ s/@/@@/g; +(my $description = $self->TransactionObj->Description) =~ s/@/@@/g; +(my $subject = $self->TicketObj->Subject) =~ s/@/@@/g; + +send_notice "$instance_prefix$id", $description, $subject; +1;